Skip to content

cdktf: toBeValidTerraform() should pass -backend=false to terraform init #3909

@msztainbok

Description

@msztainbok

Expected Behavior

toBeValidTerraform() should work in all circumstances and not require access to the Terraform backend

Actual Behavior

toBeValidTerraform() calls terraform init with no parameters so the Terraform backend which is instantitated in the code is used which increases the time it takes to do the validation and also causes the test to fail if the backend is not accessible. The backend is not needed for validation as it just validates the syntax of the generated Terraform and the actual validation is done by the plan operation (as per the Terraform documentation)

Steps to Reproduce

  1. Create a stack using CDKTF
  2. Add an Azure backend which has an inaccessible storage account
  3. Run a test that uses toBeValidTerraform() to validate the generated Terraform code

Versions

lanugage: typescript
cdktf-cli: 0.21.0
node: v20.19.2
terraform: 1.12.2
arch: x64
os: win32 10.0.26100
providers
@cdktf/provider-azuread (PREBUILT)
terraform provider version: 3.4.0
prebuilt provider version: 14.0.0
cdktf version: ^0.21.0
@cdktf/provider-azurerm (PREBUILT)
terraform provider version: 4.34.0
prebuilt provider version: 14.3.0
cdktf version: ^0.21.0

Providers

┌───────────────┬──────────────────┬─────────┬────────────┬─────────────────────────┬─────────────────┐
│ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │
├───────────────┼──────────────────┼─────────┼────────────┼─────────────────────────┼─────────────────┤
│ azuread │ 3.4.0 │ ^0.21.0 │ │ @cdktf/provider-azuread │ 14.0.0 │
├───────────────┼──────────────────┼─────────┼────────────┼─────────────────────────┼─────────────────┤
│ azurerm │ 4.34.0 │ ^0.21.0 │ │ @cdktf/provider-azurerm │ 14.3.0 │
└───────────────┴──────────────────┴─────────┴────────────┴─────────────────────────┴─────────────────┘

Gist

No response

Possible Solutions

Alter the code for toBeValidTerraform to pass the -backend=false parameter to terraform init

Workarounds

None

Anything Else?

The Terraform documentation for terraform validate states that terraform init should be run with the -backend=false argument before doing the validate.

References

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnewUn-triaged issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions