Azure Terraform Tips
Here we get some tips and tricks to get around with Terraform and Azure, sometimes we have a lot of problems to get some information so let's make it easy.
Setting the variables to be used
Let's set the environment variables that will be read by Terraform. SPN Configuring Azure SPN for Terraform
The Subscription ID which should be used. This can also be sourced from the ARM_SUBSCRIPTION_ID Environment Variable.
export ARM_SUBSCRIPTION_ID="xxxxxxxx-xxxx-xxxx-xxxx-62f9d45b6957"
The Client ID which should be used. This can also be sourced from the ARM_CLIENT_ID Environment Variable.
export ARM_CLIENT_ID="xxxxxxxx-xxxx-xxxx-xxxx-e684b975d113"
The Client Secret which should be used. This can also be sourced from the ARM_CLIENT_SECRET Environment Variable.
export ARM_CLIENT_SECRET="8Z:s.?3pa@2zjuM4Y-JEoUdlj@w9SXfb"
The Tenant ID which should be used. This can also be sourced from the ARM_TENANT_ID Environment Variable.
export ARM_TENANT_ID="xxxxxxxx-xxxx-xxxx-xxxx-9c8a75bbff3e"
Azure Locations
We can get the global infrastructure from the following link: Azure locations
But usually we need to get it from the Azure CLI so.
Let's log in
az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET -t $ARM_TENANT_ID
Now we can get the locations
az account list-locations -o table Sat Apr 4 08:19:38 2020 DisplayName Latitude Longitude Name -------------------- ---------- ----------- ------------------ East Asia 22.267 114.188 eastasia Southeast Asia 1.283 103.833 southeastasia Central US 41.5908 -93.6208 centralus East US 37.3719 -79.8164 eastus East US 2 36.6681 -78.3889 eastus2 West US 37.783 -122.417 westus North Central US 41.8819 -87.6278 northcentralus South Central US 29.4167 -98.5 southcentralus North Europe 53.3478 -6.2597 northeurope West Europe 52.3667 4.9 westeurope Japan West 34.6939 135.5022 japanwest Japan East 35.68 139.77 japaneast Brazil South -23.55 -46.633 brazilsouth Australia East -33.86 151.2094 australiaeast Australia Southeast -37.8136 144.9631 australiasoutheast South India 12.9822 80.1636 southindia Central India 18.5822 73.9197 centralindia West India 19.088 72.868 westindia Canada Central 43.653 -79.383 canadacentral Canada East 46.817 -71.217 canadaeast UK South 50.941 -0.799 uksouth UK West 53.427 -3.084 ukwest West Central US 40.890 -110.234 westcentralus West US 2 47.233 -119.852 westus2 Korea Central 37.5665 126.9780 koreacentral Korea South 35.1796 129.0756 koreasouth France Central 46.3772 2.3730 francecentral France South 43.8345 2.1972 francesouth Australia Central -35.3075 149.1244 australiacentral Australia Central 2 -35.3075 149.1244 australiacentral2 UAE Central 24.466667 54.366669 uaecentral UAE North 25.266666 55.316666 uaenorth South Africa North -25.731340 28.218370 southafricanorth South Africa West -34.075691 18.843266 southafricawest Switzerland North 47.451542 8.564572 switzerlandnorth Switzerland West 46.204391 6.143158 switzerlandwest Germany North 53.073635 8.806422 germanynorth Germany West Central 50.110924 8.682127 germanywestcentral Norway West 58.969975 5.733107 norwaywest Norway East 59.913868 10.752245 norwayeast
Azure Market Place Images
Getting the list of all images available on West US 2, here a listing only the first ten results because the list is far long.
az vm image list-publishers -l westus2 -o table | head 3970ms Sat Apr 4 08:21:57 2020 Location Name ---------- ---------------------------------------------------------------------------------- westus2 128technology westus2 1e westus2 2021ai westus2 3cx-pbx westus2 4psa westus2 5nine-software-inc westus2 7isolutions westus2 a10networks
Getting the list of offers of Windows from West US 2
az vm image list-offers -l westus2 -p MicrosoftWindowsServer -o table 5.3s Sat Apr 4 08:23:29 2020 Location Name ---------- ----------------------------------------- westus2 19h1gen2servertest westus2 servertesting westus2 windows-10-1607-vhd-server-prod-stage westus2 windows-10-1607-vhd-sf-server-prod-stage westus2 windows-10-1803-vhd-server-prod-stage westus2 windows-10-1809-vhd-server-prod-stage westus2 windows-10-1809-vhd-sf-server-prod-stage westus2 windows-10-1903-vhd-server-prod-stage westus2 windows-10-1909-vhd-server-prod-stage westus2 windows-7-0-sp1-vhd-server-prod-stage westus2 windows-8-0-vhd-server-prod-stage westus2 windows-8-1-vhd-server-prod-stage westus2 Windows-HUB westus2 windows-server-2012-vhd-server-prod-stage westus2 WindowsServer westus2 windowsserver-gen2preview westus2 windowsserverdotnet westus2 WindowsServerSemiAnnual
Getting the list of SKU from West US 2 of Windows Server
az vm image list-skus -l westus2 -p MicrosoftWindowsServer -f WindowsServer -o table 5s Sat Apr 4 08:24:34 2020 Location Name ---------- ------------------------------------------------- westus2 2008-R2-SP1 westus2 2008-R2-SP1-smalldisk westus2 2008-R2-SP1-zhcn westus2 2012-Datacenter westus2 2012-datacenter-gensecond westus2 2012-Datacenter-smalldisk westus2 2012-datacenter-smalldisk-g2 westus2 2012-Datacenter-zhcn westus2 2012-datacenter-zhcn-g2 westus2 2012-R2-Datacenter westus2 2012-r2-datacenter-gensecond westus2 2012-R2-Datacenter-smalldisk westus2 2012-r2-datacenter-smalldisk-g2 westus2 2012-R2-Datacenter-zhcn westus2 2012-r2-datacenter-zhcn-g2 westus2 2016-Datacenter westus2 2016-datacenter-gensecond westus2 2016-datacenter-gs westus2 2016-Datacenter-Server-Core westus2 2016-datacenter-server-core-g2 westus2 2016-Datacenter-Server-Core-smalldisk westus2 2016-datacenter-server-core-smalldisk-g2 westus2 2016-Datacenter-smalldisk westus2 2016-datacenter-smalldisk-g2 westus2 2016-Datacenter-with-Containers westus2 2016-datacenter-with-containers-g2 westus2 2016-Datacenter-with-RDSH westus2 2016-Datacenter-zhcn westus2 2016-datacenter-zhcn-g2 westus2 2019-Datacenter westus2 2019-Datacenter-Core westus2 2019-datacenter-core-g2 westus2 2019-Datacenter-Core-smalldisk westus2 2019-datacenter-core-smalldisk-g2 westus2 2019-Datacenter-Core-with-Containers westus2 2019-datacenter-core-with-containers-g2 westus2 2019-Datacenter-Core-with-Containers-smalldisk westus2 2019-datacenter-core-with-containers-smalldisk-g2 westus2 2019-datacenter-gensecond westus2 2019-datacenter-gs westus2 2019-Datacenter-smalldisk westus2 2019-datacenter-smalldisk-g2 westus2 2019-Datacenter-with-Containers westus2 2019-datacenter-with-containers-g2 westus2 2019-Datacenter-with-Containers-smalldisk westus2 2019-datacenter-with-containers-smalldisk-g2 westus2 2019-Datacenter-zhcn westus2 2019-datacenter-zhcn-g2 westus2 Datacenter-Core-1803-with-Containers-smalldisk westus2 datacenter-core-1803-with-containers-smalldisk-g2 westus2 Datacenter-Core-1809-with-Containers-smalldisk westus2 datacenter-core-1809-with-containers-smalldisk-g2 westus2 Datacenter-Core-1903-with-Containers-smalldisk westus2 datacenter-core-1903-with-containers-smalldisk-g2 westus2 datacenter-core-1909-with-containers-smalldisk westus2 datacenter-core-1909-with-containers-smalldisk-g1 westus2 datacenter-core-1909-with-containers-smalldisk-g2
Azure Hardware Models
We can get the list of Hardware models for Windows in the following link: Sizes for Windows virtual machines in Azure
Listing the Hardware types
az vm list-sizes -l westus2 -o table 3936ms Sat Apr 4 08:27:33 2020 MaxDataDiskCount MemoryInMb Name NumberOfCores OsDiskSizeInMb ResourceDiskSizeInMb ------------------ ------------ ---------------------- --------------- ---------------- ---------------------- 64 5836800 Standard_M208ms_v2 208 1047552 4194304 64 2918400 Standard_M208s_v2 208 1047552 4194304 64 5836800 Standard_M416s_v2 416 1047552 8388608 64 11673600 Standard_M416ms_v2 416 1047552 8388608 4 4096 Standard_F2s_v2 2 1047552 16384 8 8192 Standard_F4s_v2 4 1047552 32768 16 16384 Standard_F8s_v2 8 1047552 65536 32 32768 Standard_F16s_v2 16 1047552 131072 32 65536 Standard_F32s_v2 32 1047552 262144 32 98304 Standard_F48s_v2 48 1047552 393216 32 131072 Standard_F64s_v2 64 1047552 524288 32 147456 Standard_F72s_v2 72 1047552 589824 2 512 Standard_B1ls 1 1047552 4096 2 2048 Standard_B1ms 1 1047552 4096 2 1024 Standard_B1s 1 1047552 4096 4 8192 Standard_B2ms 2 1047552 16384 4 4096 Standard_B2s 2 1047552 8192 8 16384 Standard_B4ms 4 1047552 32768 16 32768 Standard_B8ms 8 1047552 65536 16 49152 Standard_B12ms 12 1047552 98304 32 65536 Standard_B16ms 16 1047552 131072 32 81920 Standard_B20ms 20 1047552 163840 1 768 Standard_A0 1 1047552 20480 2 1792 Standard_A1 1 1047552 71680 4 3584 Standard_A2 2 1047552 138240 8 7168 Standard_A3 4 1047552 291840 4 14336 Standard_A5 2 1047552 138240 16 14336 Standard_A4 8 1047552 619520 8 28672 Standard_A6 4 1047552 291840 16 57344 Standard_A7 8 1047552 619520 1 768 Basic_A0 1 1047552 20480 2 1792 Basic_A1 1 1047552 40960 4 3584 Basic_A2 2 1047552 61440 8 7168 Basic_A3 4 1047552 122880 16 14336 Basic_A4 8 1047552 245760 4 3584 Standard_D1_v2 1 1047552 51200 8 7168 Standard_D2_v2 2 1047552 102400 16 14336 Standard_D3_v2 4 1047552 204800 32 28672 Standard_D4_v2 8 1047552 409600 64 57344 Standard_D5_v2 16 1047552 819200 8 14336 Standard_D11_v2 2 1047552 102400 16 28672 Standard_D12_v2 4 1047552 204800 32 57344 Standard_D13_v2 8 1047552 409600 64 114688 Standard_D14_v2 16 1047552 819200 64 143360 Standard_D15_v2 20 1047552 1024000 8 7168 Standard_D2_v2_Promo 2 1047552 102400 16 14336 Standard_D3_v2_Promo 4 1047552 204800 32 28672 Standard_D4_v2_Promo 8 1047552 409600 64 57344 Standard_D5_v2_Promo 16 1047552 819200 8 14336 Standard_D11_v2_Promo 2 1047552 102400 16 28672 Standard_D12_v2_Promo 4 1047552 204800 32 57344 Standard_D13_v2_Promo 8 1047552 409600 64 114688 Standard_D14_v2_Promo 16 1047552 819200 4 2048 Standard_F1 1 1047552 16384 8 4096 Standard_F2 2 1047552 32768 16 8192 Standard_F4 4 1047552 65536 32 16384 Standard_F8 8 1047552 131072 64 32768 Standard_F16 16 1047552 262144 4 3584 Standard_DS1_v2 1 1047552 7168 8 7168 Standard_DS2_v2 2 1047552 14336 16 14336 Standard_DS3_v2 4 1047552 28672 32 28672 Standard_DS4_v2 8 1047552 57344 64 57344 Standard_DS5_v2 16 1047552 114688 8 14336 Standard_DS11-1_v2 2 1047552 28672 8 14336 Standard_DS11_v2 2 1047552 28672 16 28672 Standard_DS12-1_v2 4 1047552 57344 16 28672 Standard_DS12-2_v2 4 1047552 57344 16 28672 Standard_DS12_v2 4 1047552 57344 32 57344 Standard_DS13-2_v2 8 1047552 114688 32 57344 Standard_DS13-4_v2 8 1047552 114688 32 57344 Standard_DS13_v2 8 1047552 114688 64 114688 Standard_DS14-4_v2 16 1047552 229376 64 114688 Standard_DS14-8_v2 16 1047552 229376 64 114688 Standard_DS14_v2 16 1047552 229376 64 143360 Standard_DS15_v2 20 1047552 286720 8 7168 Standard_DS2_v2_Promo 2 1047552 14336 16 14336 Standard_DS3_v2_Promo 4 1047552 28672 32 28672 Standard_DS4_v2_Promo 8 1047552 57344 64 57344 Standard_DS5_v2_Promo 16 1047552 114688 8 14336 Standard_DS11_v2_Promo 2 1047552 28672 16 28672 Standard_DS12_v2_Promo 4 1047552 57344 32 57344 Standard_DS13_v2_Promo 8 1047552 114688 64 114688 Standard_DS14_v2_Promo 16 1047552 229376 4 2048 Standard_F1s 1 1047552 4096 8 4096 Standard_F2s 2 1047552 8192 16 8192 Standard_F4s 4 1047552 16384 32 16384 Standard_F8s 8 1047552 32768 64 32768 Standard_F16s 16 1047552 65536 2 2048 Standard_A1_v2 1 1047552 10240 4 16384 Standard_A2m_v2 2 1047552 20480 4 4096 Standard_A2_v2 2 1047552 20480 8 32768 Standard_A4m_v2 4 1047552 40960 8 8192 Standard_A4_v2 4 1047552 40960 16 65536 Standard_A8m_v2 8 1047552 81920 16 16384 Standard_A8_v2 8 1047552 81920 4 8192 Standard_D2_v3 2 1047552 51200 8 16384 Standard_D4_v3 4 1047552 102400 16 32768 Standard_D8_v3 8 1047552 204800 32 65536 Standard_D16_v3 16 1047552 409600 32 131072 Standard_D32_v3 32 1047552 819200 4 8192 Standard_D2s_v3 2 1047552 16384 8 16384 Standard_D4s_v3 4 1047552 32768 16 32768 Standard_D8s_v3 8 1047552 65536 32 65536 Standard_D16s_v3 16 1047552 131072 32 131072 Standard_D32s_v3 32 1047552 262144 8 172032 Standard_NP10s 10 1047552 753664 16 344064 Standard_NP20s 20 1047552 1509376 32 688128 Standard_NP40s 40 1047552 3018752 32 196608 Standard_D48_v3 48 1047552 1228800 32 262144 Standard_D64_v3 64 1047552 1638400 32 196608 Standard_D48s_v3 48 1047552 393216 32 262144 Standard_D64s_v3 64 1047552 524288 4 16384 Standard_E2_v3 2 1047552 51200 8 32768 Standard_E4_v3 4 1047552 102400 16 65536 Standard_E8_v3 8 1047552 204800 32 131072 Standard_E16_v3 16 1047552 409600 32 163840 Standard_E20_v3 20 1047552 512000 32 262144 Standard_E32_v3 32 1047552 819200 32 393216 Standard_E48_v3 48 1047552 1228800 32 442368 Standard_E64_v3 64 1047552 1638400 4 16384 Standard_E2s_v3 2 1047552 32768 8 32768 Standard_E4-2s_v3 4 1047552 65536 8 32768 Standard_E4s_v3 4 1047552 65536 16 65536 Standard_E8-2s_v3 8 1047552 131072 16 65536 Standard_E8-4s_v3 8 1047552 131072 16 65536 Standard_E8s_v3 8 1047552 131072 32 131072 Standard_E16-4s_v3 16 1047552 262144 32 131072 Standard_E16-8s_v3 16 1047552 262144 32 131072 Standard_E16s_v3 16 1047552 262144 32 163840 Standard_E20s_v3 20 1047552 327680 32 262144 Standard_E32-8s_v3 32 1047552 524288 32 262144 Standard_E32-16s_v3 32 1047552 524288 32 262144 Standard_E32s_v3 32 1047552 524288 32 393216 Standard_E48s_v3 48 1047552 786432 32 442368 Standard_E64-16s_v3 64 1047552 884736 32 442368 Standard_E64-32s_v3 64 1047552 884736 32 442368 Standard_E64s_v3 64 1047552 884736 32 896000 Standard_M32-8ms 32 1047552 1024000 32 896000 Standard_M32-16ms 32 1047552 1024000 32 262144 Standard_M32ls 32 1047552 1024000 32 896000 Standard_M32ms 32 1047552 1024000 32 196608 Standard_M32ts 32 1047552 1024000 64 1792000 Standard_M64-16ms 64 1047552 2048000 64 1792000 Standard_M64-32ms 64 1047552 2048000 64 524288 Standard_M64ls 64 1047552 2048000 64 1792000 Standard_M64ms 64 1047552 2048000 64 1024000 Standard_M64s 64 1047552 2048000 64 3891200 Standard_M128-32ms 128 1047552 4096000 64 3891200 Standard_M128-64ms 128 1047552 4096000 64 3891200 Standard_M128ms 128 1047552 4096000 64 2048000 Standard_M128s 128 1047552 4096000 64 1024000 Standard_M64 64 1047552 8192000 64 1792000 Standard_M64m 64 1047552 8192000 64 2048000 Standard_M128 128 1047552 16384000 64 3891200 Standard_M128m 128 1047552 16384000
Azure VM Extentions
Getting the Available extensions
az vm extension image list -l westus2 -o table | head -n 20 3769ms Sat Apr 4 08:31:02 2020 Name Publisher Version ----------------------------------- ---------------------------------------------------- ---------------- AcronisBackup Acronis.Backup 1.0.33 AcronisBackup Acronis.Backup 1.0.51 AcronisBackupLinux Acronis.Backup 1.0.33 AlertLogicLM alertlogic 1.3.0.1 AlertLogicLM AlertLogic.Extension 1.3.0.0 AlertLogicLM AlertLogic.Extension 1.4.0.0 AlertLogicLM AlertLogic.Extension 1.9.0.0 AlertLogicLM AlertLogic.Extension 1.9.1.0 AgentWinExt bmc.ctm 9.0.0.1 ChefClient Chef.Bootstrap.WindowsAzure 11.18.6.2 ChefClient Chef.Bootstrap.WindowsAzure 1207.12.3.0 ChefClient Chef.Bootstrap.WindowsAzure 1210.12.109.1004 ChefClient Chef.Bootstrap.WindowsAzure 1210.12.109.1005 ChefClient Chef.Bootstrap.WindowsAzure 1210.12.110.1000 ChefClient Chef.Bootstrap.WindowsAzure 1210.12.110.1001 ChefClient Chef.Bootstrap.WindowsAzure 1210.12.110.1002 ChefClient Chef.Bootstrap.WindowsAzure 1210.13.1.0 ChefClient Chef.Bootstrap.WindowsAzure 1210.13.1.1
Getting the Available extensions by publisher Microsoft
az vm extension image list-names -l westus2 -p Microsoft.Compute -o table Location Name ---------- --------------------- westus2 BGInfo westus2 CustomScriptExtension westus2 JsonADDomainExtension westus2 VMAccessAgent
Getting the Available extensions by publisher Microsoft and its version
az vm extension image list-versions -l westus2 -p Microsoft.Compute -n CustomScriptExtension -o table Location Name ---------- ------ westus2 1.0 westus2 1.0.3 westus2 1.1 westus2 1.10.2 westus2 1.10.3 westus2 1.10.5 westus2 1.2 westus2 1.3 westus2 1.4 westus2 1.7 westus2 1.8 westus2 1.9 westus2 1.9.1 westus2 1.9.2 westus2 1.9.3 westus2 1.9.5