Created
December 7, 2020 11:27
-
-
Save theuves/8b9585e54a1a09ed7e480cde39f66c80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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