Home > other >  terraform aws_secretsmanager_secret_version set base64encode(file("./src/secret.json")) as
terraform aws_secretsmanager_secret_version set base64encode(file("./src/secret.json")) as

Time:09-17

I am trying to setup a key value secret in AWS Secrets Manager with terraform. Now I would like to replace the string "AzureDiamond" with a base64 encoded json object. Can you help me how I could replace the mentioned string with the value returned by this base64encode(file("./src/secret.json"))

resource "aws_secretsmanager_secret_version" "testtools" {
    secret_id     = aws_secretsmanager_secret.testtools.id
    secret_string = "{\"config\":\"AzureDiamond\"}"
}

CodePudding user response:

I think the easiest way is to use filebase64 with jsonencode:

resource "aws_secretsmanager_secret_version" "testtools" {
    secret_id     = aws_secretsmanager_secret.testtools.id
    secret_string = jsonencode({config = filebase64("./src/secret.json")})
}
  • Related