Search code examples
terraform

Terraform unknown provider packages


I am attempting to run the below Terraform code and finding a strange reference to a provider hashicorp/server that I did not expect. Running:

terraform init

results in:

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 4.16"...
- Finding latest version of hashicorp/server...
- Installing hashicorp/aws v4.67.0...
- Installed hashicorp/aws v4.67.0 (signed by HashiCorp)
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider hashicorp/server: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/server
│ 
│ All modules should specify their required_providers so that external consumers will get the correct providers when using a module. To see which modules are currently depending on hashicorp/server,
│ run the following command:
│     terraform providers

When I run terraform providers I get:

Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/aws] ~> 4.16
└── provider[registry.terraform.io/hashicorp/server]

Providers required by state:

    provider[registry.terraform.io/hashicorp/aws]

I'm unable to find any reference to a provider server, so not sure how I can resolve this.

This is how I'm currently setting my provider:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.16"
    }
  }

  required_version = ">= 1.2.0"
}

After process of elimination I have discovered the issue is with this file which is creating an s3 bucket. Not to sure which bit is incorrect.

resource "aws_s3_bucket" "terraform-state" {
  bucket = "terrafrom-state-992292"
  acl    = "private"
}

resource "aws_s3_bucket_versioning" "versioning-terrafrom-state" {
  bucket = aws_s3_bucket.terrafrom-state-992292.id
  versioning_configuration {
    status = "Enabled"
  }
}

resource "server_side_encryption_configuration" "ssec_terrafrom-state-992292" {
  rule {
    apply_server_side_encryption_by_default {
      kms_master_key_id = aws_kms_key.terrafrom-state-992292-bucket-key.arn
      sse_algorithm     = "aws:kms"
    }
  }
}

resource "aws_s3_bucket_public_access_block" "block" {
  bucket = aws_s3_bucket.terrafrom-state-992292.id

  block_public_acls       = true
  block_public_policy     = true
  ignore_public_acls      = true
  restrict_public_buckets = true
}

Solution

  • Your issue is with this resource:

    resource "server_side_encryption_configuration" "ssec_terrafrom-state-992292" {
      rule {
        apply_server_side_encryption_by_default {
          kms_master_key_id = aws_kms_key.terrafrom-state-992292-bucket-key.arn
          sse_algorithm     = "aws:kms"
        }
      }
    }
    

    It is looking for a resource named server because that is the first part of the name for that resource. The name should be aws_s3_bucket_server_side_encryption_configuration as documented here, not server_side_encryption_configuration. You can't modify or shorten the resource names in Terraform, you must use the full name of a resource, exactly as shown in the documentation.