Python Function App to automate resource cleanup in Azure.
To use this sample:
- Install Python 3.6
- Install the Azure CLI version 2.x or later.
- Install Azure Functions Core Tools
In a terminal window, run the following commands to clone the sample application to your local machine, and navigate to the directory with the sample code.
git clone https://github.com/asavaritayal/azure-resource-management.git
cd azure-resource-management
The names and versions of the required packages are already listed in the requirements.txt
file. Use the following command to install these dependencies using pip
:
pip install -r requirements.txt
To grant your Function App the permission to manage resources in a specific subscription in Azure, you will need to create a Service Principal using the following commands:
az account set --subscription="SUBSCRIPTION_ID"
az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/SUBSCRIPTION_ID"
This command will output 5 values:
{
"appId": "00000000-0000-0000-0000-000000000000",
"displayName": "azure-cli-2017-06-05-10-41-15",
"name": "http://azure-cli-2017-06-05-10-41-15",
"password": "0000-0000-0000-0000-000000000000",
"tenant": "00000000-0000-0000-0000-000000000000"
}
Use the following commands to configure the required secrets as local settings for your application:
func settings add AZURE_SUBSCRIPTION_ID {SUBSCRIPTION_ID}
func settings add AZURE_CLIENT_ID {appId}
func settings add AZURE_CLIENT_SECRET {password}
func settings add AZURE_TENANT_ID {tenant}
Use the following command to run the Functions host locally.
func host start
Trigger the function from the command line using curl in a new terminal window:
curl -w '\n' http://localhost:7071/api/HttpTrigger
Using the Azure Functions Core Tools, run the following command. Replace <APP_NAME> with the name of your Linux Function App.
func azure functionapp publish <APP_NAME> --publish-local-settings