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

Support for mocking providers in opentofu test #1155

Open
tv-sister opened this issue Jan 19, 2024 · 3 comments
Open

Support for mocking providers in opentofu test #1155

tv-sister opened this issue Jan 19, 2024 · 3 comments
Assignees
Labels
accepted This issue has been accepted for implementation. enhancement New feature or request
Milestone

Comments

@tv-sister
Copy link

OpenTofu Version

OpenTofu v1.6.0

Use Cases

Test OpenTofu code offline.

Attempted Solutions

Using fake credentials in your provider in the testfile does not always work, the newly implemented mock provider by Terraform has a broader usecase, as it allows faking data sources etc.

https://developer.hashicorp.com/terraform/language/tests/mocking

For example, using fake credentials and trying to retrieve an AMI with

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}

Returns the following error

reading EC2 AMIs: AuthFailure: AWS was not able to validate the provided access credentials

Proposal

Add support for mocking providers, resources, and data sources.

References

No response

@tv-sister tv-sister added enhancement New feature or request pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion. labels Jan 19, 2024
@cube2222 cube2222 added accepted This issue has been accepted for implementation. and removed pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion. labels Jan 22, 2024
@cube2222 cube2222 added this to the 1.7.0 milestone Jan 22, 2024
@cube2222
Copy link
Collaborator

Thanks for submitting the issue @tv-sister!

We've agreed that this makes sense for compatibility purposes, and the core team will pick it up with the goal being a release of this alongside 1.7.0.

@RLRabinowitz
Copy link
Collaborator

When taking this task, and if deciding to use the same syntax as Terraform does (.tfmock.hcl files), make sure these files would be included in the tofu fmt command run - hashicorp/terraform#34577

@RLRabinowitz
Copy link
Collaborator

Also - keep this possible crash in mind - hashicorp/terraform#34601

@cam72cam cam72cam assigned cam72cam and unassigned cam72cam Mar 21, 2024
@Yantrio Yantrio modified the milestones: 1.7.0, 1.7.1 Apr 11, 2024
@ollevche ollevche self-assigned this May 21, 2024
@ollevche ollevche modified the milestones: 1.7.3, 1.8.0 Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This issue has been accepted for implementation. enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants