Learn Azure Terraform newbie

I am stuck here with the tutorial, any help would be greatly appreciated.

here is the error
Error: timeout - last error: dial tcp: lookup /subscriptions//resourceGroups/myTFResourceGroup/providers/Microsoft.Network/publicIPAddresses/myTFPublicIP: no such host

main.tf
/*

  • Demonstrate use of provisioner ‘remote-exec’ to execute a command
  • on a new VM instance.
    */

/*

  • NOTE: It is very poor practice to hardcode sensitive information
  • such as user name, password, etc. Hardcoded values are used here
  • only to simplify the tutorial.
    */
    variable “admin_username” {
    default = “plankton”
    }
    variable “admin_password” {
    default = “Password1234!”
    }

variable “resource_prefix” {
default = “my”
}

You’ll usually want to set this to a region near you.

variable “location” {
default = “centralus”
}

Configure the provider.

provider “azurerm” {
version = “=1.28.0”
}

Create a resource group

resource “azurerm_resource_group” “rg” {
name = “{var.resource_prefix}TFResourceGroup" location = "{var.location}”
}

Create virtual network

resource “azurerm_virtual_network” “vnet” {
name = “{var.resource_prefix}TFVnet" address_space = ["10.0.0.0/16"] location = "{var.location}”
resource_group_name = “${azurerm_resource_group.rg.name}”
}

Create subnet

resource “azurerm_subnet” “subnet” {
name = “{var.resource_prefix}TFSubnet" resource_group_name = "{azurerm_resource_group.rg.name}”
virtual_network_name = “${azurerm_virtual_network.vnet.name}”
address_prefix = “10.0.1.0/24”
}

Create public IP

resource “azurerm_public_ip” “publicip” {
name = “{var.resource_prefix}TFPublicIP" location = "{var.location}”
resource_group_name = “${azurerm_resource_group.rg.name}”
allocation_method = “Dynamic”
}

Create Network Security Group and rule

resource “azurerm_network_security_group” “nsg” {
name = “{var.resource_prefix}TFNSG" location = "{var.location}”
resource_group_name = “${azurerm_resource_group.rg.name}”

security_rule {
    name                       = "SSH"
    priority                   = 1001
    direction                  = "Inbound"
    access                     = "Allow"
    protocol                   = "Tcp"
    source_port_range          = "*"
    destination_port_range     = "22"
    source_address_prefix      = "*"
    destination_address_prefix = "*"
}

}

Create network interface

resource “azurerm_network_interface” “nic” {
name = “{var.resource_prefix}NIC" location = "{var.location}”
resource_group_name = “{azurerm_resource_group.rg.name}" network_security_group_id = "{azurerm_network_security_group.nsg.id}”

ip_configuration {
    name                          = "${var.resource_prefix}NICConfg"
    subnet_id                     = "${azurerm_subnet.subnet.id}"
    private_ip_address_allocation = "dynamic"
    public_ip_address_id          = "${azurerm_public_ip.publicip.id}"
}

}

Create a Linux virtual machine

resource “azurerm_virtual_machine” “vm” {
name = “{var.resource_prefix}TFVM" location = "{var.location}”
resource_group_name = “{azurerm_resource_group.rg.name}" network_interface_ids = ["{azurerm_network_interface.nic.id}”]
vm_size = “Standard_DS1_v2”

storage_os_disk {
    name              = "${var.resource_prefix}OsDisk"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Premium_LRS"
}

storage_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04.0-LTS"
    version   = "latest"
}

os_profile {
    computer_name  = "${var.resource_prefix}TFVM"
    admin_username = "${var.admin_username}"
    admin_password = "${var.admin_password}"
}

os_profile_linux_config {
    disable_password_authentication = false
}

provisioner "file" {
    connection {
        type = "ssh"
        user = "${var.admin_username}"
        password = "${var.admin_password}"
        host = azurerm_public_ip.publicip.id
    }

    source = "newfile.txt"
    destination = "newfile.txt"
}

provisioner "remote-exec" {
    connection {
        type = "ssh"
        user     = "${var.admin_username}"
        password = "${var.admin_password}"
        host = azurerm_public_ip.publicip.id
    }

    inline = [
    "ls -a",
    "cat newfile.txt"
    ]
}

}

Are you using Terraform 0.11 or 0.12? We are rewriting this guide for Terraform 0.12 as the existing code will only work with Terraform 0.11.

Or, could you create a GitHub gist or similar with the code you are trying to run? (Be sure to omit any cloud credentials or other secrets.)

https://gist.github.com

i skipped that part of the tutorial since I understood the just of what was going on. I am using .12.x so that may have been an issue as well.

thanks for the reply and help :slight_smile: