Problem
When we do not intend to use a provider further and try to remove the provider from your terraform configuration, we can get below errors when executing a plan on terraform cloud workspace:
Error: Cannot obtain plugin client
│
│ with provider["registry.terraform.io/provider/provider"],
│ on <empty> line 0:
│ (source code not available)
│
│ HTTP response with status code 401 does not contain Content-Type:
│ application/json
│
│ No valid credentials found for PagerDuty provider.
│ Please see https://www.terraform.io/docs/providers/provider/index.html
│ for more information on providing credentials for this provider.
│
╵
╷
│ Error: Invalid provider configuration
│
│ Provider "registry.terraform.io/provider/provider" requires explicit
│ configuration. Add a provider block to the root module and configure the
│ provider's required arguments as described in the provider documentation.
When we try to remove the resources from the state, we can get below error:
Error saving the state: unsupported attribute "override_json"
The state was not saved. No items were removed from the persisted
state. No backup was created since no modification occurred. Please
resolve the issue above and try again.
Probable Cause
- Since the provider resources could not be successfully removed from state, terraform operations are looking to download the provider but as it is not present in the configuration, we get the
Error: Invalid provider configuration
- Also, while trying to remove the provider from state, the error unsupported attribute "override_json" appears because the provider resources were configured with old version of the provider and then the provider configuration got updated.
Solution
The solution in this case would be to download the state file and remove the resources related to the provider we no longer intend to use and then upload the updated state file to the terraform cloud workspace.
- Download the state file from the terraform cloud workspace.
- Create a new directory on the local machine and create an empty file
main.tf
- Run
terraform init
- Copy the downloaded state to this directory and rename it as
terraform.tfstate
- Get a list of resources in the state with the command
terraform state list
and then remove the resources related to the provider from the state using the commandterraform state rm <<resource name>>
- Verify that the state file does not have any provider related resource and copy the updated state file (without provider resources) to the existing directory of terraform configuration.
- Do a
terraform init
- Update the state file to the terraform cloud workspace with the command
terraform state push "terraform.tfstate"
and the state file should get updated on Terraform cloud workspace. - Run a terraform plan and it should get successful.
Sometimes the plan can result in an Error: Error asking for state migration action: input is disabled.
In this case, remove the terraform.tfstate file from local machine configuration and run the plan again.
Outcome
The workspace should get updated with a new state without the resources related to the provider and further terraform plans and applies should not fail because of provider references.
Note: If you continue to experience issues, please contact HashiCorp Support.