AWS SSM Parameter Setting Strategy in Terraform
We use AWS SSM parameters to store specifics of our deployed infrastructure, and to share those specifics between terraform projects deployed in an environment.
We use AWS SSM parameters to store specifics of our deployed infrastructure, and to share those specifics between terraform projects deployed in an environment.
Setting SSM parameters can happen in one of two ways:
- Set by Terraform, after the deployment of infrastructure (an output, used by other things)
- Set by a human (an input, used to define something that differs in each environment (say, a VPC CIDR)
Setting the parameter in code is relatively easy, we use a resource
block and make sure to overwrite the value on each apply (so that we know its up to date)
But humans are not to great at setting a parameters, especially not in a specific path, with a specific format.
Helping the Humans
To aid the humans here, we do two things.
Shell example
First, we provide a text file in the project repository with an AWS ssm
command with details of how we expect the parameter to be created:
This way, we have an example (we don't commit the other environments VALUE, but can use the command in AWS CloudShell to set in the environment.
TF HCL conditions and outputs
Next, we do some checking in the Terraform HCL for human-set values to resolve common mistakes when setting the values, and make it easier to catch them if they do happen.
First, spaces in the SSM Parameter is a common mistaken, particularly when copy/pasting values into the console.
Second, we can use an output so that we see the value in our terraform plan/applies to catch other mistakes.