Unable to get the Public IP (Dynamic IP) in output with azurerm

38 views
Skip to first unread message

Suraj Muthreja

unread,
May 22, 2018, 3:07:14 PM5/22/18
to Terraform
Hi Team,

I am not able to get the Public IP in output when dynamic IP allocation is used with azurerm.

Below is the snippet from template:

# Create public IPs
resource "azurerm_public_ip" "myterraformpublicip" {
    name                         = "myPublicIPTerraform"
    location                     = "westus"
    resource_group_name          = "${azurerm_resource_group.myterraformgroup.name}"
    public_ip_address_allocation = "dynamic"

    tags {
        environment = "myTerraformDemo"
    }
}

# Create network interface
resource "azurerm_network_interface" "myterraformnic1" {
    name                      = "myNICTerraform1"
    location                  = "westus"
    resource_group_name       = "${azurerm_resource_group.myterraformgroup.name}"
    network_security_group_id = "${azurerm_network_security_group.myterraformnsg.id}"

    ip_configuration {
        name                          = "myNICTerraformConfiguration"
        subnet_id                     = "${azurerm_subnet.myterraformsubnet.id}"
        private_ip_address_allocation = "dynamic"
        public_ip_address_id          = "${azurerm_public_ip.myterraformpublicip.id}"
    }

    tags {
        environment = "myTerraformDemo"
    }
}

# Create virtual machine
resource "azurerm_virtual_machine" "myterraformvm" {
    name                  = "myVMTerraform"
    location              = "westus"
    resource_group_name   = "${azurerm_resource_group.myterraformgroup.name}"
primary_network_interface_id = "${azurerm_network_interface.myterraformnic1.id}"
    vm_size               = "Standard_DS3"

    storage_os_disk {
        name              = "myOsDisk"
        caching           = "ReadWrite"
        create_option     = "FromImage"
        managed_disk_type = "Standard_LRS"
    }

    storage_image_reference {
        id="Image reference"
    }

    os_profile {
        computer_name  = "myVMTerraform"
        admin_username = "azure_devops"
    }

    os_profile_linux_config {
        disable_password_authentication = true
        ssh_keys {
            path     = "path to ssh key"
            key_data = "ssh key here"
        }
    }

    boot_diagnostics {
        enabled = "true"
        storage_uri = "${azurerm_storage_account.mystorageaccount.primary_blob_endpoint}"
    }
    tags {
        environment = "myTerraformDemo"
    }
}

output "public_ip" {
  value = "${azurerm_public_ip.myterraformpublicip.ip_address}"
}

But this gives error as "does not have attribute 'ip_address' for variable".
I saw one closed issue https://github.com/hashicorp/terraform/issues/6634 related to this problem. Is this fixed?
Can anyone please help here.

Terraform version: 
Terraform v0.11.7
+ provider.azurerm v1.5.0


Thanks,
Suraj Muthreja.

Reply all
Reply to author
Forward
0 new messages