Inappropriate value for attribute "secret_string": string required

Viewed 28

I have the following terraform that creates RDS instance and then try to create a new key-value in existing secret.

Get rds credentials from the secret manager.

locals {
  db_name  = "mydb"
  username = jsondecode(data.aws_secretsmanager_secret_version.rdscreds.secret_string)["rds_username"]
  password = jsondecode(data.aws_secretsmanager_secret_version.rdscreds.secret_string)["rds_password"]
}

create rds instance (some variables removed for brevity)

module "rds" {
  source                  = "git::https://scm....."
  db_name                 = local.db_name
  username                = local.username
  password                = local.password
}

create a new key in existing secret

locals {
  database_url = "{\"DATABASE_URL\": \"postgres://${local.username}:${local.password}@${module.rds.endpoint}/${local.db_name}\"}"
}

resource "aws_secretsmanager_secret_version" "example" {
  secret_id     = "some existing secret"
  secret_string = jsondecode(local.database_url)
}

When I apply getting following error

Error: Incorrect attribute value type
│
│   on ..\..\..\..\..\applications\rds\db_instance\main.tf line 76, in resource "aws_secretsmanager_secret_version" "example":
│   76:   secret_string = jsondecode(local.database_url)
│     ├────────────────
│     │ local.database_url has a sensitive value
│
│ Inappropriate value for attribute "secret_string": string required.
1 Answers

secret_string is just a string, not TF map nor any other variable. So it should be:

secret_string = local.database_url
Related