hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.74k stars 9.56k forks source link

Support requiring providers within tests #35753

Open wyardley opened 1 month ago

wyardley commented 1 month ago

Terraform Version

Terraform v1.9.5
on darwin_arm64

Use Cases

Similar to https://github.com/hashicorp/terraform-provider-assert/issues/48 I'd like to use a module specific to tests (that one), but not have it as a dependency of the module I'm testing.

As of now, this requires some pretty ugly hacks like mocking and initializing an extra "module", since terraform { required_providers }} can't be set in the test configs.

Attempted Solutions

in tests/main.tftest.hcl:

provider "google" {
  project = "foo-testproject"
}
variables {
  foo = "bar"
}
terraform {
  required_providers {
    assert = {
      source = "hashicorp/assert"
    }
  }
}
run "basic" {
  command = plan
  plan_options {
    refresh = false
  }
  assert {
    condition = ....
  }
}

Proposal

No response

References

crw commented 1 month ago

Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!