Terraform: init command should support workspaces block in backend config file

Created on 11 Aug 2020  ยท  9Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.13.0

Terraform Configuration Files

Backend config like official doc
https://www.terraform.io/docs/backends/types/remote.html#using-cli-input

workspaces { name = "workspace" }
hostname     = "app.terraform.io"
organization = "company"

Debug Output


N/A

Crash Output


N/A

Expected Behavior


init backend without error

Actual Behavior

Initializing the backend...

Error: Invalid backend configuration file

The backend configuration file "backend.hcl" given on the command
line must contain key-value pairs only, and not configuration blocks.

Steps to Reproduce

terraform init -backend-config=backend.hcl

Additional Context


N/A

References

  • #25411
bug explained

Most helpful comment

second. not sure if I am missing updated docs ref, but I started hitting this today as well.

All 9 comments

second. not sure if I am missing updated docs ref, but I started hitting this today as well.

Same, works fine in 0.12.28 as documented but not in 0.13.0

I'm able to reproduce this and I think it is indeed a bug. It looks like in #25411 we were overzealous in validating the backend configuration file as purely attributes, when it actually should contain the configuration body for the specified backend. As in the remote backend example, this configuration may include blocks.

We need to remove the attributes-only constraint, but I'm not sure what we can replace it with to help out with the original issue (#24845). Maybe a check that there is no terraform block at the top level?

@alisdair Thanks. At lease me, I don't put terraform block at the top level in config file. If it would be difficult to check it at runtime, I think refining docs & outputs are enough.

Is there a workaround that still lets you use a backend.hcl file, but in a different format?

Is there a workaround that still lets you use a backend.hcl file, but in a different format?

Yes. You can combine the attributes as blocks alternate syntax with HCL as JSON. Instead of this HCL:

workspaces { name = "workspace" }
hostname     = "app.terraform.io"
organization = "company"

Write this JSON as backend.hcl.json:

{
  "workspaces": [
    {
      "name": "workspace"
    }
  ],
  "hostname": "app.terraform.io",
  "organization": "company"
}

And run terraform init -backend-config=backend.hcl.json.

I can config that JSON syntax is working as fine with terraform 0.13. Is there a plan to add support for previous HCL syntax or is this the final solution going forward?

I consider it to be a bug and think it should be fixed. I only suggest the JSON workaround as a temporary way to unblock use of 0.13.0.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings