Closed immae1 closed 5 years ago
Same issue here. Even add explicit depends_on won't change the behavior.
Same issue there, I found several workaround (like using a null_resource + data to get the IP and do the provision step in another block) but that just looks wrong and is not intuitive at all. Morever, I am actually hitting this issue as I am going through the Terraform Azure Getting start guide (https://learn.hashicorp.com/terraform/azure/provision_az). So if it is not the way it works actually, it should be updated.
By the way, examples (https://github.com/terraform-providers/terraform-provider-azurerm/blob/master/examples/virtual-machines/provisioners/linux/main.tf) are wrong to, because they don't define an host value on the connection, and when doing so, Terrafor will fail because host is not defined. The Azure Getting Start guide is also wrong on that subject (no host is defined).
hi @immae1 @rukawata @eesprit
Thanks for opening this issue.
Taking a look at the example configuration posted above - unfortunately Azure doesn't assign an IP Address to Dynamic Public IP Addresses until they're attached to a booted device (in this case a Virtual Machine), which is why this value is empty from the azurerm_public_ip
Data Source. Instead you should be able to use the null_resource to retrieve the IP Address using the Data Source once the Virtual Machine has booted, for example:
resource "azurerm_public_ip" "test" { ... }
resource "azurerm_virtual_machine" "test" { ... }
data "azurerm_public_ip" "test" {
name = "${azurerm_public_ip.test.name}"
resource_group_name = "${azurerm_virtual_machine.test.resource_group_name}"
}
resource "null_resource" "ansible" {
provisioner "remote-exec" {
# Install Python for Ansible
inline = ["while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done; sudo rm /var/lib/apt/lists/* ; sudo apt-get update ; sudo apt-get install -y python python-pip "]
connection {
user = "${var.admin_username}"
password = "${var.admin_password}"
host = "${data.azurerm_public_ip.test.ip_address}" # <-- note here we're using the Data Source rather than the Resource for a Public IP
}
}
}
Would you be able to take a look and see if that works for you?
This forum is intended to be used for feature enhancements and bugs in the Azure Provider - so that we can keep this forum focused on that we instead ask that broader questions are raised using one of the Community Resources. As such I'm going to close this issue for the moment, but if that doesn't work for you I believe you should be able to get an answer for this using one of the Community Resources.
Thanks!
I'm going to lock this issue because it has been closed for 30 days ā³. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error š¤ š , please reach out to my human friends š hashibot-feedback@hashicorp.com. Thanks!
Community Note
Terraform (and AzureRM Provider) Version
Terraform v0.12.5 provider "azurerm" { version = "1.31.0" }
Affected Resource(s)
azurerm_public_ip
Terraform Configuration Files
Debug Output
Panic Output
Expected Behavior
host = "${azurerm_public_ip.publicip.ip_address}" should have an ip-address for connecting to the generated vm.
Actual Behavior
The host is empty - so no connection could established to the new vm. The funny thing is - if i comment the provision part. i get an ip-address outputed to the cli.
Steps to Reproduce
terraform apply
Important Factoids
References
0000