Skip to content

Conversation

manu-akw
Copy link
Contributor

fix decoding of password

provider "postgresql" {
[...]
password = data.aws_secretsmanager_secret_version.postgres_password.secret_string
password = jsondecode(data.aws_secretsmanager_secret_version.postgres_password.secret_string)["password"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong but this seems to depends of what you put in the secret_string no?

I mean one could put the password directly and not a JSON containing a password field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you use the AWS Secrets Manager, the secrets are always stored as key/value pairs, so there is no way around the JSON format.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the secrets are always stored as key/value pairs

Actually no, if you define the secret with the key/value tab in the AWS console, it indeed generates JSON, but the SecretString is a text in which you can put what you want.
In the AWS console, there's even a "plaintext" tab in which you can enter a raw string, e.g.:

image

But as your example could indeed be a typical setup (many users will set a JSON), I'm ok to merge this example 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I took an extra look at the console yesterday, but somehow overlooked this option. Sorry, you're right👍

Just a small addition: if you create an RDS in AWS with Terraform, it is possible to set the attribute "manage_master_user_password" to true, then the credentials are automatically managed by the RDS itself in the Secrets Manager. And then they are automatically saved in JSON format.
That was the actual reason for this PR, coming from this setup.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then the credentials are automatically managed by the RDS itself in the Secrets Manager. And then they are automatically saved in JSON format

@manu-akw Thanks, I didn't know that 👍

@cyrilgdn cyrilgdn added the waiting-response Further information is requested label Aug 29, 2024
@cyrilgdn cyrilgdn removed the waiting-response Further information is requested label Sep 2, 2024
@cyrilgdn cyrilgdn merged commit b23202a into cyrilgdn:main Sep 2, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants