Don't Add aws_ssm_parameter's value to ignore_changes
Overview
Up until now, secret information was often handled in ways like the following.
1 | resource "aws_ssm_parameter" "master_password" { |
1 | data "aws_ssm_parameter" "master_password" { |
In either of the above cases, registering the value in Parameter Store beforehand is required.
In other words, this introduces work that is not managed by Terraform.
Steps to Address This
The way to keep everything within Terraform is to encrypt the value before registering it in Parameter Store.
1 | resource "aws_kms_key" "a" { |
- Encrypt the value with aws kms encrypt
1 | aws kms encrypt --key-id <key-id> --plaintext <value> |
- Register the value obtained via data.aws_kms_secrets in Parameter Store
1 | data "aws_kms_secrets" "parameters" { |
Under the premise of registering it in Parameter Store, the resource "aws_ssm_parameter" processing was necessary, but you can also specify it directly on a resource as shown below.
1 | resource "aws_rds_cluster" "example" { |
Summary
It’s truly common that, when you’re stuck, checking the official documentation resolves the issue.
By the way,
when you think about who is the one encrypting with the KMS key, it’s probably the person writing the Terraform code, and that operator needs permission to encrypt with the KMS key.
- kms:Encrypt
That’s all.
I hope this helps.
