Terraform conditional help argument to public_ip_adress_id Azure

305 views
Skip to first unread message

Don Ky

unread,
May 1, 2017, 5:06:15 PM5/1/17
to Terraform
Hello all,

I'm struggling on how to make the parameter public_ip_adress_id optional using the azurerm_network_interface resource. 

In my original code block:

ip_configuration {
    name                          = "vm-ip"
    subnet_id                     = "${data.terraform_remote_state.vnet.external_subnet_id}"
    private_ip_address_allocation = "dynamic"
    public_ip_adress_id           = "${azurerm_public_ip.test.id}"
}

Works fine as it associates it to my public_ip resource. 

Now I want to make this parameter optional. Since on internal machines we don't need to assign public ip addresses so I'm using a variable with a bool to enable or disable creation of the public ip address. The issue is then how do we make this parameter optional? 

I've tried the following with no avail and have been struggling for a bit researching how this could work:


ip_configuration {
    name                          = "vm-ip"
    subnet_id                     = "${data.terraform_remote_state.vnet.external_subnet_id}"
    private_ip_address_allocation = "dynamic"
    public_ip_adress_id           = "${var.enable_public_ip == true ? azure_public_ip.test.id : list() }"
}

Any pointers would be useful.

Thanks 

Haydn Dufrene

unread,
May 1, 2017, 10:46:55 PM5/1/17
to terrafo...@googlegroups.com
not totally familiar with the use case, but when i have desired to have different setups per environment, i have done this by resource count, and looks like this has become suggested practice. (https://www.terraform.io/docs/state/environments.html#current-environment-interpolation) it could be a little cumbersome to copy configs across larger resources but unaware of a better option

you could try using the tertiary operator in count with a variable to see if you have better success.. i just did a quick little test and looks like it should work.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/b48c2c69-21f8-4f82-bd58-0ec4d4602917%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
CONFIDENTIALITY NOTE

The information transmitted, including attachments, is intended only for the person(s) or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and destroy any copies of this information.

Reply all
Reply to author
Forward
0 new messages