There is issue with command line input for any string attribute inside a map/object variable. the below configuration works with below command. But the moment I use any string attribute inside the object variable. it fails
terraform plan -var='storageProfile2={"storage_mb":102400,"backup_retention_days":15,"geo_redundant_backup_enabled":false}'
//main.tf
resource "azurerm_postgresql_server" "dmcdevops_postgress" {
name = "pstgressdb101"
location = azurerm_resource_group.dmc_rg_creation.location
resource_group_name = azurerm_resource_group.dmc_rg_creation.name
sku_name = "GP_Gen5_4"
backup_retention_days = var.storageProfile2.backup_retention_days
storage_mb = var.storageProfile2.storage_mb
geo_redundant_backup_enabled = var.storageProfile2.geo_redundant_backup_enabled
administrator_login = "sdfgsgfsg"
administrator_login_password = "H@Sh1CoR3!"
version = "11"
ssl_enforcement_enabled = true
}
//variables.tf
variable "storageProfile2" {
default = {
storage_mb = 102400
backup_retention_days = 15
geo_redundant_backup_enabled = false
}
type = object(
{
storage_mb = number
backup_retention_days = number
geo_redundant_backup_enabled = bool
}
)
}
Below config doesn't work. I just added administrator_login as string attribute to the object variable. terraform plan and apply works with default values tho.
terraform plan -var='storageProfile2={"storage_mb":102400,"backup_retention_days":15,"geo_redundant_backup_enabled":false,"administrator_login":"pgadmin1223"}'
//main.tf
resource "azurerm_postgresql_server" "dmcdevops_postgress" {
name = "pstgressdb101"
location = azurerm_resource_group.dmc_rg_creation.location
resource_group_name = azurerm_resource_group.dmc_rg_creation.name
sku_name = "GP_Gen5_4"
backup_retention_days = var.storageProfile2.backup_retention_days
storage_mb = var.storageProfile2.storage_mb
geo_redundant_backup_enabled = var.storageProfile2.geo_redundant_backup_enabled
administrator_login = var.storageProfile2.administrator_login
administrator_login_password = "H@Sh1CoR3!"
version = "11"
ssl_enforcement_enabled = true
}
//varibale.tf
variable "storageProfile2" {
default = {
storage_mb = 102400
backup_retention_days = 15
geo_redundant_backup_enabled = false
administrator_login = "pgadmin"
}
type = object(
{
storage_mb = number
backup_retention_days = number
geo_redundant_backup_enabled = bool
administrator_login = string
}
)
}
Error message
"
and so the syntax is no longer valid. It would work in your first case because coincidentally it's valid to omit the quotes on an attribute name, but an unquoted identifier in a normal expression is understood as a reference and references are not allowed in variable values. – Martin Atkins