sparse-intern-71089
10/03/2023, 8:47 PMicy-dress-83371
10/04/2023, 1:35 PMpulumi_aws
components and build each piece myself. Creating the VPC, then adding the additional cidr block, followed by the subnets, then everything else like nat gateway and internet gateway.billowy-army-68599
icy-dress-83371
10/04/2023, 2:48 PMlocals {
cluster_name = "${var.name}-${var.environment}"
region = var.aws_region
sliced_azs = slice(data.aws_availability_zones.available_azs.zone_ids, 0, var.number_of_azs)
subnet_group_count = 3
tags = {
Environment = var.environment
}
}
data "aws_availability_zones" "available_azs" {
state = "available"
exclude_names = [ "us-east-1e" ] #us-east-1e was not supporting EKS deployment
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "${var.name}-${var.environment}-vpc"
cidr = var.primary_vpc_cidr
secondary_cidr_blocks = [var.secondary_vpc_cidr]
azs = local.sliced_azs
enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
private_subnets = [
for netnumber in range(0, length(local.sliced_azs)):
cidrsubnet(var.primary_vpc_cidr, ceil(log(length(local.sliced_azs) * local.subnet_group_count, 2)), netnumber)
]
public_subnets = [
for netnumber in range(length(local.sliced_azs), length(local.sliced_azs) * 2):
cidrsubnet(var.primary_vpc_cidr, ceil(log(length(local.sliced_azs) * local.subnet_group_count, 2)), netnumber)
]
intra_subnets = [
for netnumber in range(length(local.sliced_azs) * 2, length(local.sliced_azs)):
cidrsubnet(var.secondary_vpc_cidr, ceil(log(length(local.sliced_azs) * local.subnet_group_count, 2)), netnumber)
]
tags = {
"<http://kubernetes.io/cluster/${local.cluster_name}|kubernetes.io/cluster/${local.cluster_name}>" = "shared"
}
public_subnet_tags = {
"<http://kubernetes.io/cluster/${local.cluster_name}-primary|kubernetes.io/cluster/${local.cluster_name}-primary>" = "shared"
"<http://kubernetes.io/role/elb|kubernetes.io/role/elb>" = "1"
}
private_subnet_tags = {
"<http://kubernetes.io/cluster/${local.cluster_name}-primary|kubernetes.io/cluster/${local.cluster_name}-primary>" = "shared"
"<http://kubernetes.io/role/internal-elb|kubernetes.io/role/internal-elb>" = "1"
}
}
icy-dress-83371
10/04/2023, 2:55 PMicy-dress-83371
10/04/2023, 2:58 PMbillowy-army-68599
awsx.ec2.Vpc
as a native input. However, you should be able to do this, because it’s just a resource https://github.com/terraform-aws-modules/terraform-aws-vpc/blob/master/main.tf#L53billowy-army-68599
icy-dress-83371
10/04/2023, 3:04 PMaws.ec2.VpcIpv4CidrBlockAssociation
requires a vpc_id. But in order for the VPC to be built (at least using awsx.ec2.Vpc
) I need to provide subnet specs. I also don’t see how I would set the actual cidr for each subnet, when it only seems to allow a cidr_mask.billowy-army-68599
icy-dress-83371
10/04/2023, 3:11 PMbillowy-army-68599
billowy-army-68599
"""An AWS Python Pulumi program"""
import pulumi
import pulumi_aws as aws
import pulumi_awsx as awsx
vpc = awsx.ec2.Vpc(
"vpc",
cidr_block="10.0.0.0/16",
subnet_specs=[
awsx.ec2.SubnetSpecArgs(
cidr_mask=22,
type="public",
),
awsx.ec2.SubnetSpecArgs(
cidr_mask=22,
type="private",
),
],
)
secondary_block = aws.ec2.VpcIpv4CidrBlockAssociation(
"secondaryBlock", vpc_id=vpc.vpc_id, cidr_block="10.0.20.0/22"
)
intra = aws.ec2.Subnet(
"intra",
vpc_id=vpc.vpc_id,
cidr_block=secondary_block.cidr_block,
)
intra_rt = aws.ec2.RouteTable(
"intra",
vpc_id=vpc.vpc_id,
)
intra_rt_associ = aws.ec2.RouteTableAssociation(
"intra",
route_table_id=intra_rt.id,
subnet_id=intra.id,
)
icy-dress-83371
10/04/2023, 3:26 PMbillowy-army-68599
icy-dress-83371
10/04/2023, 3:32 PMbillowy-army-68599
icy-dress-83371
10/04/2023, 3:34 PMicy-dress-83371
10/04/2023, 3:34 PMbillowy-army-68599
icy-dress-83371
10/04/2023, 3:41 PMbillowy-army-68599