Terraform-provider-aws: A managed resource "aws_secretsmanager_secret_version" "db_password" has not been declared in the root module.

Created on 11 Dec 2019  ยท  3Comments  ยท  Source: hashicorp/terraform-provider-aws

Attempting to use AWS secrets manager and jsondecode throws the following errors:

on rds.tf line 27, in resource "aws_db_instance" "dev-test":
27: username = jsondecode(aws_secretsmanager_secret_version.db_password.secret_string)["username"]

on rds.tf line 28, in resource "aws_db_instance" "dev-test":
28: password = jsondecode(aws_secretsmanager_secret_version.db_password.secret_string)["password"]

This is defined at the top of the very same Terraform file as:
data "aws_secretsmanager_secret_version" "db_password" {
secret_id = "secret-name"
}

Terraform v0.12.18

When using this with Terraform 11 and without jsondecode I was able to pull the required secret from AWS without any problems.

needs-triage servicrds servicsecretsmanager

Most helpful comment

You access the data resources by putting "data." before the name: data.aws_secretsmanager_secret_version

All 3 comments

You access the data resources by putting "data." before the name: data.aws_secretsmanager_secret_version

This solved the problem for me. The examples in all the documentation I found on this did not show the data. before as indicated here. Thank you.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings