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

provider/azurerm: Expose any dynamically-assigned private IP address #13965

Merged

Conversation

codekoala
Copy link
Contributor

Currently, if you want to use a private IP address with an Azure Load Balancer, you must statically assign the address in order to reference the IP elsewhere (such as in an azurerm_dns_a_record). If you have something like the following:

resource "azurerm_lb" "demo" {
  name                = "demo-lb"
  location            = "${var.location}"
  resource_group_name = "${var.resource_group}"

  frontend_ip_configuration {
    name                          = "default"
    private_ip_address_allocation = "dynamic"
    subnet_id                     = "${var.subnet_id}"
  }
}

the dynamically-allocated private IP address is visible when you dig into the state using terraform console, but it is inaccessible using interpolation.

This pull request exposes the dynamic private IP address (if any) as private_ip_address for use elsewhere:

resource "azurerm_dns_a_record" "demo" {
  name                = "demo"
  zone_name           = "${var.dns_zone}"
  resource_group_name = "${var.resource_group}"
  ttl                 = "300"
  records             = ["${azurerm_lb.demo.private_ip_address}"]
}

@tombuildsstuff tombuildsstuff changed the title Expose any dynamically-assigned private IP address provider/azurerm: Expose any dynamically-assigned private IP address Apr 26, 2017
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @codekoala

Thanks for this PR - I've left a comment in-line but it otherwise looks good :)


for _, config := range ipconfig {
cfg := config.(map[string]interface{})
if priv_ip, ok := cfg["private_ip_address"]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better to iterate over the loadBalancer.LoadBalancerPropertiesFormat.FrontendIPConfigurations here, rather than the flattened list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That had occurred to me too. I opted to iterate over the flattened list so there would be a single piece of code accessing loadBalancer.LoadBalancerPropertyFormat.FrontendIPConfigurations.*.FrontendIPConfigurationPropertiesFormat.PrivateIPAddress, just in case the API changes in the future.

I can definitely switch it up when I get back to a keyboard tomorrow if you'd like though!

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @codekoala

Thanks for pushing the updates here - I've taken another look and this LGTM :)

The tests pass:

$ envchain azurerm make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMLoadBalancer'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/04/27 10:02:59 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMLoadBalancer -timeout 120m
=== RUN   TestAccAzureRMLoadBalancerBackEndAddressPool_importBasic
--- PASS: TestAccAzureRMLoadBalancerBackEndAddressPool_importBasic (105.85s)
=== RUN   TestAccAzureRMLoadBalancerNatPool_importBasic
--- PASS: TestAccAzureRMLoadBalancerNatPool_importBasic (101.23s)
=== RUN   TestAccAzureRMLoadBalancerNatRule_importBasic
--- PASS: TestAccAzureRMLoadBalancerNatRule_importBasic (104.67s)
=== RUN   TestAccAzureRMLoadBalancerProbe_importBasic
--- PASS: TestAccAzureRMLoadBalancerProbe_importBasic (103.20s)
=== RUN   TestAccAzureRMLoadBalancerRule_importBasic
--- PASS: TestAccAzureRMLoadBalancerRule_importBasic (108.42s)
=== RUN   TestAccAzureRMLoadBalancer_importBasic
--- PASS: TestAccAzureRMLoadBalancer_importBasic (83.88s)
=== RUN   TestAccAzureRMLoadBalancerBackEndAddressPool_basic
--- PASS: TestAccAzureRMLoadBalancerBackEndAddressPool_basic (95.01s)
=== RUN   TestAccAzureRMLoadBalancerBackEndAddressPool_removal
--- PASS: TestAccAzureRMLoadBalancerBackEndAddressPool_removal (103.33s)
=== RUN   TestAccAzureRMLoadBalancerBackEndAddressPool_reapply
--- PASS: TestAccAzureRMLoadBalancerBackEndAddressPool_reapply (118.21s)
=== RUN   TestAccAzureRMLoadBalancerBackEndAddressPool_disappears
--- PASS: TestAccAzureRMLoadBalancerBackEndAddressPool_disappears (104.65s)
=== RUN   TestAccAzureRMLoadBalancerNatPool_basic
--- PASS: TestAccAzureRMLoadBalancerNatPool_basic (107.88s)
=== RUN   TestAccAzureRMLoadBalancerNatPool_removal
--- PASS: TestAccAzureRMLoadBalancerNatPool_removal (126.45s)
=== RUN   TestAccAzureRMLoadBalancerNatPool_update
--- PASS: TestAccAzureRMLoadBalancerNatPool_update (149.92s)
=== RUN   TestAccAzureRMLoadBalancerNatPool_reapply
--- PASS: TestAccAzureRMLoadBalancerNatPool_reapply (138.87s)
=== RUN   TestAccAzureRMLoadBalancerNatPool_disappears
--- PASS: TestAccAzureRMLoadBalancerNatPool_disappears (225.81s)
=== RUN   TestAccAzureRMLoadBalancerNatRule_basic
--- PASS: TestAccAzureRMLoadBalancerNatRule_basic (101.34s)
=== RUN   TestAccAzureRMLoadBalancerNatRule_removal
--- PASS: TestAccAzureRMLoadBalancerNatRule_removal (110.35s)
=== RUN   TestAccAzureRMLoadBalancerNatRule_update
--- PASS: TestAccAzureRMLoadBalancerNatRule_update (144.07s)
=== RUN   TestAccAzureRMLoadBalancerNatRule_reapply
--- PASS: TestAccAzureRMLoadBalancerNatRule_reapply (140.07s)
=== RUN   TestAccAzureRMLoadBalancerNatRule_disappears
--- PASS: TestAccAzureRMLoadBalancerNatRule_disappears (107.00s)
=== RUN   TestAccAzureRMLoadBalancerProbe_basic
--- PASS: TestAccAzureRMLoadBalancerProbe_basic (90.18s)
=== RUN   TestAccAzureRMLoadBalancerProbe_removal
--- PASS: TestAccAzureRMLoadBalancerProbe_removal (124.36s)
=== RUN   TestAccAzureRMLoadBalancerProbe_update
--- PASS: TestAccAzureRMLoadBalancerProbe_update (125.19s)
=== RUN   TestAccAzureRMLoadBalancerProbe_updateProtocol
--- PASS: TestAccAzureRMLoadBalancerProbe_updateProtocol (117.87s)
=== RUN   TestAccAzureRMLoadBalancerProbe_reapply
--- PASS: TestAccAzureRMLoadBalancerProbe_reapply (120.73s)
=== RUN   TestAccAzureRMLoadBalancerProbe_disappears
--- PASS: TestAccAzureRMLoadBalancerProbe_disappears (91.11s)
=== RUN   TestAccAzureRMLoadBalancerRule_basic
--- PASS: TestAccAzureRMLoadBalancerRule_basic (84.67s)
=== RUN   TestAccAzureRMLoadBalancerRule_removal
--- PASS: TestAccAzureRMLoadBalancerRule_removal (112.93s)
=== RUN   TestAccAzureRMLoadBalancerRule_inconsistentReads
--- PASS: TestAccAzureRMLoadBalancerRule_inconsistentReads (120.43s)
=== RUN   TestAccAzureRMLoadBalancerRule_update
--- PASS: TestAccAzureRMLoadBalancerRule_update (132.46s)
=== RUN   TestAccAzureRMLoadBalancerRule_reapply
--- PASS: TestAccAzureRMLoadBalancerRule_reapply (114.33s)
=== RUN   TestAccAzureRMLoadBalancerRule_disappears
--- PASS: TestAccAzureRMLoadBalancerRule_disappears (104.48s)
=== RUN   TestAccAzureRMLoadBalancer_basic
--- PASS: TestAccAzureRMLoadBalancer_basic (66.58s)
=== RUN   TestAccAzureRMLoadBalancer_frontEndConfig
--- PASS: TestAccAzureRMLoadBalancer_frontEndConfig (124.67s)
=== RUN   TestAccAzureRMLoadBalancer_tags
--- PASS: TestAccAzureRMLoadBalancer_tags (95.81s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/azurerm	4006.047s

Thanks!

@tombuildsstuff tombuildsstuff merged commit a23201a into hashicorp:master Apr 27, 2017
tombuildsstuff added a commit that referenced this pull request Apr 27, 2017
@codekoala
Copy link
Contributor Author

Thank you!

@ghost
Copy link

ghost commented Apr 13, 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

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

Successfully merging this pull request may close these issues.

2 participants