-
Notifications
You must be signed in to change notification settings - Fork 1
/
vpc-gcp.ts
35 lines (29 loc) · 1.08 KB
/
vpc-gcp.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 gcp from "@pulumi/gcp";
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:gcp:Vpc", args.name, {});
const vpc = new gcp.compute.Network(args.name, {
name: args.name,
autoCreateSubnetworks: false,
}, { parent: this });
const subnetIds = args.subnetCidrBlocks.map((cidrBlock, i) => {
const subnetName = `${args.name}-${i}`;
const subnet = new gcp.compute.Subnetwork(subnetName, {
name: subnetName,
network: vpc.selfLink,
ipCidrRange: cidrBlock,
});
return subnet.selfLink;
}, { parent: this });
this.vpcId = vpc.selfLink;
this.subnetIds = subnetIds;
this.registerOutputs({
vpcId: vpc.id,
subnetIds: subnetIds,
})
}
}