Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform Test Mocks: Add ability to omit targeted resources from mocking #36189

Open
Jpk518 opened this issue Dec 10, 2024 · 1 comment
Open
Labels
enhancement new new issue not yet triaged terraform test

Comments

@Jpk518
Copy link

Jpk518 commented Dec 10, 2024

Terraform Version

1.10.1

Use Cases

Currently, when using a mock provider in Terraform tests (e.g., mock_provider "aws" {}), the entire provider is mocked. This approach is limiting in certain situations where logic is being computed directly in a data block. It would be great to add functionality to selectively exclude specific resources or data sources from being mocked within a mock provider.

  1. Testing Custom Logic in Data Sources: Some data sources contain custom logic that a user may want to test directly. For example:
data "aws_ami" "example" {
 count = length(var.ami_names)
  most_recent = true

  owners = ["self"]
  tags = {
    Name   = var.ami_names[count.index]
  }
}
  1. Inline Logic Data Sources: Certain data sources, like the aws provider iam_policy_document do not perform external lookups but instead use the data block construct to define inline logic. It would be very useful often want to test and validate this logic directly in Terraform tests.

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document

Attempted Solutions

N/A.

Proposal

Add a new configuration option within the mock_provider block to specify resources or data sources that should be excluded from mocking. This could be implemented in multiple ways:

Option 1

mock_provider "aws" {
  exclude_resources = ["aws_ami", "aws_iam_policy_document"]
}

Option 2

mock_provider "aws" {
  excluded_data "aws_iam_policy_block" {}
}

References

No response

@Jpk518 Jpk518 added enhancement new new issue not yet triaged labels Dec 10, 2024
@crw
Copy link
Contributor

crw commented Dec 10, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new new issue not yet triaged terraform test
Projects
None yet
Development

No branches or pull requests

3 participants