Skip to content

Commit 50c0a9d

Browse files
committed
aws/publicIpv4Pool: terraform - allocate byoip from eips
Terraform support for user-specified Public IPv4 Pool ID feature (BYOIPv4). Terraform will allocate EIPs for resources in public subnets when installing a cluster with publish strategy External. The EIPs will be claimed from a Public IPv4 Pool ID, and EIPs will be associated to resousces: Nat Gateways, Public Network LBs, and EC2 for Bootstrap node.
1 parent e0a520b commit 50c0a9d

File tree

8 files changed

+61
-2
lines changed

8 files changed

+61
-2
lines changed

data/data/aws/bootstrap/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,11 @@ resource "aws_security_group_rule" "bootstrap_journald_gateway" {
249249
from_port = 19531
250250
to_port = 19531
251251
}
252+
253+
resource "aws_eip" "bootstrap" {
254+
domain = "vpc"
255+
instance = aws_instance.bootstrap.id
256+
public_ipv4_pool = var.aws_public_ipv4_pool == "" ? null : var.aws_public_ipv4_pool
257+
258+
depends_on = [aws_instance.bootstrap]
259+
}

data/data/aws/cluster/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ module "vpc" {
109109
edge_parent_gw_map = var.aws_edge_parent_zones_index
110110
edge_zones_type = var.aws_edge_zones_type
111111

112+
public_ipv4_pool = var.aws_public_ipv4_pool
113+
112114
tags = local.tags
113115
}
114116

data/data/aws/cluster/vpc/master-elb.tf

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@ resource "aws_lb" "api_external" {
2424

2525
name = "${var.cluster_id}-ext"
2626
load_balancer_type = "network"
27-
subnets = data.aws_subnet.public.*.id
2827
internal = false
2928
enable_cross_zone_load_balancing = true
3029

30+
dynamic "subnet_mapping" {
31+
for_each = range(length(data.aws_subnet.public))
32+
33+
content {
34+
subnet_id = data.aws_subnet.public[subnet_mapping.key].id
35+
allocation_id = aws_eip.api_nlb_public[subnet_mapping.key].id
36+
}
37+
}
38+
3139
tags = merge(
3240
{
3341
"Name" = "${var.cluster_id}-ext"
@@ -38,7 +46,24 @@ resource "aws_lb" "api_external" {
3846
timeouts {
3947
create = "20m"
4048
}
49+
}
50+
51+
resource "aws_eip" "api_nlb_public" {
52+
count = length(var.availability_zones)
53+
domain = "vpc"
54+
55+
public_ipv4_pool = var.public_ipv4_pool == "" ? null : var.public_ipv4_pool
56+
57+
tags = merge(
58+
{
59+
"Name" = "${var.cluster_id}-eip-${var.availability_zones[count.index]}-lb-api"
60+
},
61+
var.tags,
62+
)
4163

64+
# Terraform does not declare an explicit dependency towards the internet gateway.
65+
# this can cause the internet gateway to be deleted/detached before the EIPs.
66+
# https://github.com/coreos/tectonic-installer/issues/1017#issuecomment-307780549
4267
depends_on = [aws_internet_gateway.igw]
4368
}
4469

data/data/aws/cluster/vpc/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ variable "public_subnets" {
5959
variable "private_subnets" {
6060
type = list(string)
6161
description = "Existing private subnets into which the cluster should be installed."
62+
}
63+
64+
variable "public_ipv4_pool" {
65+
type = string
66+
description = "An Public IPv4 Pool"
6267
}

data/data/aws/cluster/vpc/vpc-public.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ resource "aws_eip" "nat_eip" {
9595
count = var.public_subnets == null ? length(var.availability_zones) : 0
9696
vpc = true
9797

98+
public_ipv4_pool = var.public_ipv4_pool == "" ? null : var.public_ipv4_pool
99+
98100
tags = merge(
99101
{
100102
"Name" = "${var.cluster_id}-eip-${var.availability_zones[count.index]}"

data/data/aws/variables-aws.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,16 @@ a Public Route Table and the default route entry pointing to the carrier gateway
226226
227227
Example: `{ "us-east-1-nyc-1a"=local-zone, "us-east-1-wl1-nyc-wlz-1"=wavelength-zone }`
228228
EOF
229-
}
229+
}
230+
231+
variable "aws_public_ipv4_pool" {
232+
type = string
233+
234+
description = <<EOF
235+
(optional) Indicates the installation process to use Public IPv4 address
236+
that you bring to your AWS account with BYOIP to create resources which consumes
237+
Elastic IPs when the publish strategy is External.
238+
EOF
239+
240+
default = ""
241+
}

pkg/asset/cluster/tfvars/tfvars.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
333333
Proxy: installConfig.Config.Proxy,
334334
PreserveBootstrapIgnition: installConfig.Config.AWS.PreserveBootstrapIgnition,
335335
MasterSecurityGroups: securityGroups,
336+
PublicIpv4Pool: installConfig.Config.AWS.PublicIpv4Pool,
336337
})
337338
if err != nil {
338339
return errors.Wrapf(err, "failed to get %s Terraform variables", platform)

pkg/tfvars/aws/aws.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Config struct {
4949
BootstrapMetadataAuthentication string `json:"aws_bootstrap_instance_metadata_authentication,omitempty"`
5050
PreserveBootstrapIgnition bool `json:"aws_preserve_bootstrap_ignition"`
5151
MasterSecurityGroups []string `json:"aws_master_security_groups,omitempty"`
52+
PublicIpv4Pool string `json:"aws_public_ipv4_pool"`
5253
}
5354

5455
// TFVarsSources contains the parameters to be converted into Terraform variables
@@ -80,6 +81,8 @@ type TFVarsSources struct {
8081
PreserveBootstrapIgnition bool
8182

8283
MasterSecurityGroups []string
84+
85+
PublicIpv4Pool string
8386
}
8487

8588
// TFVars generates AWS-specific Terraform variables launching the cluster.
@@ -207,6 +210,7 @@ func TFVars(sources TFVarsSources) ([]byte, error) {
207210
WorkerIAMRoleName: sources.WorkerIAMRoleName,
208211
PreserveBootstrapIgnition: sources.PreserveBootstrapIgnition,
209212
MasterSecurityGroups: sources.MasterSecurityGroups,
213+
PublicIpv4Pool: sources.PublicIpv4Pool,
210214
}
211215

212216
stubIgn, err := bootstrap.GenerateIgnitionShimWithCertBundleAndProxy(sources.IgnitionPresignedURL, sources.AdditionalTrustBundle, sources.Proxy)

0 commit comments

Comments
 (0)