Part of my daily routine involves prototyping environments for scenarios spanning multiple public cloud providers. This Python script creates and deletes networks and subnets across AWS, Azure, and GCP from a .xlsx. Once the networks are provisioned, it returns and appends the id of each network to the spreadsheet so it can delete the resource when needed.
This script uses Pandas for data manipulation along with the SDKs for each cloud provider. The following packages are required:
pip3 install -r requirements.txtThis script uses environment variables to securely provide sensitive details, like credentials. These can be set in shell.
export AWS_ACCESS_KEY_ID=aws_access_key_id
export AWS_SECRET_ACCESS_KEY=aws_secret_access_key
export AZURE_TENANT_ID=azure_tenant_id
export AZURE_CLIENT_ID=azure_client_id
export AZURE_CLIENT_SECRET=azure_client_secret
export SUBSCRIPTION_ID=azure_subscription_id
export GOOGLE_APPLICATION_CREDENTIALS=credentials.jsonExcel .xlsx file should contain the following columns:
- name: The name of the network
- cloud: The cloud provider. Valid options are 'aws', 'azure', or 'gcp'
- region: The region in which to create the network
- cidr: The CIDR block for the network; Must be large enough to accommodate the specified number of /24 subnets
- num_subnets: The number of subnets to create for the network
- resource_group: (For Azure only) The resource group in which to create the VNet
- project_id: (For GCP only) The id of the project in which to create the VPC.
- resource_id: Leave this empty; It will be filled with the id of the resource
| name | cloud | region | cidr | num_subnets | resource_group | project_id | resource_id |
|---|---|---|---|---|---|---|---|
| vpc-01-npe | aws | us-east-1 | 10.1.0.0/16 | 1 | |||
| vpc-02-npe | aws | us-east-2 | 10.2.0.0/16 | 2 | |||
| vnet-01-npe | azure | eastus2 | 10.3.0.0/16 | 1 | rg-eastus2 | ||
| vnet-02-npe | azure | centralus | 10.4.0.0/16 | 2 | rg-centralus | ||
| vpc-01-npe | gcp | us-east4 | 10.5.0.0/16 | 2 | project-a | ||
| vpc-02-npe | gcp | us-central1 | 10.6.0.0/16 | 2 | project-b |
Networks can be created using the following:
python3 pymcn.py networks.xlsxIt will then append the id of each network created to the resource_id column
Networks can be deleted using the following:
python3 pymcn.py networks.xlsx --deleteThe id of each network existing under the resource_id column will be used to reference the network being deleted