1

How to get aws configuration parameters stored in json format on S3 in terraform scripts. I want to use those parameters in another resources. I just want to externalise all the variable parameters in the script.

e.g: we have Data Source: aws_ssm_parameter to get AWS ssm parameters.

'''

data "aws_ssm_parameter" "foo" {
  name = "foo"
}

'''

Similarly how can we get aws app configurations in terraform scripts.

PrasadB
  • 91
  • 1
  • 7

1 Answers1

0

From my understanding you need to read S3 objects' value's and use it in terraform.

Used data because it's external resource that we're referencing. I would use like this:

data "aws_s3_object" "obj" {
  bucket = "foo"
  key    = "foo.json"
}

output "s3_json_value" {
    value = data.aws_s3_object.obj.body
}

To parse JSON you can use jsondecode

locals {
    a_variable = jsondecode(data.aws_s3_object.obj.body)
}

output "Username" {
    value = local.a_variable.name
}
Umut Gerçek
  • 630
  • 6
  • 9
  • using aws_s3_object directly defeats the purpose of using AWS APP Config. I can use aws_ssm_parameter instead to externalise the parameters that changes frequently, – PrasadB Jul 04 '22 at 13:10
  • Makes sense but you said `How to get aws configuration parameters stored in json format on S3 in terraform scripts.` For `I just want to externalise all the variable parameters in the script.` What do you want to use? `i just want to use AWS app config instead.` I can look at `AppConfig` – Umut Gerçek Jul 04 '22 at 13:24