Hi team,
I’m trying to move all legacy code to Terraform Cloud.
But I have a problem when using the terraform cloud provider to auto input variables.
I have a terraform folder like that:
terraform-cloud
├── config
│ ├── dev.tfvars
│ └── stg.tfvars
├── providers.tf
├── terraform.tfstate.d
│ ├── dev
│ │ ├── terraform.tfstate
│ │ └── terraform.tfstate.backup
│ └── stg
│ ├── terraform.tfstate
│ └── terraform.tfstate.backup
├── tfe_variable.tf
├── variables.tf
└── workspace.tf
variables.tf
variable "rds" {
type = map(string)
}
in dev.tfvars, I have a variable type map(string)
rds = {
number_of_instance = "1"
allocated_storage = "10"
engine = "mysql"
engine_version = "5.7.26"
instance_type = "db.t3.micro"
storage_type = "gp2"
database_identifier = "db"
backup_retention_period = "1"
preferred_backup_window = "14:00-17:00"
preferred_maintenance_window = "sun:17:01-sun:17:31"
final_snapshot_identifier = "final-db-snapshot"
monitoring_interval = "60"
monitoring_role_name = "rds-monitoring-role"
auto_minor_version_upgrade = false
multi_availability_zone = false
storage_encrypted = true
skip_final_snapshot = false
copy_tags_to_snapshot = true
is_enable_readreplica = false
apply_immediately = true
parameter_group_family = "mysql5.7"
}
and now, I want to create it on Variable of Terraform Cloud GUI
resource "tfe_variable" "rds2" {
key = "rds2"
value = var.rds
hcl = true
category = "terraform"
workspace_id = tfe_workspace.test.id
description = "a useful description"
}
And Failed when apply
$terraform apply -var-file=./config/dev.tfvars
╷
│ Error: Incorrect attribute value type
│
│ on tfe_variable.tf line 67, in resource “tfe_variable” “rds2”:
│ 67: value = var.rds
│ ├────────────────
│ │ var.rds is a map of string, known only after apply
│
│ Inappropriate value for attribute “value”: string required.
After that I tried: (jsonencode)
resource "tfe_variable" "rds2" {
key = "rds2"
value = jsonencode(var.rds)
hcl = true
category = "terraform"
workspace_id = tfe_workspace.test.id
description = "a useful description"
}
Ok to apply, but could not use it as a map.
Please help me!