Reputation: 380
I'm creating a terraform config (let's call it config A) who is used as a module in another config (config B). In config A I have a optional variable who is a comma separated string (without space) contain IP addresses or IP address ranges in CIDR form. What I want is to skip or not set value of this variable if there is no IP's as input from config B. I tried set "" as value, but that of course not work. Also tried other values, but can't figure it out.
Is there any way to have this work or must I create two config (let's call it config A.1 and A.2) where A.1 contains the string variable, and A.2 not.
Maybe a sample code of what I try to do can help.
#Config A
resource "azurerm_cosmosdb_account" "db" {
name = "${var.name_from_module_caller}"
location = "northeuropa"
resource_group_name = "test-cosmos-db-from-terraform"
offer_type = "Standard"
consistency_policy = {
consistency_level = "Session"
}
geo_location = {
location = "northeuropa"
location = "${azurerm_resource_group.rg.location}"
failover_priority = 0
}
ip_range_filter = "${var.whitelis_ip_from_module_caller}" #Need a way to skip this, if var.whitelis_ip_from_module_caller is "". Can't use ""
}
#Config B
module "test-cosmos-db" {
source = "/module/azure_cosmos_module" #This is the Config A
name_from_module_caller = "test-cosmosdb"
# whitelis_ip_from_module_caller //NOT SET, BECAUSE THIS MUST BE OPENED FOR EVERYONE
}
I
Upvotes: 3
Views: 9484
Reputation: 1026
As of terraform version 0.12 there is a null value. If you set this as the default value in your module input variable it will effectively omit ip_range_filter
from the resource when it is instantiated.
Upvotes: 3