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.
- Azure subscription
- Azure Function Core Tools
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.
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>
az deployment group create -g $RESOURCE_GROUP -f ./logicApp/template.json
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
az role assignment create --assignee-object-id <serviceprincipalid> \
--role 'Contributor' \
--resource-group $RESOURCE_GROUP
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
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>"
func azure functionapp publish $FUNCAPP_NAME