I am using terratest successfully, but since switching to a remote backend, where the details are defined in a separate backend.hcl
file, I am running into trouble.
The situation: my main.tf
starts like this:
terraform {
required_version = "~> 0.14.0"
backend "remote" {}
}
And my backend.hcl
:
workspaces { name = "foobar" }
hostname = "app.terraform.io"
organization = "ACME"
Then when using terraform, I init like terraform init -backend-config=./backend.hcl
. So far, so good. When using terratest, it now complains among other errors about the organization
not beeing defined. This seems reasonable, as organization
is not in main.tf
.
One workaround would be to include the contents of backend.hcl
in main.tf
, but that would not fit with our architecture, it would require to edit main.tf
just for testing.
Is there a way to tell terratest to include the backend.hcl
when terraform initing?
EDIT 1: I see there is a way to add backend information to the terraformOptions
, however I was not able to correctly format these:
BackendConfig: map[string]interface{}{
"organization": "ACME",
"hostname": "app.terraform.io",
"workspaces": "{ name = "foobar" }",
},
If I could get this to work this would provide a workaround, as I could add some code to read the backend.hcl
and inject the information, however the workspaces formatting is not correct and I am a bit lost as to how that should look.
EDIT 2: Ok, now I found out that my workaround mentioned in EDIT 1 will not work because workspaces is a block value, which is currently not supported. The issue is open since 2019 ... https://github.com/hashicorp/terraform/issues/21830.
So it would be really helpfull if terratest would support the backend configuration in a file.