Acctest: Add back the missing provider config #28052
Merged
+713
−174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Community Note
Description
This PR is to add back the missing provider config for the acctests, which is now required as a result of the PR: #27936.
This PR is constructed via the following procedures:
Note that the following test case and steps are not exported:
(The branch is at: https://github.com/magodo/terraform-plugin-testing/tree/config_print)
I then replace the module with my fork above,
go mod tidy && go mod vendor
, then run the command below:This exports the test cases/steps into /tmp/test with above folder structure, where each file represents the effective config for each test step.
Next thing is to run
grep
(too lazy to write a HCL parsing tool for this case) in the /tmp/test folder:grep -rL "provider .*azurerm.* {" .
: This returns the ones that has no provider config defined at all.grep -r "provider .*azurerm.* {" . | awk -F: '{count[$1]++} END {for (file in count) print file, count[file]}' | awk '$2 != 1'
: This returns the ones have provider config defined multiple timesWith the change of this PR, there is no entry for the 1st case. For the 2nd case, I get the followings:
The
TestAccDataSourceNetAppVolume
andTestAccStorageAccountCustomerManagedKey
ones are due to there is theazurerm-alt
provider defined. While theTestAccNetAppVolume
ones are existing errors, introduced in #27188 (TC: https://hashicorp.teamcity.com/buildConfiguration/TF_AzureRM_AZURERM_SERVICE_PUBLIC_NETAPP/266596?buildTab=tests&status=failed), and I'd rather leave them untouched.Finally, I created a root main.tf, and reference all the folders as submodules. With some reasonable modifications, the
terraform init
succeeded, which at least proves there is no duplicate provider configurations. To ensure each one has the valid provider configuration, things become challenging, as some of the existing configurations themselves are problematic. I don't know the exact number of them (there are >10000 modules). Up to this point, it should be good to go/test for a couple of big RPs.Regarding the fixes, I'd like to mention the principle I've been following:
WithOutProvider
, and remove the provider config inside the original base/template. Then use this new variation function insteadPR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_resource
- support for thething1
property [GH-00000]This is a (please select all that apply):
Related Issue(s)
Fixes #0000
Note
If this PR changes meaningfully during the course of review please update the title and description as required.