Skip to content

Unable to create extra IPv6 subnets - CIDR clash #220

@cc-stjm

Description

@cc-stjm

Describe the Feature

If you want to create extra subnets using just IPv4, you can do this with multiple calls to the module, as described in #165 (comment)

However, you can't do the same for IPv6 at the moment - as the module assumes that the CIDR blocks being passed are /56 so it can convert them to /64. So if you allow the module to calculate the blocks then it selects the same IPv6 range.

Calculating & providing the CIDR blocks directly, using e.g.

  ipv6_cidrs = [
    {
      private=[
        cidrsubnet(module.vpc.vpc_ipv6_cidr_block, 8, 8),
        cidrsubnet(module.vpc.vpc_ipv6_cidr_block, 8, 9),
        cidrsubnet(module.vpc.vpc_ipv6_cidr_block, 8, 10)
      ]
    }
  ]

Doesn't work when you're also defining the VPC - terraform gives the following:

Error: Invalid count argument

on .terraform/modules/subnets_ipv6_only/main.tf line 272, in data "aws_vpc" "default":
272: count = local.need_vpc_data ? 1 : 0

The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be
created. To work around this, use the -target argument to first apply only
the resources that the count depends on.

(Unfortunately, Terraform can't work out that although it doesn't know the values of the 'Private' list, it does know the length which should be sufficient)

Expected Behavior

Ability to create extra IPv6 subnets (e.g. some with and some without IPv4)

Use Case

I need some subnets with IPv4 and some without.

Describe Ideal Solution

A couple of options for how to fix this:

  • Accept a value for var.ipv6_cidr_block that doesn't have to be a /56 (e.g. it could be a /57 or /58), meaning the fix can be analogous to IPv4. I think you can do this by parsing the input CIDR, and then setting local.required_ipv6_subnet_bits appropriately.
  • Allow passing existing blocks & only return those that don't clash and/or are after all of those presented. I can't see a nice way to do this.

Alternatives Considered

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions