forked from datalisk/pulumi-aws-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStdSecurityGroup.ts
More file actions
62 lines (54 loc) · 2.01 KB
/
Copy pathStdSecurityGroup.ts
File metadata and controls
62 lines (54 loc) · 2.01 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as aws from "@pulumi/aws";
import { ComponentResource, ComponentResourceOptions, Output } from "@pulumi/pulumi";
import { IVpc } from "./Vpc";
/**
* A simple security group for many standard cases.
*/
export class StdSecurityGroup extends ComponentResource {
readonly name: string;
readonly securityGroupId: Output<string>;
constructor(name: string, args: StdSecurityGroupArgs, opts?: ComponentResourceOptions) {
super("pat:vpc:StdSecurityGroup", name, args, opts);
this.name = name;
const sg = new aws.ec2.SecurityGroup(name, {
vpcId: args.vpc.vpcId,
description: name,
}, { parent: this });
this.securityGroupId = sg.id;
for (const port of args.ingressPorts) {
new aws.vpc.SecurityGroupIngressRule(`${name}-ipv4-${port}`, {
securityGroupId: sg.id,
ipProtocol: "tcp",
fromPort: port,
toPort: port,
cidrIpv4: args.publicIngress ? "0.0.0.0/0" : args.vpc.cidrIpv4,
}, { parent: this });
new aws.vpc.SecurityGroupIngressRule(`${name}-ipv6-${port}`, {
securityGroupId: sg.id,
ipProtocol: "tcp",
fromPort: port,
toPort: port,
cidrIpv6: args.publicIngress ? "::/0" : args.vpc.cidrIpv6,
}, { parent: this });
}
new aws.vpc.SecurityGroupEgressRule(`${name}-ipv4`, {
securityGroupId: sg.id,
ipProtocol: "tcp",
fromPort: 0,
toPort: 65535,
cidrIpv4: "0.0.0.0/0",
}, { parent: this });
new aws.vpc.SecurityGroupEgressRule(`${name}-ipv6`, {
securityGroupId: sg.id,
ipProtocol: "tcp",
fromPort: 0,
toPort: 65535,
cidrIpv6: "::/0",
}, { parent: this });
}
}
export interface StdSecurityGroupArgs {
readonly ingressPorts: number[];
readonly publicIngress: boolean;
readonly vpc: IVpc;
}