-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
mock_provider does not work with providers that have required configuration blocks (e.g. azurerm) #34489
Comments
Hi @arylatt, thanks for filing this! This is a problem with the mocking framework so you've filed it in the right place - it shouldn't be validating the configuration against the providers schema. We also caught this internally yesterday, and it should have been fixed in #34481. That fix will be released in the next release candidate - hopefully next week, but maybe the one after. Thanks so much for trying out the new features, and please keep filing any other issues you find or any potential feature requests. |
@liamcervante awesome, yes building from the v1.7 branch and running my tests against that version of Terraform it works. Thanks! |
Hi @arnaudlh, what version of Terraform are you using for this? Or can you share your config? I'm unable to reproduce this as the following is working for me on Terraform v1.7.0. # main.tf
provider "azuread" {}
resource "azuread_group" "example" {
display_name = "what"
security_enabled = true
} # main.tftest.hcl
mock_provider "azuread" {}
run "test" {
assert {
condition = azuread_group.example.display_name == "what"
error_message = "wrong display name"
}
} ~/terraform/34489 > terraform test
main.tftest.hcl... in progress
run "test"... pass
main.tftest.hcl... tearing down
main.tftest.hcl... pass
Success! 1 passed, 0 failed.
~/terraform/34489 > terraform version
Terraform v1.7.0
on darwin_arm64
+ provider registry.terraform.io/hashicorp/azuread v2.47.0 |
A note on recreation, please use the This is still an issue on 1.7.1 |
Hi @stusklinar, are you able to provide some reproduction config for your error? I am able to get this working on Terraform v1.7.1 with both # main.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "main" {
name = "example"
location = "West Europe"
} # main.tftest.hcl
mock_provider "azurerm" {}
run "test" {
assert {
condition = azurerm_resource_group.main.name == "example"
error_message = "wrong name"
}
} ~/terraform/34489/component > terraform test
main.tftest.hcl... in progress
run "test"... pass
main.tftest.hcl... tearing down
main.tftest.hcl... pass
Success! 1 passed, 0 failed.
~/terraform/34489/component > terraform version
Terraform v1.7.1
on darwin_arm64
+ provider registry.terraform.io/hashicorp/azurerm v3.89.0
~/terraform/34489/component > Thanks! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Terraform Version
Terraform Configuration Files
main.tf
:main.tftest.hcl
:Debug Output
https://gist.github.com/arylatt/796ee2f5a8576cba2195985c4e7acd33.
Expected Behavior
Mock provider should initialize and tests should run.
Actual Behavior
Since the
azurerm
provider requires afeatures
block to be defined, the provider initialization fails. There is no way to provide configuration to the mock provider to avoid this error.Steps to Reproduce
terraform init
terraform test
Additional Context
https://github.com/hashicorp/terraform/blob/v1.7.0-rc1/internal/configs/mock_provider.go#L35-L36 suggests that there is an expectation that mock providers won't need config. Not sure if this assumption should be changed (since there are providers that require config) or if I should raise this against terraform-providers/terraform-provider-azurerm?
References
No response
The text was updated successfully, but these errors were encountered: