{"id":1264,"date":"2018-09-15T11:54:39","date_gmt":"2018-09-15T16:54:39","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1264"},"modified":"2018-11-09T14:54:26","modified_gmt":"2018-11-09T20:54:26","slug":"terraform-with-azure","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/terraform-with-azure\/","title":{"rendered":"Terraform with Azure"},"content":{"rendered":"

Azure provides a cloud shell with Terraform already installed and even an editor aware of Terraform source. I tested creating a network and VM using the cloud shell in the browser.<\/p>\n

REF: https:\/\/docs.microsoft.com\/en-us\/azure\/virtual-machines\/linux\/terraform-install-configure<\/p>\n

Note: I am not showing dry run (terraform plan) but you should always be in the habit of plan before apply.<\/p>\n

###################################################################
\nUsing cloud shell prompts for a storage account tied to your shell.
\n###################################################################<\/p>\n

\r\nYour cloud drive has been created in:\r\n\r\nSubscription Id: b[..]b\r\nResource group:  cloud-shell-storage-southcentralus\r\nStorage account: c[..]4\r\nFile share:      cs-[..]2\r\n\r\nInitializing your account for Cloud Shell...\\\r\nRequesting a Cloud Shell.Succeeded.\r\nConnecting terminal...\r\n\r\nWelcome to Azure Cloud Shell\r\n\r\nType "az" to use Azure CLI 2.0\r\nType "help" to learn about Cloud Shell\r\n<\/pre>\n

#######
\nTest az
\n#######<\/p>\n

\r\nriaan@Azure:~$ az vm list\r\n[\r\n  {\r\n    "availabilitySet": null,\r\n    "diagnosticsProfile": {\r\n      "bootDiagnostics": {\r\n        "enabled": true,\r\n        "storageUri": "https:\/\/sitesdiag.blob.core.windows.net\/"\r\n      }\r\n    },\r\n    "hardwareProfile": {\r\n      "vmSize": "Standard_B1s"\r\n    },\r\n [..]\r\n  }\r\n]\r\n<\/pre>\n

###################################################################################################################
\nCheck folder and space available
\n###################################################################################################################<\/p>\n

\r\nriaan@Azure:~$ ls\r\nclouddrive\r\nriaan@Azure:~$ df -h .\r\nFilesystem      Size  Used Avail Use% Mounted on\r\n\/dev\/loop0      5.0G   11M  4.7G   1% \/home\/riaan\r\n\r\nriaan@Azure:~$ az account show --query "{subscriptionId:id, tenantId:tenantId}"\r\n{\r\n  "subscriptionId": "b[..]",\r\n  "tenantId": "f[..]"\r\n}\r\n<\/pre>\n

###################################################################################################################
\nSimple terraform test add a resource group
\n###################################################################################################################<\/p>\n

\r\nriaan@Azure:~$ mkdir sites\r\nriaan@Azure:~$ cd sites\r\nriaan@Azure:~\/sites$ vi test.tf\r\nriaan@Azure:~\/sites$ terraform init\r\n\r\nInitializing provider plugins...\r\n- Checking for available provider plugins on https:\/\/releases.hashicorp.com...\r\n- Downloading plugin for provider "azurerm" (1.15.0)...\r\n[..]\r\n* provider.azurerm: version = "~> 1.15"\r\nTerraform has been successfully initialized!\r\n\r\nriaan@Azure:~\/sites$ terraform apply\r\n[..]\r\n  + create\r\n\r\nTerraform will perform the following actions:\r\n\r\n  + azurerm_resource_group.rg\r\n      id:       <computed>\r\n      location: "centralus"\r\n      name:     "testResourceGroup"\r\n      tags.%:   <computed>\r\n\r\nPlan: 1 to add, 0 to change, 0 to destroy.\r\n\r\nDo you want to perform these actions?\r\n  Terraform will perform the actions described above.\r\n  Only 'yes' will be accepted to approve.\r\n\r\n  Enter a value: yes\r\n\r\nazurerm_resource_group.rg: Creating...\r\n  location: "" => "centralus"\r\n  name:     "" => "testResourceGroup"\r\n  tags.%:   "" => "<computed>"\r\nazurerm_resource_group.rg: Creation complete after 0s (ID: \/subscriptions\/b[..]\/resourceGroups\/testResourceGroup)\r\n\r\nApply complete! Resources: 1 added, 0 changed, 0 destroyed.\r\n<\/pre>\n

#######################################################################
\nSimple terraform test. Destroy a resource group. I just comment it out.
\n#######################################################################<\/p>\n

\r\nriaan@Azure:~\/sites$ vi test.tf\r\nriaan@Azure:~\/sites$ terraform apply\r\nazurerm_resource_group.rg: Refreshing state... (ID: \/subscriptions\/b[..]\/resourceGroups\/testResourceGroup)\r\n\r\nAn execution plan has been generated and is shown below.\r\nResource actions are indicated with the following symbols:\r\n  - destroy\r\n\r\nTerraform will perform the following actions:\r\n\r\n  - azurerm_resource_group.rg\r\n\r\nPlan: 0 to add, 0 to change, 1 to destroy.\r\n\r\nDo you want to perform these actions?\r\n  Terraform will perform the actions described above.\r\n  Only 'yes' will be accepted to approve.\r\n\r\n  Enter a value: yes\r\n\r\nazurerm_resource_group.rg: Destroying... (ID: \/subscriptions\/b[..]\/resourceGroups\/testResourceGroup)\r\nazurerm_resource_group.rg: Still destroying... (ID: \/subscriptions\/b[..]\/resourceGroups\/testResourceGroup, 10s elapsed)\r\n[..]\r\nazurerm_resource_group.rg: Destruction complete after 45s\r\n\r\nApply complete! Resources: 0 added, 0 changed, 1 destroyed.\r\n<\/pre>\n

###################################################################################################################
\nCreate VM plus network
\nhttps:\/\/docs.microsoft.com\/en-us\/azure\/virtual-machines\/linux\/terraform-create-complete-vm
\n###################################################################################################################<\/p>\n

\r\nriaan@Azure:~\/sites$ rm test.tf\r\nriaan@Azure:~\/sites$ vi main.tf\r\nriaan@Azure:~\/sites$ terraform apply\r\n\r\nAn execution plan has been generated and is shown below.\r\nResource actions are indicated with the following symbols:\r\n  + create\r\n\r\nTerraform will perform the following actions:\r\n\r\n  + azurerm_network_interface.myterraformnic\r\n      id:                                                                    <computed>\r\n      applied_dns_servers.#:                                                 <computed>\r\n      dns_servers.#:                                                         <computed>\r\n      enable_accelerated_networking:                                         "false"\r\n      enable_ip_forwarding:                                                  "false"\r\n      internal_dns_name_label:                                               <computed>\r\n      internal_fqdn:                                                         <computed>\r\n      ip_configuration.#:                                                    "1"\r\n      ip_configuration.0.application_gateway_backend_address_pools_ids.#:    <computed>\r\n      ip_configuration.0.application_security_group_ids.#:                   <computed>\r\n      ip_configuration.0.load_balancer_backend_address_pools_ids.#:          <computed>\r\n      ip_configuration.0.load_balancer_inbound_nat_rules_ids.#:              <computed>\r\n      ip_configuration.0.name:                                               "myNicConfiguration"\r\n      ip_configuration.0.primary:                                            <computed>\r\n      ip_configuration.0.private_ip_address_allocation:                      "dynamic"\r\n      ip_configuration.0.public_ip_address_id:                               "${azurerm_public_ip.myterraformpublicip.id}"\r\n      ip_configuration.0.subnet_id:                                          "${azurerm_subnet.myterraformsubnet.id}"\r\n      location:                                                              "eastus"\r\n      mac_address:                                                           <computed>\r\n      name:                                                                  "myNIC"\r\n      network_security_group_id:                                             "${azurerm_network_security_group.myterraformnsg.id}"\r\n      private_ip_address:                                                    <computed>\r\n      private_ip_addresses.#:                                                <computed>\r\n      resource_group_name:                                                   "myResourceGroup"\r\n      tags.%:                                                                "1"\r\n      tags.environment:                                                      "Terraform Demo"\r\n      virtual_machine_id:                                                    <computed>\r\n\r\n  + azurerm_network_security_group.myterraformnsg\r\n      id:                                                                    <computed>\r\n      location:                                                              "eastus"\r\n      name:                                                                  "myNetworkSecurityGroup"\r\n      resource_group_name:                                                   "myResourceGroup"\r\n      security_rule.#:                                                       "1"\r\n      security_rule.2090309246.access:                                       "Allow"\r\n      security_rule.2090309246.description:                                  ""\r\n      security_rule.2090309246.destination_address_prefix:                   "*"\r\n      security_rule.2090309246.destination_address_prefixes.#:               "0"\r\n      security_rule.2090309246.destination_application_security_group_ids.#: "0"\r\n      security_rule.2090309246.destination_port_range:                       "22"\r\n      security_rule.2090309246.destination_port_ranges.#:                    "0"\r\n      security_rule.2090309246.direction:                                    "Inbound"\r\n      security_rule.2090309246.name:                                         "SSH"\r\n      security_rule.2090309246.priority:                                     "1001"\r\n      security_rule.2090309246.protocol:                                     "Tcp"\r\n      security_rule.2090309246.source_address_prefix:                        "*"\r\n      security_rule.2090309246.source_address_prefixes.#:                    "0"\r\n      security_rule.2090309246.source_application_security_group_ids.#:      "0"\r\n      security_rule.2090309246.source_port_range:                            "*"\r\n      security_rule.2090309246.source_port_ranges.#:                         "0"\r\n      tags.%:                                                                "1"\r\n      tags.environment:                                                      "Terraform Demo"\r\n\r\n  + azurerm_public_ip.myterraformpublicip\r\n      id:                                                                    <computed>\r\n      fqdn:                                                                  <computed>\r\n      ip_address:                                                            <computed>\r\n      location:                                                              "eastus"\r\n      name:                                                                  "myPublicIP"\r\n      public_ip_address_allocation:                                          "dynamic"\r\n      resource_group_name:                                                   "myResourceGroup"\r\n      sku:                                                                   "Basic"\r\n      tags.%:                                                                "1"\r\n      tags.environment:                                                      "Terraform Demo"\r\n\r\n  + azurerm_resource_group.myterraformgroup\r\n      id:                                                                    <computed>\r\n      location:                                                              "eastus"\r\n      name:                                                                  "myResourceGroup"\r\n      tags.%:                                                                "1"\r\n      tags.environment:                                                      "Terraform Demo"\r\n\r\n  + azurerm_storage_account.mystorageaccount\r\n      id:                                                                    <computed>\r\n      access_tier:                                                           <computed>\r\n      account_encryption_source:                                             "Microsoft.Storage"\r\n      account_kind:                                                          "Storage"\r\n      account_replication_type:                                              "LRS"\r\n      account_tier:                                                          "Standard"\r\n      enable_blob_encryption:                                                "true"\r\n      enable_file_encryption:                                                "true"\r\n      identity.#:                                                            <computed>\r\n      location:                                                              "eastus"\r\n      name:                                                                  "diag${random_id.randomId.hex}"\r\n      primary_access_key:                                                    <computed>\r\n      primary_blob_connection_string:                                        <computed>\r\n      primary_blob_endpoint:                                                 <computed>\r\n      primary_connection_string:                                             <computed>\r\n      primary_file_endpoint:                                                 <computed>\r\n      primary_location:                                                      <computed>\r\n      primary_queue_endpoint:                                                <computed>\r\n      primary_table_endpoint:                                                <computed>\r\n      resource_group_name:                                                   "myResourceGroup"\r\n      secondary_access_key:                                                  <computed>\r\n      secondary_blob_connection_string:                                      <computed>\r\n      secondary_blob_endpoint:                                               <computed>\r\n      secondary_connection_string:                                           <computed>\r\n      secondary_location:                                                    <computed>\r\n      secondary_queue_endpoint:                                              <computed>\r\n      secondary_table_endpoint:                                              <computed>\r\n      tags.%:                                                                "1"\r\n      tags.environment:                                                      "Terraform Demo"\r\n\r\n  + azurerm_subnet.myterraformsubnet\r\n      id:                                                                    <computed>\r\n      address_prefix:                                                        "10.0.1.0\/24"\r\n      ip_configurations.#:                                                   <computed>\r\n      name:                                                                  "mySubnet"\r\n      resource_group_name:                                                   "myResourceGroup"\r\n      virtual_network_name:                                                  "myVnet"\r\n\r\n  + azurerm_virtual_machine.myterraformvm\r\n      id:                                                                    <computed>\r\n      availability_set_id:                                                   <computed>\r\n      boot_diagnostics.#:                                                    "1"\r\n      boot_diagnostics.0.enabled:                                            "true"\r\n      boot_diagnostics.0.storage_uri:                                        "${azurerm_storage_account.mystorageaccount.primary_blob_endpoint}"\r\n      delete_data_disks_on_termination:                                      "false"\r\n      delete_os_disk_on_termination:                                         "false"\r\n      identity.#:                                                            <computed>\r\n      location:                                                              "eastus"\r\n      name:                                                                  "myVM"\r\n      network_interface_ids.#:                                               <computed>\r\n      os_profile.#:                                                          "1"\r\n      os_profile.1770182618.admin_password:                                  <sensitive>\r\n      os_profile.1770182618.admin_username:                                  "azureuser"\r\n      os_profile.1770182618.computer_name:                                   "myvm"\r\n      os_profile.1770182618.custom_data:                                     <computed>\r\n      os_profile_linux_config.#:                                             "1"\r\n      os_profile_linux_config.69840937.disable_password_authentication:      "true"\r\n      os_profile_linux_config.69840937.ssh_keys.#:                           "1"\r\n      os_profile_linux_config.69840937.ssh_keys.0.key_data:                  "ssh-rsa AAAAB3Nz{snip}hwhqT9h"\r\n      os_profile_linux_config.69840937.ssh_keys.0.path:                      "\/home\/azureuser\/.ssh\/authorized_keys"\r\n      resource_group_name:                                                   "myResourceGroup"\r\n      storage_data_disk.#:                                                   <computed>\r\n      storage_image_reference.#:                                             "1"\r\n      storage_image_reference.363552096.id:                                  ""\r\n      storage_image_reference.363552096.offer:                               "UbuntuServer"\r\n      storage_image_reference.363552096.publisher:                           "Canonical"\r\n      storage_image_reference.363552096.sku:                                 "16.04.0-LTS"\r\n      storage_image_reference.363552096.version:                             "latest"\r\n      storage_os_disk.#:                                                     "1"\r\n      storage_os_disk.0.caching:                                             "ReadWrite"\r\n      storage_os_disk.0.create_option:                                       "FromImage"\r\n      storage_os_disk.0.disk_size_gb:                                        <computed>\r\n      storage_os_disk.0.managed_disk_id:                                     <computed>\r\n      storage_os_disk.0.managed_disk_type:                                   "Premium_LRS"\r\n      storage_os_disk.0.name:                                                "myOsDisk"\r\n      storage_os_disk.0.write_accelerator_enabled:                           "false"\r\n      tags.%:                                                                "1"\r\n      tags.environment:                                                      "Terraform Demo"\r\n      vm_size:                                                               "Standard_DS1_v2"\r\n\r\n  + azurerm_virtual_network.myterraformnetwork\r\n      id:                                                                    <computed>\r\n      address_space.#:                                                       "1"\r\n      address_space.0:                                                       "10.0.0.0\/16"\r\n      location:                                                              "eastus"\r\n      name:                                                                  "myVnet"\r\n      resource_group_name:                                                   "myResourceGroup"\r\n      subnet.#:                                                              <computed>\r\n      tags.%:                                                                "1"\r\n      tags.environment:                                                      "Terraform Demo"\r\n\r\n  + random_id.randomId\r\n      id:                                                                    <computed>\r\n      b64:                                                                   <computed>\r\n      b64_std:                                                               <computed>\r\n      b64_url:                                                               <computed>\r\n      byte_length:                                                           "8"\r\n      dec:                                                                   <computed>\r\n      hex:                                                                   <computed>\r\n      keepers.%:                                                             "1"\r\n      keepers.resource_group:                                                "myResourceGroup"\r\n\r\n\r\nPlan: 9 to add, 0 to change, 0 to destroy.\r\n\r\nDo you want to perform these actions?\r\n  Terraform will perform the actions described above.\r\n  Only 'yes' will be accepted to approve.\r\n\r\n  Enter a value: yes\r\n\r\nazurerm_resource_group.myterraformgroup: Creating...\r\n  location:         "" => "eastus"\r\n  name:             "" => "myResourceGroup"\r\n  tags.%:           "" => "1"\r\n  tags.environment: "" => "Terraform Demo"\r\nazurerm_resource_group.myterraformgroup: Creation complete after 0s (ID: \/subscriptions\/b[..]\/resourceGroups\/myResourceGroup)\r\nazurerm_virtual_network.myterraformnetwork: Creating...\r\n  address_space.#:     "" => "1"\r\n  address_space.0:     "" => "10.0.0.0\/16"\r\n  location:            "" => "eastus"\r\n  name:                "" => "myVnet"\r\n  resource_group_name: "" => "myResourceGroup"\r\n  subnet.#:            "" => "<computed>"\r\n  tags.%:              "" => "1"\r\n  tags.environment:    "" => "Terraform Demo"\r\nazurerm_public_ip.myterraformpublicip: Creating...\r\n  fqdn:                         "" => "<computed>"\r\n  ip_address:                   "" => "<computed>"\r\n  location:                     "" => "eastus"\r\n  name:                         "" => "myPublicIP"\r\n  public_ip_address_allocation: "" => "dynamic"\r\n  resource_group_name:          "" => "myResourceGroup"\r\n  sku:                          "" => "Basic"\r\n  tags.%:                       "" => "1"\r\n  tags.environment:             "" => "Terraform Demo"\r\nrandom_id.randomId: Creating...\r\n  b64:                    "" => "<computed>"\r\n  b64_std:                "" => "<computed>"\r\n  b64_url:                "" => "<computed>"\r\n  byte_length:            "" => "8"\r\n  dec:                    "" => "<computed>"\r\n  hex:                    "" => "<computed>"\r\n  keepers.%:              "" => "1"\r\n  keepers.resource_group: "" => "myResourceGroup"\r\nrandom_id.randomId: Creation complete after 0s (ID: ZZic4bhOapM)\r\nazurerm_network_security_group.myterraformnsg: Creating...\r\n  location:                                                              "" => "eastus"\r\n  name:                                                                  "" => "myNetworkSecurityGroup"\r\n  resource_group_name:                                                   "" => "myResourceGroup"\r\n  security_rule.#:                                                       "" => "1"\r\n  security_rule.2090309246.access:                                       "" => "Allow"\r\n  security_rule.2090309246.description:                                  "" => ""\r\n  security_rule.2090309246.destination_address_prefix:                   "" => "*"\r\n  security_rule.2090309246.destination_address_prefixes.#:               "" => "0"\r\n  security_rule.2090309246.destination_application_security_group_ids.#: "" => "0"\r\n  security_rule.2090309246.destination_port_range:                       "" => "22"\r\n  security_rule.2090309246.destination_port_ranges.#:                    "" => "0"\r\n  security_rule.2090309246.direction:                                    "" => "Inbound"\r\n  security_rule.2090309246.name:                                         "" => "SSH"\r\n  security_rule.2090309246.priority:                                     "" => "1001"\r\n  security_rule.2090309246.protocol:                                     "" => "Tcp"\r\n  security_rule.2090309246.source_address_prefix:                        "" => "*"\r\n  security_rule.2090309246.source_address_prefixes.#:                    "" => "0"\r\n  security_rule.2090309246.source_application_security_group_ids.#:      "" => "0"\r\n  security_rule.2090309246.source_port_range:                            "" => "*"\r\n  security_rule.2090309246.source_port_ranges.#:                         "" => "0"\r\n  tags.%:                                                                "" => "1"\r\n  tags.environment:                                                      "" => "Terraform Demo"\r\nazurerm_storage_account.mystorageaccount: Creating...\r\n  access_tier:                      "" => "<computed>"\r\n  account_encryption_source:        "" => "Microsoft.Storage"\r\n  account_kind:                     "" => "Storage"\r\n  account_replication_type:         "" => "LRS"\r\n  account_tier:                     "" => "Standard"\r\n  enable_blob_encryption:           "" => "true"\r\n  enable_file_encryption:           "" => "true"\r\n  identity.#:                       "" => "<computed>"\r\n  location:                         "" => "eastus"\r\n  name:                             "" => "diag6[..]"\r\n  primary_access_key:               "<sensitive>" => "<sensitive>"\r\n  primary_blob_connection_string:   "<sensitive>" => "<sensitive>"\r\n  primary_blob_endpoint:            "" => "<computed>"\r\n  primary_connection_string:        "<sensitive>" => "<sensitive>"\r\n  primary_file_endpoint:            "" => "<computed>"\r\n  primary_location:                 "" => "<computed>"\r\n  primary_queue_endpoint:           "" => "<computed>"\r\n  primary_table_endpoint:           "" => "<computed>"\r\n  resource_group_name:              "" => "myResourceGroup"\r\n  secondary_access_key:             "<sensitive>" => "<sensitive>"\r\n  secondary_blob_connection_string: "<sensitive>" => "<sensitive>"\r\n  secondary_blob_endpoint:          "" => "<computed>"\r\n  secondary_connection_string:      "<sensitive>" => "<sensitive>"\r\n  secondary_location:               "" => "<computed>"\r\n  secondary_queue_endpoint:         "" => "<computed>"\r\n  secondary_table_endpoint:         "" => "<computed>"\r\n  tags.%:                           "" => "1"\r\n  tags.environment:                 "" => "Terraform Demo"\r\nazurerm_public_ip.myterraformpublicip: Creation complete after 2s (ID: \/subscriptions\/b[..]-...t.Network\/publicIPAddresses\/myPublicIP)\r\nazurerm_network_security_group.myterraformnsg: Creation complete after 2s (ID: \/subscriptions\/b[..]-...kSecurityGroups\/myNetworkSecurityGroup)\r\nazurerm_virtual_network.myterraformnetwork: Still creating... (10s elapsed)\r\nazurerm_storage_account.mystorageaccount: Still creating... (10s elapsed)\r\nazurerm_storage_account.mystorageaccount: Creation complete after 19s (ID: \/subscriptions\/b[..]-...e\/storageAccounts\/diag6[..])\r\nazurerm_virtual_network.myterraformnetwork: Still creating... (20s elapsed)\r\nazurerm_virtual_network.myterraformnetwork: Creation complete after 22s (ID: \/subscriptions\/b[..]-...crosoft.Network\/virtualNetworks\/myVnet)\r\nazurerm_subnet.myterraformsubnet: Creating...\r\n  address_prefix:       "" => "10.0.1.0\/24"\r\n  ip_configurations.#:  "" => "<computed>"\r\n  name:                 "" => "mySubnet"\r\n  resource_group_name:  "" => "myResourceGroup"\r\n  virtual_network_name: "" => "myVnet"\r\nazurerm_subnet.myterraformsubnet: Still creating... (10s elapsed)\r\nazurerm_subnet.myterraformsubnet: Creation complete after 11s (ID: \/subscriptions\/b[..]-...irtualNetworks\/myVnet\/subnets\/mySubnet)\r\nazurerm_network_interface.myterraformnic: Creating...\r\n  applied_dns_servers.#:                                              "" => "<computed>"\r\n  dns_servers.#:                                                      "" => "<computed>"\r\n  enable_accelerated_networking:                                      "" => "false"\r\n  enable_ip_forwarding:                                               "" => "false"\r\n  internal_dns_name_label:                                            "" => "<computed>"\r\n  internal_fqdn:                                                      "" => "<computed>"\r\n  ip_configuration.#:                                                 "" => "1"\r\n  ip_configuration.0.application_gateway_backend_address_pools_ids.#: "" => "<computed>"\r\n  ip_configuration.0.application_security_group_ids.#:                "" => "<computed>"\r\n  ip_configuration.0.load_balancer_backend_address_pools_ids.#:       "" => "<computed>"\r\n  ip_configuration.0.load_balancer_inbound_nat_rules_ids.#:           "" => "<computed>"\r\n  ip_configuration.0.name:                                            "" => "myNicConfiguration"\r\n  ip_configuration.0.primary:                                         "" => "<computed>"\r\n  ip_configuration.0.private_ip_address_allocation:                   "" => "dynamic"\r\n  ip_configuration.0.public_ip_address_id:                            "" => "\/subscriptions\/b[..]\/resourceGroups\/myResourceGroup\/providers\/Microsoft.Network\/publicIPAddresses\/myPublicIP"\r\n  ip_configuration.0.subnet_id:                                       "" => "\/subscriptions\/b[..]\/resourceGroups\/myResourceGroup\/providers\/Microsoft.Network\/virtualNetworks\/myVnet\/subnets\/mySubnet"\r\n  location:                                                           "" => "eastus"\r\n  mac_address:                                                        "" => "<computed>"\r\n  name:                                                               "" => "myNIC"\r\n  network_security_group_id:                                          "" => "\/subscriptions\/b[..]\/resourceGroups\/myResourceGroup\/providers\/Microsoft.Network\/networkSecurityGroups\/myNetworkSecurityGroup"\r\n  private_ip_address:                                                 "" => "<computed>"\r\n  private_ip_addresses.#:                                             "" => "<computed>"\r\n  resource_group_name:                                                "" => "myResourceGroup"\r\n  tags.%:                                                             "" => "1"\r\n  tags.environment:                                                   "" => "Terraform Demo"\r\n  virtual_machine_id:                                                 "" => "<computed>"\r\nazurerm_network_interface.myterraformnic: Creation complete after 1s (ID: \/subscriptions\/b[..]-...rosoft.Network\/networkInterfaces\/myNIC)\r\nazurerm_virtual_machine.myterraformvm: Creating...\r\n  availability_set_id:                                              "" => "<computed>"\r\n  boot_diagnostics.#:                                               "" => "1"\r\n  boot_diagnostics.0.enabled:                                       "" => "true"\r\n  boot_diagnostics.0.storage_uri:                                   "" => "https:\/\/diag[..].blob.core.windows.net\/"\r\n  delete_data_disks_on_termination:                                 "" => "false"\r\n  delete_os_disk_on_termination:                                    "" => "false"\r\n  identity.#:                                                       "" => "<computed>"\r\n  location:                                                         "" => "eastus"\r\n  name:                                                             "" => "myVM"\r\n  network_interface_ids.#:                                          "" => "1"\r\n  network_interface_ids.0:                                          "" => "\/subscriptions\/b[..]\/resourceGroups\/myResourceGroup\/providers\/Microsoft.Network\/networkInterfaces\/myNIC"\r\n  os_profile.#:                                                     "" => "1"\r\n  os_profile.1770182618.admin_password:                             "<sensitive>" => "<sensitive>"\r\n  os_profile.1770182618.admin_username:                             "" => "azureuser"\r\n  os_profile.1770182618.computer_name:                              "" => "myvm"\r\n  os_profile.1770182618.custom_data:                                "" => "<computed>"\r\n  os_profile_linux_config.#:                                        "" => "1"\r\n  os_profile_linux_config.69840937.disable_password_authentication: "" => "true"\r\n  os_profile_linux_config.69840937.ssh_keys.#:                      "" => "1"\r\n  os_profile_linux_config.69840937.ssh_keys.0.key_data:             "" => "ssh-rsa AAAAB3Nz{snip}hwhqT9h"\r\n  os_profile_linux_config.69840937.ssh_keys.0.path:                 "" => "\/home\/azureuser\/.ssh\/authorized_keys"\r\n  resource_group_name:                                              "" => "myResourceGroup"\r\n  storage_data_disk.#:                                              "" => "<computed>"\r\n  storage_image_reference.#:                                        "" => "1"\r\n  storage_image_reference.363552096.id:                             "" => ""\r\n  storage_image_reference.363552096.offer:                          "" => "UbuntuServer"\r\n  storage_image_reference.363552096.publisher:                      "" => "Canonical"\r\n  storage_image_reference.363552096.sku:                            "" => "16.04.0-LTS"\r\n  storage_image_reference.363552096.version:                        "" => "latest"\r\n  storage_os_disk.#:                                                "" => "1"\r\n  storage_os_disk.0.caching:                                        "" => "ReadWrite"\r\n  storage_os_disk.0.create_option:                                  "" => "FromImage"\r\n  storage_os_disk.0.disk_size_gb:                                   "" => "<computed>"\r\n  storage_os_disk.0.managed_disk_id:                                "" => "<computed>"\r\n  storage_os_disk.0.managed_disk_type:                              "" => "Premium_LRS"\r\n  storage_os_disk.0.name:                                           "" => "myOsDisk"\r\n  storage_os_disk.0.write_accelerator_enabled:                      "" => "false"\r\n  tags.%:                                                           "" => "1"\r\n  tags.environment:                                                 "" => "Terraform Demo"\r\n  vm_size:                                                          "" => "Standard_DS1_v2"\r\n\r\nError: Error applying plan:\r\n\r\n1 error(s) occurred:\r\n\r\n* azurerm_virtual_machine.myterraformvm: 1 error(s) occurred:\r\n\r\n* azurerm_virtual_machine.myterraformvm: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest\/azure: Service returned an error. Status=400 Code="InvalidParameter" Message="The value of parameter linuxConfiguration.ssh.publicKeys.keyData is invalid." Target="linuxConfiguration.ssh.publicKeys.keyData"\r\n\r\nTerraform does not automatically rollback in the face of errors.\r\nInstead, your Terraform state file has been partially updated with\r\nany resources that successfully completed. Please address the error\r\nabove and apply again to incrementally change your infrastructure.\r\n<\/pre>\n

######################################################
\nAdd a valid ssh public key to continue creating the VM
\n######################################################<\/p>\n

\r\nriaan@Azure:~\/sites$ vi main.tf\r\nriaan@Azure:~\/sites$ terraform apply\r\nazurerm_resource_group.myterraformgroup: Refreshing state... (ID: \/subscriptions\/b[..]\/resourceGroups\/myResourceGroup)\r\nazurerm_network_security_group.myterraformnsg: Refreshing state... (ID: \/subscriptions\/b[..]-...kSecurityGroups\/myNetworkSecurityGroup)\r\nrandom_id.randomId: Refreshing state... (ID: ZZic4bhOapM)\r\nazurerm_virtual_network.myterraformnetwork: Refreshing state... (ID: \/subscriptions\/b[..]-...crosoft.Network\/virtualNetworks\/myVnet)\r\nazurerm_public_ip.myterraformpublicip: Refreshing state... (ID: \/subscriptions\/b[..]-...t.Network\/publicIPAddresses\/myPublicIP)\r\nazurerm_storage_account.mystorageaccount: Refreshing state... (ID: \/subscriptions\/b[..]-...e\/storageAccounts\/diag[..])\r\nazurerm_subnet.myterraformsubnet: Refreshing state... (ID: \/subscriptions\/b[..]-...irtualNetworks\/myVnet\/subnets\/mySubnet)\r\nazurerm_network_interface.myterraformnic: Refreshing state... (ID: \/subscriptions\/b[..]-...rosoft.Network\/networkInterfaces\/myNIC)\r\n\r\nAn execution plan has been generated and is shown below.\r\nResource actions are indicated with the following symbols:\r\n  + create\r\n\r\nTerraform will perform the following actions:\r\n\r\n  + azurerm_virtual_machine.myterraformvm\r\n      id:                                                               <computed>\r\n      availability_set_id:                                              <computed>\r\n      boot_diagnostics.#:                                               "1"\r\n      boot_diagnostics.0.enabled:                                       "true"\r\n      boot_diagnostics.0.storage_uri:                                   "https:\/\/diag[..].blob.core.windows.net\/"\r\n      delete_data_disks_on_termination:                                 "false"\r\n      delete_os_disk_on_termination:                                    "false"\r\n      identity.#:                                                       <computed>\r\n      location:                                                         "eastus"\r\n      name:                                                             "myVM"\r\n      network_interface_ids.#:                                          "1"\r\n      network_interface_ids.0:                                          "\/subscriptions\/b[..]\/resourceGroups\/myResourceGroup\/providers\/Microsoft.Network\/networkInterfaces\/myNIC"\r\n      os_profile.#:                                                     "1"\r\n      os_profile.1770182618.admin_password:                             <sensitive>\r\n      os_profile.1770182618.admin_username:                             "azureuser"\r\n      os_profile.1770182618.computer_name:                              "myvm"\r\n      os_profile.1770182618.custom_data:                                <computed>\r\n      os_profile_linux_config.#:                                        "1"\r\n      os_profile_linux_config.69840937.disable_password_authentication: "true"\r\n      os_profile_linux_config.69840937.ssh_keys.#:                      "1"\r\n      os_profile_linux_config.69840937.ssh_keys.0.key_data:             "ssh-rsa [..]"\r\n      os_profile_linux_config.69840937.ssh_keys.0.path:                 "\/home\/azureuser\/.ssh\/authorized_keys"\r\n      resource_group_name:                                              "myResourceGroup"\r\n      storage_data_disk.#:                                              <computed>\r\n      storage_image_reference.#:                                        "1"\r\n      storage_image_reference.363552096.id:                             ""\r\n      storage_image_reference.363552096.offer:                          "UbuntuServer"\r\n      storage_image_reference.363552096.publisher:                      "Canonical"\r\n      storage_image_reference.363552096.sku:                            "16.04.0-LTS"\r\n      storage_image_reference.363552096.version:                        "latest"\r\n      storage_os_disk.#:                                                "1"\r\n      storage_os_disk.0.caching:                                        "ReadWrite"\r\n      storage_os_disk.0.create_option:                                  "FromImage"\r\n      storage_os_disk.0.disk_size_gb:                                   <computed>\r\n      storage_os_disk.0.managed_disk_id:                                <computed>\r\n      storage_os_disk.0.managed_disk_type:                              "Premium_LRS"\r\n      storage_os_disk.0.name:                                           "myOsDisk"\r\n      storage_os_disk.0.write_accelerator_enabled:                      "false"\r\n      tags.%:                                                           "1"\r\n      tags.environment:                                                 "Terraform Demo"\r\n      vm_size:                                                          "Standard_DS1_v2"\r\n\r\n\r\nPlan: 1 to add, 0 to change, 0 to destroy.\r\n\r\nDo you want to perform these actions?\r\n  Terraform will perform the actions described above.\r\n  Only 'yes' will be accepted to approve.\r\n\r\n  Enter a value: yes\r\n\r\nazurerm_virtual_machine.myterraformvm: Creating...\r\n  availability_set_id:                                              "" => "<computed>"\r\n  boot_diagnostics.#:                                               "" => "1"\r\n  boot_diagnostics.0.enabled:                                       "" => "true"\r\n  boot_diagnostics.0.storage_uri:                                   "" => "https:\/\/diag[..].blob.core.windows.net\/"\r\n  delete_data_disks_on_termination:                                 "" => "false"\r\n  delete_os_disk_on_termination:                                    "" => "false"\r\n  identity.#:                                                       "" => "<computed>"\r\n  location:                                                         "" => "eastus"\r\n  name:                                                             "" => "myVM"\r\n  network_interface_ids.#:                                          "" => "1"\r\n  network_interface_ids.0:                                          "" => "\/subscriptions\/b[..]\/resourceGroups\/myResourceGroup\/providers\/Microsoft.Network\/networkInterfaces\/myNIC"\r\n  os_profile.#:                                                     "" => "1"\r\n  os_profile.1770182618.admin_password:                             "<sensitive>" => "<sensitive>"\r\n  os_profile.1770182618.admin_username:                             "" => "azureuser"\r\n  os_profile.1770182618.computer_name:                              "" => "myvm"\r\n  os_profile.1770182618.custom_data:                                "" => "<computed>"\r\n  os_profile_linux_config.#:                                        "" => "1"\r\n  os_profile_linux_config.69840937.disable_password_authentication: "" => "true"\r\n  os_profile_linux_config.69840937.ssh_keys.#:                      "" => "1"\r\n  os_profile_linux_config.69840937.ssh_keys.0.key_data:             "" => "ssh-rsa A[..]"\r\n  os_profile_linux_config.69840937.ssh_keys.0.path:                 "" => "\/home\/azureuser\/.ssh\/authorized_keys"\r\n  resource_group_name:                                              "" => "myResourceGroup"\r\n  storage_data_disk.#:                                              "" => "<computed>"\r\n  storage_image_reference.#:                                        "" => "1"\r\n  storage_image_reference.363552096.id:                             "" => ""\r\n  storage_image_reference.363552096.offer:                          "" => "UbuntuServer"\r\n  storage_image_reference.363552096.publisher:                      "" => "Canonical"\r\n  storage_image_reference.363552096.sku:                            "" => "16.04.0-LTS"\r\n  storage_image_reference.363552096.version:                        "" => "latest"\r\n  storage_os_disk.#:                                                "" => "1"\r\n  storage_os_disk.0.caching:                                        "" => "ReadWrite"\r\n  storage_os_disk.0.create_option:                                  "" => "FromImage"\r\n  storage_os_disk.0.disk_size_gb:                                   "" => "<computed>"\r\n  storage_os_disk.0.managed_disk_id:                                "" => "<computed>"\r\n  storage_os_disk.0.managed_disk_type:                              "" => "Premium_LRS"\r\n  storage_os_disk.0.name:                                           "" => "myOsDisk"\r\n  storage_os_disk.0.write_accelerator_enabled:                      "" => "false"\r\n  tags.%:                                                           "" => "1"\r\n  tags.environment:                                                 "" => "Terraform Demo"\r\n  vm_size:                                                          "" => "Standard_DS1_v2"\r\nazurerm_virtual_machine.myterraformvm: Still creating... (10s elapsed)\r\nazurerm_virtual_machine.myterraformvm: Still creating... (20s elapsed)\r\nazurerm_virtual_machine.myterraformvm: Still creating... (30s elapsed)\r\nazurerm_virtual_machine.myterraformvm: Still creating... (40s elapsed)\r\nazurerm_virtual_machine.myterraformvm: Still creating... (50s elapsed)\r\nazurerm_virtual_machine.myterraformvm: Still creating... (1m0s elapsed)\r\nazurerm_virtual_machine.myterraformvm: Still creating... (1m10s elapsed)\r\nazurerm_virtual_machine.myterraformvm: Still creating... (1m20s elapsed)\r\nazurerm_virtual_machine.myterraformvm: Still creating... (1m30s elapsed)\r\nazurerm_virtual_machine.myterraformvm: Creation complete after 1m35s (ID: \/subscriptions\/b[..]-...Microsoft.Compute\/virtualMachines\/myVM)\r\n\r\nApply complete! Resources: 1 added, 0 changed, 0 destroyed.\r\n<\/pre>\n

##################################################################
\nuse built-in editor(vscode?) Comment out the VM so we can destroy
\n##################################################################<\/p>\n

\r\nriaan@Azure:~\/sites$ terraform apply\r\nazurerm_resource_group.myterraformgroup: Refreshing state...\r\n[..]\r\n\r\nAn execution plan has been generated and is shown below.\r\nResource actions are indicated with the following symbols:\r\n  - destroy\r\n\r\nTerraform will perform the following actions:\r\n\r\n  - azurerm_virtual_machine.myterraformvm\r\n\r\n\r\nPlan: 0 to add, 0 to change, 1 to destroy.\r\n\r\nDo you want to perform these actions?\r\n  Terraform will perform the actions described above.\r\n  Only 'yes' will be accepted to approve.\r\n\r\n  Enter a value: yes\r\n\r\nazurerm_virtual_machine.myterraformvm: Destroying... (ID: \/subscriptions\/[..]-...Microsoft.Compute\/virtualMachines\/myVM)\r\n[..]\r\nazurerm_virtual_machine.myterraformvm: Destruction complete after 34s\r\n\r\nApply complete! Resources: 0 added, 0 changed, 1 destroyed.\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

Azure provides a cloud shell with Terraform already installed and even an editor aware of Terraform source. I tested creating<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[103,88],"tags":[],"class_list":["post-1264","post","type-post","status-publish","format-standard","hentry","category-azure","category-terraform"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1264"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1264\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}