cloudposse / terraform-aws-vpc-peering-multi-account

Terraform module to provision a VPC peering across multiple VPCs in different accounts by using multiple providers
https://cloudposse.com/accelerate
Apache License 2.0
129 stars 92 forks source link

The given key does not identify an element in this collection value #47

Closed rust84 closed 2 years ago

rust84 commented 3 years ago

Describe the Bug

We are getting the following error when running apply. We are in the process of upgrading from Terraform 0.11 to Terraform 0.12. Previously this was successful on Terraform 0.11 using the 0.11 branch.

Error: Invalid index

  on .terraform/modules/staging_peering/accepter.tf line 88, in resource "aws_route" "accepter":
  88:   route_table_id            = local.accepter_aws_route_table_ids[ceil(count.index / local.requester_cidr_block_associations_count)]
    |----------------
    | count.index is 5
    | local.accepter_aws_route_table_ids is list of string with 3 elements
    | local.requester_cidr_block_associations_count is 2

The given key does not identify an element in this collection value.

Expected Behavior

Plan runs without error.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Configure the module as follows.
module "staging_peering" {
  source  = "cloudposse/vpc-peering-multi-account/aws"
  version = "0.11.3"

  namespace = "staging"
  stage     = "staging"
  name      = "staging-shared-services-peering"

  requester_aws_assume_role_arn             = "arn:aws:iam::xxxxxx:role/cross-account-vpc-peering"
  requester_region                          = "eu-west-1"
  requester_vpc_id                          = data.aws_vpc.peer_from_vpc.id
  requester_allow_remote_vpc_dns_resolution = false

  accepter_aws_assume_role_arn             = "arn:aws:iam::xxxxxx:role/pipeline"
  accepter_region                          = "us-east-2"
  accepter_vpc_id                          = data.aws_vpc.peer_to_staging_vpc.id
  accepter_allow_remote_vpc_dns_resolution = false
}
  1. Run 'terraform plan.'
  2. See error

Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:

rust84 commented 3 years ago

Removed from the state and tried recreating but still the same issue.

nitrocode commented 3 years ago

Do you get the same error if you use the latest version of this module ?

rust84 commented 3 years ago

If I try 0.15.0 then I get the following error

Error: Custom variable validation is experimental

  on .terraform/modules/hxm-qa_peering/context.tf line 182, in variable "label_key_case":
 182:   validation {

This feature is currently an opt-in experiment, subject to change in future
releases based on feedback.

Activate the feature for this module by adding variable_validation to the list
of active experiments.

I've tried forking the module and enabling the experiment but wherever I put it I still get the error.

terraform {
  experiments = [variable_validation]
}

We are using terraform 0.12.30.

runtman commented 3 years ago

I work with @rust84 it seems upgrading to terraform 0.13.7 has resolved this issue.

nitrocode commented 2 years ago

It looks like upgrading terraform resolves the issue. Thanks for closing the loop @runtman .