Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use with existing VPC #147

Open
shadycuz opened this issue Apr 5, 2024 · 0 comments
Open

Unable to use with existing VPC #147

shadycuz opened this issue Apr 5, 2024 · 0 comments

Comments

@shadycuz
Copy link

shadycuz commented Apr 5, 2024

I'm trying to use this module to add transit subnets and attachment to my existing VPC.

module "vpc" {
  source   = "aws-ia/vpc/aws"
  version = ">= 4.4.2"

  name                                 = "sandbox"
  # cidr_block                           = "10.80.0.0/16"

  vpc_id = "vpc-xxxxxxxx"
  vpc_assign_generated_ipv6_cidr_block = false
  vpc_egress_only_internet_gateway     = false
  az_count                             = 3

  transit_gateway_id = "tgw-xxxxxx"

  subnets = {
    public = {
      name_prefix               = "sandbox-public" # omit to prefix with "public"
      nat_gateway_configuration = "none" # options: "single_az", "none"
      assign_ipv6_cidr         = false
      cidrs      = ["10.80.144.0/23", "10.80.176.0/23", "10.80.208.0/23"]
    }
    # IPv4 only subnet
    private = {
      name_prefix  = "sandbox-private"
      connect_to_public_natgw = false
      assign_ipv6_cidr         = false
      cidrs = ["10.80.128.0/23","10.80.160.0/20","10.80.192.0/20"]
    }

    transit_gateway = {
        name_prefix = "sandbox-transit-gateway"
        assign_ipv6_cidr                                = false
        transit_gateway_default_route_table_association = false
        transit_gateway_default_route_table_propagation = false
        transit_gateway_appliance_mode_support          = "enable"
        transit_gateway_dns_support                     = "disable"
        cidrs = ["10.80.146.0/28", "10.80.178.0/28", "10.80.210.0/28"]
    }
  }
}

If I supply the VPC ID as vpc_id and run plan I get the following:

Plan: 16 to add, 0 to change, 0 to destroy.
╷
│ Error: Invalid index
│ 
│   on .terraform/modules/sandbox_us_east.vpc.calculate_subnets_ipv6.subnet_calculator/main.tf line 2, in locals:
│    2:   cidr_netmask = tonumber(split("/", var.base_cidr_block)[1])
│     ├────────────────
│     │ var.base_cidr_block is ""
│ 
│ The given key does not identify an element in this collection value: the given index is greater than or equal to the length of the collection.

If I remove vpc_id and use cidr_block, I get the same error when trying to import the existing VPC.

tofu import module.sandbox_us_east.module.vpc.aws_vpc.main[0] vpc-xxxxxx
...
module.sandbox_us_east.module.vpc.aws_vpc.main[0]: Import prepared!
  Prepared aws_vpc for import
module.sandbox_us_east.module.vpc.aws_vpc.main[0]: Refreshing state... [id=vpc-xxxxxxx]
...

│ Error: Invalid index
│ 
│   on .terraform/modules/sandbox_us_east.vpc.calculate_subnets_ipv6.subnet_calculator/main.tf line 2, in locals:
│    2:   cidr_netmask = tonumber(split("/", var.base_cidr_block)[1])
│     ├────────────────
│     │ var.base_cidr_block is ""
│ 
│ The given key does not identify an element in this collection value: the given index is greater than or equal to the length of the collection.

I am using tofu instead of terraform, but I didn't think that was the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant