hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.65k stars 9.03k forks source link

Add BYOIP usage support to VPCs #17425

Open gwvandesteeg opened 3 years ago

gwvandesteeg commented 3 years ago

Community Note

Description

There are a variety of components that need to be added and update to allow for the creation of VPCs when using BYOIP, especially since the support for IPv6 BYOIP was added. This feature request only defines the changes needed to utilise the BYOIP blocks not the loading and activation of the BYOIP blocks (as such we exclude the provision-byoip-cidr, advertise-byoip-cidr, and withdraw-byoip-cidr CLI command functionality)

User Stories

This last User story allows us to deal with certain network applications that do not function well behind NAT connections, by creating a VPC with the same network range as your public range you can then trick the application in thinking it is not behind NAT. Let's say you have 1.2.3.0/24 as your BYOIP block, you create a VPC that also has 1.2.3.0/24 as its subnet then you can spin up instances inside that VPC that have IPs in this IP range on the EC2 instance. By then allocating an EIP with the exact same IP to these instances to the world and the application they all believe they are on this IP and the network traffic gets routed correctly. (It looks crazy but it works).

New or Affected Resource(s)

Potential Terraform Configuration


data "aws_vpc_ipv6_pools" "pools"  {}

data "aws_vpc_public_ipv4_pools" "pools" {}

resource "aws_vpc" "vpc" {
  ipv6_cidr_block = data.aws_vpc_ipv6_pools.pools[0].cidr
  ipv6_pool = data.aws_vpc_ipv6_pools.pools[0].id
}

resource "aws_eip" "eip" {
  address = cidrhost(data.aws_vpc_public_ipv4_pools.pools[0].cidr, 1)
}

References

BYOIP

aws_vpc change:

aws_vpc_ipv6_pools addition:

aws_vpc_public_ipv4_pools addtion:

aws_vpc_ipv6_cidr_block_association addition:

aws_eip change:

ewbankkit commented 3 years ago

Support for a aws_vpc_ipv6_cidr_block_association resource also mentioned here.

YakDriver commented 3 years ago

See #8876 for partial fix to this.

AdamTylerLynch commented 2 years ago

Related #21998

Need to scope of effort to to finish BYOIP.

hoo29 commented 2 years ago

You can achieve this by using terraform to provision a cloudformation stack with a AWS::EC2::VPCCidrBlock resource. e.g.

resource "aws_cloudformation_stack" "ipv6" {
  name = "terraform-cf"

  parameters = {
    IPv6Cidr   = local.ipv6_cidr
    IPv6Poolid = local.ipv6_pool_id
    VpcId      = local.vpc_id
  }

  template_body = <<STACK
{
  "Parameters": {
    "IPv6Cidr": {
      "Type": "String",
      "Description": "Enter the IPv6 CIDR block for the VPC."
    },
    "IPv6Poolid": {
      "Type": "String",
      "Description": "Enter the IPv6 Pool ID for the CIDR block."
    },
    "VpcId": {
      "Type": "String",
      "Description": "Enter the VPC ID."
    }
  },
  "Resources": {
    "myVpc": {
      "Type": "AWS::EC2::VPCCidrBlock",
      "Properties": {
        "Ipv6CidrBlock": {
          "Ref": "IPv6Cidr"
        },
        "Ipv6Pool": {
          "Ref": "IPv6Poolid"
        },
        "VpcId": {
          "Ref": "VpcId"
        }
      }
    }
  }
}
STACK
}

Then ensure you include a depends_on reference to this resource in your aws_subnet resources.

andyshinn commented 1 year ago

I didn't see it on the list. But I would like the ability to start advertising the BYOIP CIDR. You can currently bring it into IPAM> But you cannot advertise it in Terraform.