-
Notifications
You must be signed in to change notification settings - Fork 232
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
Allow multiple versions of provider in acceptance tests #628
Comments
Reference: #253 Reference: #628 Reference: #779 Provider developers can now select whether to configure providers for acceptance testing at the `TestCase` or `TestStep` level. Only one level may be used in this current implementation, however it may be possible to allow merged `TestCase` and `TestStep` configuration with additional validation logic to ensure a single provider is not specified multiple times across the merge result of all fields. This change also introduces some upfront `TestCase` and `TestStep` configuration validation when calling any of the `Test` functions, failing the test early if a problem is detected. There are other validations that are possible, however these are considered out of scope.
Reference: #253 Reference: #628 Reference: #779 Provider developers can now select whether to configure providers for acceptance testing at the `TestCase` or `TestStep` level. Only one level may be used in this current implementation, however it may be possible to allow merged `TestCase` and `TestStep` configuration with additional validation logic to ensure a single provider is not specified multiple times across the merge result of all fields. This change also introduces some upfront `TestCase` and `TestStep` configuration validation when calling any of the `Test` functions, failing the test early if a problem is detected. There are other validations that are possible, however these are considered out of scope.
The acceptance testing framework (helper/resource) in v2.17.0 now allows provider developers to specify providers at the resource.Test(t, resource.TestCase{
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"random": {
VersionConstraint: "...", // last version of old schema version
Source: "example-namespace/example",
},
},
Config: "...",
Check: /* ... */,
},
{
ProviderFactories: testAccProviders,
Config: "...",
Check: /* ... */,
},
},
}) |
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. |
SDK version
Use-cases
Simulate provider upgrade on existing infrastructure. Specifically, I would like the acceptance tests to tell me when one of my local changes might accidentally delete a user's existing infrastructure. (This can happen when
ForceNew
andDefault
are both used in the same schema attribute).Here is a specific example:
A user has a storage volume created through Terraform. This is the existing infrastructure. They go to upgrade to the latest version of a Terraform Provider which manages this volume. One of the changes pulled in through that upgrade is a new attribute of that volume resource, and someone has accidentally added a
ForceNew
andDefault
option to that attribute.When the user goes to
terraform apply
, Terraform adds the new attribute to the volume, but in doing so, it has deleted the user's volume and created a new one. This bug should be caught in acceptance tests.Attempted Solutions
Working solution
I have this work-around that's working for the Kubernetes provider, but it would be a lot neater if the SDK had a built-in way to do this instead. Basically, what I've done is compiled the provider from the local branch and named it "kubernetes-local". And I've grabbed the latest released version and named it "kubernetes-released". Then I load both of these into the acceptance test as ExternalProviders.
In the acceptance test, I first create a resource using the released version, and then try a second apply using the pre-released version. Then, I compare the UUID of the resource to make sure it hasn't been deleted and recreated. Here is the code. It's spread across a few files:
https://github.com/hashicorp/terraform-provider-kubernetes/blob/0045c05d3cc24ed13e64f2974d63e6989ed0aa52/.terraformrc
https://github.com/hashicorp/terraform-provider-kubernetes/blob/0045c05d3cc24ed13e64f2974d63e6989ed0aa52/GNUmakefile#L46-L52
https://github.com/hashicorp/terraform-provider-kubernetes/blob/0045c05d3cc24ed13e64f2974d63e6989ed0aa52/kubernetes/provider_test.go#L38-L57
https://github.com/hashicorp/terraform-provider-kubernetes/blob/0045c05d3cc24ed13e64f2974d63e6989ed0aa52/kubernetes/provider_test.go#L453-L467
https://github.com/hashicorp/terraform-provider-kubernetes/blob/0045c05d3cc24ed13e64f2974d63e6989ed0aa52/kubernetes/resource_kubernetes_pod_test.go#L970
https://github.com/hashicorp/terraform-provider-kubernetes/blob/0045c05d3cc24ed13e64f2974d63e6989ed0aa52/kubernetes/resource_kubernetes_pod_test.go#L974
https://github.com/hashicorp/terraform-provider-kubernetes/blob/0045c05d3cc24ed13e64f2974d63e6989ed0aa52/kubernetes/resource_kubernetes_pod_test.go#L1012
https://github.com/hashicorp/terraform-provider-kubernetes/blob/0045c05d3cc24ed13e64f2974d63e6989ed0aa52/kubernetes/resource_kubernetes_pod_test.go#L1047
What didn't work
I tried getting the same behavior as above, without pre-compiling the provider, but it was unable to effectively test the two versions. Here's what I tried:
First, using the code from the links above, I confirmed that my work-around does indeed catch a
ForceNew
. I did this by adding aDefault
value to a schema attribute, along with aForceNew
. This simulates the bug that would have destroyed a user's infrastructure.The result confirms that the work-around is able to catch the ForceNew. It errors as expected when the resource is re-created:
For the second test, I removed the "kubernetes-local" provider and attempted to use the regular
ProviderFactories
instead.However, the results were not as expected. The test did not catch the ForceNew. I'm not sure why. The full diff is here which shows all the code that was modified during this test.
So this is why I think the SDK does not yet support my use case.
Proposal
If we could use
ProviderFactories
together withExternalProviders
, we could test multiple versions of the provider. It might just need to runterraform init
in between TestSteps. Alternatively, any solution which allows me to simulate a provider upgrade would be really appreciated!References
The text was updated successfully, but these errors were encountered: