variable "ext_ip" {
default = false
type = bool
description = "assign external ip to the instance"
}
Now I need to add an empty block to resource config depending on its value:
resource "google_compute_instance" "vm" {
network_interface {access_config {} // <- this block is optional}}The I came out with two ways of doing (both are ugly as hell):resource "google_compute_instance" "vm" {
network_interface {
dynamic "access_config" {
for_each = var.ext_ip ? [""] : []
content {}
}
}
}resource "google_compute_instance" "vm" {
network_interface {
dynamic "access_config" {
for_each = [""]
content {}if var.ext_ip}
}
}Is there any other non-ugly way?
Hi!
With terraform out it is now easy to make dynamic blocks. But what if I want to make a conditional block. E.g.: I have a module with bool variable:
variable "ext_ip" { default = false type = bool description = "assign external ip to the instance" }Now I need to add an empty block to resource config depending on its value:resource "google_compute_instance" "vm" { network_interface {access_config {} // <- this block is optional}}The I came out with two ways of doing (both are ugly as hell):resource "google_compute_instance" "vm" { network_interface { dynamic "access_config" { for_each = var.ext_ip ? [""] : [] content {} } } }
I posted something similar a few days ago as did someone else.
This one (above) is the one we've gone with
resource "google_compute_instance" "vm" { network_interface { dynamic "access_config" { for_each = [""] content {}if var.ext_ip} } }Is there any other non-ugly way?
--
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-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/ec18a5bd-b095-49a2-9c68-b26824f2285d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-- Stuart Clark