Skip to content

Instantly share code, notes, and snippets.

@theuves
Created December 7, 2020 11:27
Show Gist options
  • Save theuves/8b9585e54a1a09ed7e480cde39f66c80 to your computer and use it in GitHub Desktop.
Save theuves/8b9585e54a1a09ed7e480cde39f66c80 to your computer and use it in GitHub Desktop.
variable "ssm_path" {}
data "external" "ssm_parameters" {
program = ["sh", "-c", <<EOT
raw_json=$(aws ssm get-parameters-by-path --no-with-decryption --path ${var.ssm_path})
encoded_json=$(echo $raw_json | sed 's/"/\\"/g')
echo "{\"json\": \"$encoded_json\"}"
EOT
]
}
locals {
parameters = jsondecode(data.external.ssm_parameters.result.json).Parameters
environment_variables = jsonencode([
for parameter in local.parameters : {
name = reverse(split("/", parameter.Name))[0]
valueFrom = parameter.ARN
}
])
}
output "environment_variables" {
value = local.environment_variables
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment