-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
160 lines (148 loc) · 4.54 KB
/
index.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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { Network } from '@pulumi/gcp/compute/network'
import { VpcSubnet, VpcSubnetStruct } from "./vpcSubnet"
import { VpcNetwork, VpcNetworkStruct } from "./vpcNetwork"
import { VpcFirewall, VpcFirewallStruct } from './vpcFirewall'
/**
* Create VPC Network
*/
const vpcNetworkStruct: VpcNetworkStruct = {
name: 'backend-vpc-net',
description: 'VPC Network'
}
const vpcNetwork: Network = VpcNetwork(vpcNetworkStruct)
/**
* Create VPC Subnetwork
*/
const vpcSubnetStructs: VpcSubnetStruct[] = [
// asia-southeast2 (jakarta) subnetwork
{
name: 'backend-vpc-subnet-jkt-0',
description: 'VPC Subnetwork (jakarta)',
ipCidrRange: '10.0.0.0/24', // 254 hosts
network: vpcNetwork.id,
region: 'asia-southeast2',
purpose: 'PRIVATE_RFC_1918',
privateIpGoogleAccess: true,
stackType: 'IPV4_ONLY',
secondaryIpRanges: [{
rangeName: 'backend-vpc-subnet-jkt-1',
ipCidrRange: '11.0.0.0/26' // 62 hosts
}]
},
// asia-southeast1 (singapore) subnetwork
{
name: 'backend-vpc-subnet-sg-0',
description: 'VPC Subnetwork (singapore)',
ipCidrRange: '10.0.1.0/24', // 254 hosts
network: vpcNetwork.id,
region: 'asia-southeast1',
purpose: 'PRIVATE_RFC_1918',
privateIpGoogleAccess: true,
stackType: 'IPV4_ONLY',
secondaryIpRanges: [{
rangeName: 'backend-vpc-subnet-sg-1',
ipCidrRange: '11.0.1.0/26' // 62 hosts
}]
}
]
vpcSubnetStructs.forEach(
vpcSubnetStruct => VpcSubnet(vpcSubnetStruct)
)
/**
* Create VPC Firewall
*/
const vpcFirewallStructs: VpcFirewallStruct[] = [
// Firewall Allow HTTP & HTTPS
{
name: 'backend-vpc-fw-allow-http-https-ingress',
description: 'Firewall Allow HTTP & HTTPS',
network: vpcNetwork.name,
priority: 65534,
direction: 'INGRESS',
sourceRanges: [ '0.0.0.0/0' ],
destinationRanges: [
// asia-southeast2 (Jakarta)
'10.0.0.0/24', '11.0.1.0/26',
// asia-southeast1 (Singapore)
'10.0.1.0/24', '11.0.1.0/26',
],
allows: [
{
protocol: 'tcp',
ports: [ '80', '443' ]
}
],
targetTags: [ 'backend-svc-idn', 'backend-svc-sg' ],
},
// Firewall Allow SSH Internal (INGRESS)
{
name: 'backend-vpc-fw-allow-ssh-internal-ingress',
description: 'Firewall Allow HTTP & HTTPS',
network: vpcNetwork.name,
priority: 65534,
direction: 'INGRESS',
sourceRanges: [
// asia-southeast2 (Jakarta)
'10.0.0.0/24', '11.0.1.0/26',
],
destinationRanges: [
// asia-southeast1 (Singapore)
'10.0.1.0/24', '11.0.1.0/26',
],
allows: [
{
protocol: 'tcp',
ports: [ '22' ]
}
],
targetTags: [ 'backend-svc-idn', 'backend-svc-sg' ],
},
// Firewall Allow SSH Internal (EGRESS)
{
name: 'backend-vpc-fw-allow-ssh-internal-egress',
description: 'Firewall Allow HTTP & HTTPS',
network: vpcNetwork.name,
priority: 65534,
direction: 'EGRESS',
sourceRanges: [
// asia-southeast1 (Singapore)
'10.0.1.0/24', '11.0.1.0/26',
],
destinationRanges: [
// asia-southeast2 (Jakarta)
'10.0.0.0/24', '11.0.1.0/26',
],
allows: [
{
protocol: 'tcp',
ports: [ '22' ]
}
],
targetTags: [ 'backend-svc-idn', 'backend-svc-sg' ],
},
// Firewall Allow SSH External (INGRESS)
{
name: 'backend-vpc-fw-allow-ssh-external-ingress',
description: 'Firewall Allow HTTP & HTTPS',
network: vpcNetwork.name,
priority: 65534,
direction: 'INGRESS',
sourceRanges: [
'0.0.0.0/0'
],
destinationRanges: [
// asia-southeast2 (Jakarta)
'10.0.0.0/24', '11.0.1.0/26',
],
allows: [
{
protocol: 'tcp',
ports: [ '22' ]
}
],
targetTags: [ 'backend-svc-idn' ],
}
]
vpcFirewallStructs.forEach(
vpcFirewallStruct => VpcFirewall(vpcFirewallStruct)
)