skip to Main Content

Using Terraform v1.2.5 I am attempting to deploy an AWS VPC Peer. However, the following code fails validation:

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

provider "aws" {
  region = "us-east-1"
}

data "aws_vpc" "accepter" {
    provider = aws.accepter
    id = "${var.accepter_vpc_id}"
}

locals {
    accepter_account_id = "${element(split(":", data.aws_vpc.accepter.arn), 4)}"
}

resource "aws_vpc_peering_connection" "requester" {
  description   = "peer_to_${var.accepter_profile}"
  vpc_id        = "{$var.requester_vpc_id}"
  peer_vpc_id   = "${data.aws_vpc.accepter.id}"
  peer_owner_id = "${local.accepter_account_id}"
}

When validating this terraform code I am receiving the following error :

$ terraform validate
╷
│ Error: Provider configuration not present
│
│ To work with data.aws_vpc.accepter its original provider configuration at provider["registry.terraform.io/hashicorp/aws"].accepter is
│ required, but it has been removed. This occurs when a provider configuration is removed while objects created by that provider still exist
│ in the state. Re-add the provider configuration to destroy data.aws_vpc.accepter, after which you can remove the provider configuration
│ again.

What am I missing or misconfigured that is causing this error?

3

Answers


  1. You need to provide the aliased provider version you are referencing here:

    data "aws_vpc" "accepter" {
        provider = aws.accepter # <--- missing aliased provider
        id = var.accepter_vpc_id
    }
    

    To fix this, you just need to add the corresponding aliased provider block [1]:

    provider "aws" {
      alias  = "accepter"
      region = "us-east-1" # make sure the region is right
    }
    

    [1] https://developer.hashicorp.com/terraform/language/providers/configuration#alias-multiple-provider-configurations

    Login or Signup to reply.
  2. Since VPC Peering is an "inter-region" Peering we need 2 AWS regions. Hence the way to achhieve this is creating AWS provider and AWS alias provider blocks.

    See an example:

    provider "aws" {
      region = "us-east-1"
    
      # Requester's credentials.
    }
    
    provider "aws" {
      alias  = "peer"
      region = "us-west-2"
    
      # Accepter's credentials.
    }
    Login or Signup to reply.
  3. Your resource doesn’t know what provider to use, the one you provided does not exist.

    You have two options:

    1. Add alias to provider:
    provider "aws" {
      region = "us-east-1"
      alias = "accepter"
    }
    
    1. remove line provider = aws.accepter from data "aws_vpc" "accepter"

    Somehow, the first will be more valid for you, I suppose.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search