简体   繁体   中英

Terraform - output variables as quoted values

I'm using Terraform to build our AWS infrastructure projects. I need to be able to output multiple variables to a file and then to load that file back into another Terraform script.

Right now, I'm able to output the variables but they come out with the values not quoted:

variable = value

However, when loading a variable file into Terraform, it expects all values to be quoted, like this:

variable = "value"

So I can't understand why the hell Terraform doesn't just export the variables that way in the first place.

Is there any way to have it do this without requiring additional work on my part?

EDIT: I'm using Terraform v0.11.13 and cannot upgrade due to security restrictions

Output in JSON and use JQ to transform into what you like to have.

terraform output -json

main.tf

output "hogehoge" {
  value = "hogehoge"
}

Execution

$ terraform apply
Outputs:
hogehoge = hogehoge

$ terraform output -json
{
  "hogehoge": {
    "sensitive": false,
    "type": "string",
    "value": "hogehoge"
  }
}

However, as @ydaetskcoR commented, why not use data.terraform_remote_state ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM