-
Notifications
You must be signed in to change notification settings - Fork 1
/
vpc-aws.ts
35 lines (29 loc) · 1.06 KB
/
vpc-aws.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";
import { Vpc, VpcArgs } from "./vpc";
export class MyVpc extends pulumi.ComponentResource implements Vpc {
public readonly vpcId: pulumi.Output<string>;
public readonly subnetIds: pulumi.Output<string>[];
constructor(args: VpcArgs) {
super("custom:aws:Vpc", args.name, {});
const vpc = new aws.ec2.Vpc(args.name, {
cidrBlock: args.cidrBlock,
tags: { "Name": args.name, },
}, { parent: this });
const subnetIds = args.subnetCidrBlocks.map((cidrBlock, i) => {
const subnetName = `${args.name}-${i}`;
const subnet = new aws.ec2.Subnet(subnetName, {
vpcId: vpc.id,
cidrBlock: cidrBlock,
tags: { "Name": subnetName, },
});
return subnet.id;
}, { parent: this });
this.vpcId = vpc.id;
this.subnetIds = subnetIds;
this.registerOutputs({
vpcId: vpc.id,
subnetIds: subnetIds,
})
}
}