Member-only story
Generating Dynamic JSON in Terraform
8 min readMar 18, 2023
Available for free in English & Portuguese at my personal website.
In this article I’ll use Step Functions as a case study, but you can do it with whatever resources you want.
What we’re going to do
The following JSON will become dynamic. We’ll replace static values with:
- A variable
- A dynamic list
- One or more dynamic objects
(I’ve added non idiomatic comments inside the code blocks, but it’s just to show what exactly we’re doing.)
# Reference JSON
{
"Comment": "My state machine",
"StartAt": "Choice",
"States": {
"Handle Notification": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"Payload.$": "$",
"FunctionName": "my_function_name" <-- Case 1: Replace with dynamic string
},
"End": true
},
"Choice": {
"Type": "Choice",
"Choices": [ -------
{ |
"IsPresent": true, |
"Next": "SSM Execution-InstanceId", |
"Variable"…