Terraform – AWS SSM: Extract content

The SSM Parameter Store contains the following JSON:

{
  "username": "admin",
  "password": "password"
}

 

It is necessary to extract the login and password, and use their values in the Terraform code. To do this, you can use the following construction:

# Should be there before the apply
data "aws_ssm_parameter" "rds-admin-user" {
  name  = "/ARTEM-SERVICES/PROD/RDS/CREDENTIALS"
}

locals {
  additional_rds_username      = jsondecode(data.aws_ssm_parameter.rds-admin-user.value)["username"]
  additional_rds_user_password = jsondecode(data.aws_ssm_parameter.rds-admin-user.value)["password"]
}

 

And use variables:

local.additional_rds_username
local.additional_rds_user_password

 

 

Tagged: Tags

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments