Problem
After updating the credentials for a VCS provider connection in Terraform Enterprise or HCP Terraform, private registry modules that use the connection are not automatically updated. The modules continue to use the old, cached credentials, which can cause registry-related operations to fail.
Cause
Private registry modules in Terraform Enterprise and HCP Terraform do not automatically sync with changes made to their underlying VCS provider connection after the module has been created. The connection information is cached at the time of the module's creation. To associate the modules with the updated VCS connection, you must delete and recreate them.
Solutions
There are three methods to refresh the modules against the new VCS connection. You must delete all affected modules and then re-add them using the updated VCS provider.
Solution 1: Use the API
This method is recommended if you need to refresh a large number of modules.
- Use the API to list all registry modules. Identify which modules originated from the old VCS connection by checking their
sourceproperty. - For each affected module, use the API to delete the module.
- Finally, create a new module for each repository, which will use the new VCS connection.
Solution 2: Use the UI
You can perform this process manually through the Terraform Enterprise or HCP Terraform UI.
- Navigate to your organization's private module registry and select the module you want to update.
- Click Manage Module for Organization.
- Click Delete Module.
- In the confirmation dialog, select Delete all versions for this provider for this module from the dropdown menu and follow the remaining instructions.
- After deleting the module, add it again to the registry. It will now use the updated VCS connection.
Solution 3: Use the Terraform Provider
You can manage your registry modules programmatically using the tfe_registry_module resource from the official HashiCorp TFE provider. To refresh a module, you can use terraform destroy to remove the resource and terraform apply to recreate it with the updated VCS connection.