Skip to content

Latest commit

 

History

History
84 lines (61 loc) · 3.12 KB

File metadata and controls

84 lines (61 loc) · 3.12 KB

Cost Center Tagging Serverless Automation

This project contains an automation workflow for cost center tagging, using Serverless technologies on Azure. This solution is described in more detail in Azure Architecture center in the Event-based cloud automation article.

Prerequisites

Deploy the cost center automation artifacts

Clone the repo

git clone https://github.com/mspnp/serverless-automation
cd src/automation/cost-center/cost-center-tagging

The deployment steps shown here use bash shell commands. On Windows, you can use the Windows Subsystem for Linux to run Bash.

Export the automation variables representing the assets

SUBSCRIPTION_ID=<subscription-id>
RESOURCE_GROUP=<resource-group-name>
LOCATION=<resource-group-location>
STORAGE_ACCOUNT_NAME=<storageaccountname>
APPSERVICE_NAME=<appservice-name>
FUNCAPP_NAME=<funcapp-name>

Deploy the logic app

az deployment group create -g $RESOURCE_GROUP -f ./logicApp/template.json  

Deploy the Azure Function that responds to the Logic App

az group create -n $RESOURCE_GROUP -l $LOCATION \
&& az storage account create -g $RESOURCE_GROUP -n $STORAGE_ACCOUNT_NAME --sku Standard_LRS \
&& az appservice plan create --name $APPSERVICE_NAME -g $RESOURCE_GROUP --sku S1 \
&& az functionapp create -g $RESOURCE_GROUP -n $FUNCAPP_NAME -s $STORAGE_ACCOUNT_NAME --plan $APPSERVICE_NAME \
&& az functionapp identity assign -g $RESOURCE_GROUP -n $FUNCAPP_NAME

Grant the Azure Function resource policy access to the resource group

az role assignment create --assignee-object-id <serviceprincipalid> \
   --role 'Contributor' \
   --resource-group $RESOURCE_GROUP

Create a policy definition for the resources that can be tagged

az policy definition create --name appendTagsIfNotExists \
                            --description "Append tags if not already defined for supported resources" \
                            --display-name "Set of billing policy rules" \
                            --mode Indexed \
                            --subscription $SUBSCRIPTION_ID \
                            --rules policies/custompolicy.rules.json \
                            --params policies/custompolicy.rules.parameters.json

Enforce policy rules at the resource group level

az policy assignment create --name billingPolicy \
                            --display-name "Resource billing policy" \
                            --resource-group $RESOURCE_GROUP \
                            --policy "<policy-id-obtained-from-the-output-of-previous-command>"

Publish the function app

func azure functionapp publish $FUNCAPP_NAME