Reputation: 484
I am trying to do some conditional changes in terraform.
resource "azurerm_mssql_database" "war" {
name = "${local.clSqlDatabaseName}-${var.environment}"
server_id = jokes
min_capacity = 0.5
max_size_gb = 100
zone_redundant = false
collation = "SQL_Latin1_General_CP1_CI_AS"
sku_name = "GP_S_Gen5_2"
auto_pause_delay_in_minutes = "${var.environment == "Prod" ? -1 : 60}"
short_term_retention_policy {
retention_days = 35
}
auto_pause_delay_in_minutes is dependent on the environment variable == Prod and thats fair enough , but how do i make the short_term_retention_policy be dependent on the Prod variable too ?
Upvotes: 0
Views: 80
Reputation: 16815
You would want to make the short_term_retention_policy
dynamic:
resource "azurerm_mssql_database" "war" {
name = "${local.clSqlDatabaseName}-${var.environment}"
server_id = jokes
min_capacity = 0.5
max_size_gb = 100
zone_redundant = false
collation = "SQL_Latin1_General_CP1_CI_AS"
sku_name = "GP_S_Gen5_2"
auto_pause_delay_in_minutes = "${var.environment == "Prod" ? -1 : 60}"
dynamic "short_term_retention_policy" {
for_each = var.environment == "Prod" ? [1] : []
content {
retention_days = 35
}
}
}
This short_term_retention_policy
will be applied only if var.environment
is "Prod", otherwise it will be ignored.
Upvotes: 1