Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to get public ip of load balancer #773

Closed
RainFlying opened this issue Jan 30, 2018 · 4 comments
Closed

Failed to get public ip of load balancer #773

RainFlying opened this issue Jan 30, 2018 · 4 comments

Comments

@RainFlying
Copy link

For some reason, I need to assign several IPs to one load balancer. After some reading, I know that in order to get the dynamic public ip of the load balancer, I should use azurerm_public_ip data source. However, this doesn't work when there are multiple IPs.

Here is part of the tf file:

esource "azurerm_public_ip" "ip" {
  count = 6
  name = "${var.project}-ip${count.index + 1}"
  location = "${azurerm_resource_group.group.location}"
  resource_group_name = "${azurerm_resource_group.group.name}"
  public_ip_address_allocation = "dynamic"
  domain_name_label = "${var.project}-lbip${count.index + 1}"
}

resource "azurerm_lb" "lb" {
  name = "${var.project}-lb"
  location = "${azurerm_resource_group.group.location}"
  resource_group_name = "${azurerm_resource_group.group.name}"

  frontend_ip_configuration {
    name = "${var.project}-lb-ipconfig1"
    public_ip_address_id = "${azurerm_public_ip.ip.0.id}"
  }

  frontend_ip_configuration {
    name = "${var.project}-lb-ipconfig2"
    public_ip_address_id = "${azurerm_public_ip.ip.1.id}"
  }

  frontend_ip_configuration {
    name = "${var.project}-lb-ipconfig3"
    public_ip_address_id = "${azurerm_public_ip.ip.2.id}"
  }

  frontend_ip_configuration {
    name = "${var.project}-lb-ipconfig4"
    public_ip_address_id = "${azurerm_public_ip.ip.3.id}"
  }

  frontend_ip_configuration {
    name = "${var.project}-lb-ipconfig5"
    public_ip_address_id = "${azurerm_public_ip.ip.4.id}"
  }

  frontend_ip_configuration {
    name = "${var.project}-lb-ipconfig6"
    public_ip_address_id = "${azurerm_public_ip.ip.5.id}"
  }
}

Azurerm_public_ip data sources doesn't suport interpolation, so I have to create a lot of data sources.

data "azurerm_public_ip" "lb_ip1" {
  name = "${azurerm_public_ip.ip.0.name}"
  resource_group_name = "${azurerm_resource_group.group.name}"
  depends_on = ["azurerm_lb.lb"]
}

data "azurerm_public_ip" "lb_ip2" {
  name = "${azurerm_public_ip.ip.1.name}"
  resource_group_name = "${azurerm_resource_group.group.name}"
  depends_on = ["azurerm_lb.lb"]
}

output "lb_ip1" {
  value = "${data.azurerm_public_ip.lb_ip1.ip_address}"
}

output "lb_ip2" {
  value = "${data.azurerm_public_ip.lb_ip2.ip_address}"
}

Terraform failed to apply the tf file. The error message is

* module.main.output.lb_ip1: Resource 'data.azurerm_public_ip.lb_ip1' does not have attribute 'ip_address' for variable 'data.azurerm_public_ip.lb_ip1.ip_address'
* module.main.output.lb_ip2: Resource 'data.azurerm_public_ip.lb_ip2' does not have attribute 'ip_address' for variable 'data.azurerm_public_ip.lb_ip2.ip_address'

The data sources depends on lb resource, dynamic IP is created when the load balancer with this IP assigned is active. There should be no issue getting the IP. Is there any issue with the usage here ? And is there any better solution to get all the IP addresses of the load balancer ?

@ghost
Copy link

ghost commented Jan 30, 2018

It appears that as of 1.1.0 the ip_address property is only set if the DNSSettings property exists. We deploy virtual machines without domain name labels, and yesterday our plans were suddenly no longer able to retrieve the public IP address as an output variable.

As @genevieve pointed this in the commit, it appears that simply moving the ip_address logic outside the DNSSettings block should fix the issue.

Affected block starts at line 222 of resource_arm_public_ip.go

@genevieve
Copy link

#772

@tombuildsstuff tombuildsstuff added this to the 1.1.1 milestone Feb 7, 2018
@tombuildsstuff
Copy link
Contributor

hey @RainFlying

Thanks for opening this issue - apologies for the delayed response here!

This appears to be a duplicate of #771 which has been fixed via #772 which has now been released in v1.1.1 of the Azure Provider earlier today. Would you be able to upgrade to this version and see if that solves your issue?

Thanks!

@ghost
Copy link

ghost commented Mar 31, 2020

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!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants