Terraform 0.13.5 installing unreferenced plugins/providers

I am trying to understand why during terraform init Terraform v0.13.5 is installing additional plugins, that are not referenced in my code.

I have the following providers configured

terraform {
  required_version = ">= 0.13"
  required_providers {
    aws = {
      source = "hashicorp/aws"
      region = "us-west-2"
      version = "~> 2.0"
      assume_role = {
        role_arn = "arn:aws:iam::xxxxxxxx:role/Terraform"
        session_name = "automation"
      }
    }
    random = {
      source = "hashicorp/random"
      version = "~> 2.0"
    }
  }
}

During initialization I can see that both aws and random providers are downloaded and installed twice. I cant seem to find any information regarding this behaviour, so is this intentional ? or am I missing something?

Initializing modules...

Initializing the backend...

Initializing provider plugins...
 Finding latest version of -/random...
 Finding hashicorp/random versions matching "~> 2.0"...
 Finding hashicorp/aws versions matching "~> 2.0"...
 Finding latest version of -/aws...
 Installing -/random v3.0.0...
 Installed -/random v3.0.0 (signed by HashiCorp)
 Installing hashicorp/random v2.3.1...
 Installed hashicorp/random v2.3.1 (signed by HashiCorp)
 Installing hashicorp/aws v2.70.0...
 Installed hashicorp/aws v2.70.0 (signed by HashiCorp)
 Installing -/aws v3.13.0...
 Installed -/aws v3.13.0 (signed by HashiCorp)
terraform version
Terraform v0.13.5
 provider registry.terraform.io/-/aws v3.13.0
 provider registry.terraform.io/-/random v3.0.0
 provider registry.terraform.io/hashicorp/aws v2.70.0
 provider registry.terraform.io/hashicorp/random v2.3.1

I also get the following warning during initialization. This concerns me, because, it makes me believe that the wrong provider will be used at run time.

To prevent automatic upgrades to new major versions that may contain breaking
changes, we recommend adding version constraints in a required_providers block
in your configuration, with the constraint strings suggested below.

* -/aws: version = "~> 3.13.0"
* -/random: version = "~> 3.0.0"

Any help will be greatly appreciated.
Thanks!!

We normally see this problem when there are resources in state which are using the old provider. A no-change terraform apply normally fixes this, but in some cases you may need to run terraform state replace-provider.

Try running terraform providers to check if you have any resources using -/aws and -/random. If so, you can fix this with:

terraform state replace-provider -- -/aws hashicorp/aws
terraform state replace-provider -- -/random hashicorp/random

An aside:

This looks like you are attempting to configure the AWS provider inside the required_providers block—this won’t work. Your provider configuration must be inside a top-level provider "aws" { } block instead. required_providers should only contain source and version

@alisdair Thank you for your reply. I am going to try and make the suggested changes and see if this fixes the issue that I am seen. I will let you know how that goes.

With regards to the provider configuration. That was me playing with the configuration, in the hopes to fix the error that I was seen with the installation of the additional provider. That said, the provider configuration as shown above, does seem to work. Terraform is assuming the correct role and at the moment terraform plan seems to be returning correctly. I haven’t tried a terraform apply but either way, I will fix the configuration to how it was before. Thanks for the heads up!!

@alisdair just as an FYI. terraform apply solved the issue. That said the provider as showed above worked fine. However, I reverted the changes and configured it before.
Thanks again !

1 Like