-
-
Save cnunciato/ae73657396224cb0f34165707c154f45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as pulumi from "@pulumi/pulumi"; | |
import * as aws from "@pulumi/aws"; | |
import * as awsx from "@pulumi/awsx"; | |
const DEFAULT_NUMBER_OF_AVAILABILITY_ZONES = 1; | |
class AubeNetwork extends pulumi.ComponentResource { | |
vpc: awsx.ec2.Vpc; | |
constructor( | |
name: string, | |
networkCidr: string, | |
numberOfAvailabilityZones?: number, | |
opts?: pulumi.ComponentResourceOptions | |
) { | |
super("pkg:aube:network", name, {}, opts); | |
this.vpc = new awsx.ec2.Vpc( | |
`vpc-${name}`, | |
{ | |
enableDnsHostnames: true, | |
enableDnsSupport: true, | |
numberOfAvailabilityZones: | |
numberOfAvailabilityZones || | |
DEFAULT_NUMBER_OF_AVAILABILITY_ZONES, | |
cidrBlock: networkCidr, | |
subnetSpecs: [ | |
{ | |
type: "Private", | |
tags: { | |
"kubernetes.io/role/internal-elb": "1", //https://aws.amazon.com/premiumsupport/knowledge-center/eks-vpc-subnet-discovery/ | |
}, | |
cidrMask: 19, | |
}, | |
{ | |
type: "Public", | |
tags: { | |
"kubernetes.io/role/elb": "1", | |
}, | |
cidrMask: 20, | |
}, | |
], | |
tags: { | |
Name: `vpc-${name}`, | |
}, | |
}, | |
{ parent: this } | |
); | |
this.registerOutputs({ | |
vpcId: this.vpc.vpcId, | |
vpcPublicSubnetIds: this.vpc.publicSubnetIds, | |
vpcPrivateSubnetIds: this.vpc.privateSubnetIds, | |
}); | |
} | |
} | |
class AubeDatabase extends pulumi.ComponentResource { | |
vpc: awsx.ec2.Vpc; | |
constructor( | |
name: string, | |
vpc: awsx.ec2.Vpc, | |
opts?: pulumi.ComponentResourceOptions | |
) { | |
super("pkg:aube:network", name, {}, opts); | |
this.vpc = vpc; | |
const rdsSecurityGroup = new aws.ec2.SecurityGroup( | |
`${name}-rds-security-group`, | |
{ | |
vpcId: vpc.vpcId, | |
description: `Enables access on ${name} RDS`, | |
ingress: [ | |
{ | |
protocol: "tcp", | |
fromPort: 5432, | |
toPort: 5432, | |
cidrBlocks: ["0.0.0.0/0"], | |
}, | |
], | |
egress: [ | |
{ | |
protocol: "tcp", | |
fromPort: 5432, | |
toPort: 5432, | |
cidrBlocks: ["0.0.0.0/0"], | |
}, | |
], | |
}, | |
{ parent: this }, | |
); | |
} | |
} | |
const network = new AubeNetwork("network", "10.0.0.0/16", 1); | |
const database = new AubeDatabase("db", network.vpc, { parent: network.vpc }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment