Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add data to a json file in terraform

Tags:

json

terraform

I am not a software guy, but I am preparing a small script for delarative onboarding work using terraform. The declaration is in a json file and it is send to the device through terraform. But I do not want to keep the sensitive data like passwords and secret keys in the json file. I want to inject them from a seperate file in a vault to the json file when I am executing it in terraform. I can use terraform to read the data from a vault or a s3 bucket, but I am not sure how to add it to the json declaration. I saw in terraform there is a functions like jsondecode and jsonencode. But I am not sure whether they will be any use to my requirement. Could someone help me on this please ?

Thansk.

like image 396
RukshanK Avatar asked Dec 20 '25 11:12

RukshanK


1 Answers

Maybe this is something which could help you? Create a data source which loads your template file, here you can pass in some vars.

some examples for variales:

data "template_file" "my_template" {
  template = templatefile("template.json", {
    foo         = "bar"
    another_foo = aws_s3_bucket.my_bucket.id
    more_foo    = var.my_variable
  })
}

The template file could look like this:

{
  "Value":   "123",
  "value_2": "${foo}",
  "value_3": "${another_foo}",
  "value_4": ${more_foo},
}
like image 69
pfandie Avatar answered Dec 22 '25 23:12

pfandie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!