Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

Commit 017acee

Browse files
authored
Merge pull request #3 from v-iam/patch-1
Update setup instructions
2 parents 4e6298a + 86b11a5 commit 017acee

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

README.md

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,57 @@ network interface belonging to the subnet. The virtual machine is a `Standard_D1
3939

4040
### To run this sample, do the following:
4141

42-
You will need to create an Azure service principal either through Azure CLI, PowerShell or the portal. You should gather
43-
the Tenant Id, Client Id and Client Secret from creating the Service Principal for use below.
44-
45-
We recommend using a [virtual environment](https://docs.python.org/3/tutorial/venv.html) to run this example, but it's not mandatory.
46-
To initialize a virtual environment:
47-
48-
- `pip install virtualenv`
49-
- `virtualenv mytestenv`
50-
- `cd mytestenv`
51-
- `source bin/activate`
52-
53-
Once in your virtual environment:
54-
- [Create a Service Principal](https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/#authenticate-with-password---azure-cli)
55-
- `git clone https://github.com/Azure-Samples/resource-manager-python-template-deployment.git`
56-
- `cd resource-manager-python-template-deployment`
57-
- `export AZURE_TENANT_ID={your tenant id}`
58-
- `export AZURE_CLIENT_ID={your client id}`
59-
- `export AZURE_CLIENT_SECRET={your client secret}`
60-
- `python azure_deployment.py`
42+
1. If you don't already have it, [install Python](https://www.python.org/downloads/).
43+
44+
1. We recommend using a [virtual environment](https://docs.python.org/3/tutorial/venv.html) to run this example,
45+
but it's not mandatory.
46+
To initialize a virtual environment:
47+
48+
```
49+
pip install virtualenv
50+
virtualenv mytestenv
51+
cd mytestenv
52+
source bin/activate
53+
```
54+
55+
1. Create a Service Principal, either through
56+
[Azure CLI](https://azure.microsoft.com/documentation/articles/resource-group-authenticate-service-principal-cli/),
57+
[PowerShell](https://azure.microsoft.com/documentation/articles/resource-group-authenticate-service-principal/)
58+
or [the portal](https://azure.microsoft.com/documentation/articles/resource-group-create-service-principal-portal/).
59+
60+
1. Clone this repository and navigate into it.
61+
62+
```
63+
git clone https://github.com/Azure-Samples/resource-manager-python-template-deployment.git
64+
cd resource-manager-python-template-deployment
65+
```
66+
67+
1. Create environment variables with the necessary IDs for Azure authentication.
68+
You can learn where to find the first three IDs in the Azure portal in [this document](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-application-id-and-authentication-key).
69+
The subscription ID is in the subscription's overview in the "Subscriptions" blade of the portal.
70+
71+
```
72+
export AZURE_TENANT_ID={your tenant id}
73+
export AZURE_CLIENT_ID={your client id}
74+
export AZURE_CLIENT_SECRET={your client secret}
75+
export AZURE_SUBSCRIPTION_ID={your subscription id}
76+
```
77+
78+
1. Run the script.
79+
80+
```
81+
python azure_deployment.py
82+
```
6183
6284
### What is this azure_deployment.py Doing?
6385
64-
The entry point for this sample is [azure_deployment.py](https://github.com/azure-samples/resource-manager-python-template-deployment/blob/master/azure_deployment.py). This script uses the deployer class
65-
below to deploy a the aforementioned template to the subscription and resource group specified in `my_resource_group`
86+
The entry point for this sample is [azure_deployment.py](https://github.com/azure-samples/resource-manager-python-template-deployment/blob/master/azure_deployment.py). This script uses the `Deployer` class
87+
below to deploy the aforementioned template to the subscription and resource group specified in `my_resource_group`
6688
and `my_subscription_id` respectively. By default the script will use the ssh public key from your default ssh
6789
location.
6890
69-
*Note: you must set each of the below environment variables (AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET) prior to
70-
running the script.*
91+
*Note: you must set each of the environment variables (`AZURE_TENANT_ID`, `AZURE_CLIENT_ID` and `AZURE_CLIENT_SECRET`) prior to
92+
running the script, and either set `AZURE_SUBSCRIPTION_ID` or replace it in the script. See the numbered list above for instructions on how to do this.*
7193
7294
``` python
7395
import os.path
@@ -179,15 +201,17 @@ class Deployer(object):
179201
self.client.resource_groups.delete(self.resource_group)
180202
```
181203

182-
The `__init__` method initializes the class with subscription, resource group and public key. The method also fetches
204+
The `__init__` method initializes the class with the subscription, resource group and public key. The method also fetches
183205
the Azure Active Directory bearer token, which will be used in each HTTP request to the Azure Management API. The class
184206
will raise exceptions under two conditions: if the public key path does not exist, or if there are empty
185-
values for Tenant Id, Client Id or Client Secret environment variables.
207+
values for `AZURE_TENANT_ID`, `AZURE_CLIENT_ID` or `AZURE_CLIENT_SECRET` environment variables.
186208

187-
The `deploy` method does the heavy lifting of creating or updating the resource group, preparing the template,
209+
The `deploy` method does the heavy lifting of creating or updating the resource group, preparing the template
188210
parameters and deploying the template.
189211

190212
The `destroy` method simply deletes the resource group thus deleting all of the resources within that group.
213+
Note that it is commented out in `azure_deployment.py`. But you can uncomment it to easily clean up the resources
214+
created by this sample if you no longer need them.
191215

192216
Each of the above methods use the `azure.mgmt.resource.ResourceManagementClient` class, which resides within the
193217
[azure-mgmt-resource](https://pypi.python.org/pypi/azure-mgmt-resource/) package ([see the docs here](http://azure-sdk-for-python.readthedocs.io/en/latest/resourcemanagement.html)).

0 commit comments

Comments
 (0)