How to purge an unused old provider in a lock file

Hello, I am using Terraform For Github with terraform-github-provider and I saw the below message when I executed terraform init -upgrade.

Warning: Additional provider information from registry

The remote registry returned warnings for
Terraform Registry

  • For users on Terraform 0.13 or greater, this provider has moved to
    integrations/github. Please update your source in required_providers.

So I had replaced it in my required_providers clause and executed terraform init -upgrade.

 required_providers {
   github = {
-    source  = "terraform/github"
+    source  = "integrations/github"
     version = "~> 4.0"
   }
 }

But the .terraform.lock.hcl file seems still contains the information about both the old and new providers.

# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.

provider "registry.terraform.io/hashicorp/github" {
  version     = "4.5.2"
  constraints = "~> 4.0"
  hashes = [
    "h1:7H2CZZoOFRe7BEZukBPjasgNlb4TNWrneUrRVCDFjR4=",
    "zh:0bd14b4ab08970fd95a6e6f9de0ea128949e31d03dbf9b24b8a585d000f9d186",
    "zh:22970d45ff5abc671574133397cca711b18b2fecf71fdb72ac37f4e16cb1ef59",
    "zh:3f976037e257fe153b592bf0e95c182ad8bee859c5ad364c017855b67c977e83",
    "zh:8468ef880152de2d576a2a436842ab30fce5edd16b9eb11be9768ffd4e22c8ee",
    "zh:a752d1625449c2f769372e0f4291f9c81aa132880379186ed7ec18a851f46093",
    "zh:ac74cbc20bf1f80228b25c0a37e0729f8e7f0b79f6aa9ee98eda595724bfaa5d",
    "zh:b643023d50b2d261d11beb86e61d5bf7e579b517ec6b8a8abfe26e2a8a8481f4",
    "zh:c098ac282a8bff702456a080a26d088002e36726ff961cb3f3d87aa5db874098",
    "zh:c45027c4aa80f5ae14a6b81afbae0f10f161d9417eaa1da157caa7eb7db22d9f",
    "zh:d905cb43ea3f3eadff73a4ccaf88933fc32513813230bfed8d6f5b039d74a9fe",
    "zh:de4d157a176681fba735c5fb060278c9a986be5827908c5089c14cbd54e29b74",
  ]
}

provider "registry.terraform.io/integrations/github" {
  version     = "4.6.0"
  constraints = "~> 4.0"
  hashes = [
    "h1:2BbeMRVRLv086vsnxmjEBxhDut/1ozwh/BFatVxxrK0=",
    "zh:22b529f43425a56fa9cc57774f54411a85ed7669bd66616799e119a9e5ddb676",
    "zh:2f7e15f8b95ee61942043b57ab3af9e9f57cf9c65dbc5c6db72fac8eb06439f1",
    "zh:2feaabc6cd2616ebe2ac81ec38ebf09786b765eade5a3b3aa57e2efa57aec46d",
    "zh:5758627d28661cb594f2cf0c76f2ad8b60082732deedf182d300994e3b312cb5",
    "zh:665fb20fbac19920b0681cac6a6908e13fecf5c36e935d75450c1519653f6dd7",
    "zh:799cbcfdf5cac81fea36057fc7ecc247e01a54c08d367d17fb5a942c36b0802b",
    "zh:7aad0a98aa0354dfb67cfa8f003914f8ca223502c92fb534f523c2f57dc906ff",
    "zh:8a8a869af367322f392e51c3824a87d40d702c6f7b07e31217965a43f49d4617",
    "zh:94edb9987e0f86b7eb485c16f907b1f27fb071ad87a036a17f933c24aa49f447",
    "zh:b6fbdf5d198bd8bd5003f9d86730b206b7828b740c67ce44b643c254951f177a",
    "zh:f6b169d435cf0a2e9e48a16e74b0b4430b7b5f1cbb9bfe6fc86e3ca9e462471d",
  ]
}

How to purge old unused ‘terraform/github’ provider in a way other than a manual deleting these lines? I tried terraform init -reconfigure -upgrade but nothing happens.

Additional info:

$ terraform version
Terraform v0.14.8
+ provider registry.terraform.io/hashicorp/github v4.5.2
+ provider registry.terraform.io/integrations/github v4.6.0
$terraform providers

Providers required by configuration:
.
└── provider[registry.terraform.io/integrations/github] ~> 4.0

Providers required by state:

    provider[registry.terraform.io/integrations/github]

Best regards.

Hi @lens0021,

There isn’t an automatic way to purge it, because Terraform is trying to keep hold of these previously-learned hashes in case you removed the provider in error and want to add it back again.

However, if you know you will no longer be using the provider at its old address, it would be safe to edit the file and delete the corresponding block.

Terraform doesn’t make use of the information in the lock file unless the provider installation process determines that it needs to install a particular provider that’s already recorded in there, so that extra entry won’t affect Terraform’s behavior in any significant way unless you were to re-add the old address to your configuration later, although as you saw terraform version does happen to use it to produce its extra information about which specific providers are selected, which is a cosmetic thing only.

1 Like

I am happy for hearing that. Thanks!