I noticed in old versions of terraform, don’t have “null” type to omit optional attribute. Is there any workaround to omit optional attribute for older versions where “null” type is not supported.
In my specific case, I am trying to create route in AWS Route table, I have 2 optional attribute in resource nat_gateway_id
or transit_gateway_id
. only one can be added at a time.
variable "tgw" {
default = true
}
resource "aws_route" "r" {
route_table_id = "rtb-"
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = "${var.tgw ? "" : aws_nat_gateway.nat_gateway.id}"
transit_gateway_id = "${var.tgw ? var.tgw_id : "" }"
}
it’s failing currently with error,
Error: more than 1 target specified. Only 1 of gateway_id, egress_only_gateway_id, nat_gateway_id, instance_id, network_interf****_id or vpc_peering_connection_id is allowed.
Is there any way to get this working?
Creating 2 resources separately and add count attribute based on condition is last option for me. Wants to see if there is any way to get this working on 1 resource.
Thanks,