@studion/infra-code-blocks 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -7
- package/dist/components/acm-certificate.d.ts +10 -0
- package/dist/components/acm-certificate.js +29 -0
- package/dist/components/database.d.ts +48 -0
- package/dist/components/database.js +64 -0
- package/dist/components/ec2-ssm-connect.d.ts +16 -0
- package/dist/components/ec2-ssm-connect.js +104 -0
- package/dist/components/project.d.ts +24 -15
- package/dist/components/project.js +42 -111
- package/dist/components/redis.d.ts +7 -2
- package/dist/components/redis.js +7 -3
- package/dist/components/static-site.d.ts +20 -0
- package/dist/components/static-site.js +108 -0
- package/dist/components/web-server.d.ts +86 -0
- package/dist/components/web-server.js +304 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/package.json +3 -3
- package/dist/components/ecs.d.ts +0 -33
- package/dist/components/ecs.js +0 -154
- package/dist/components/rds.d.ts +0 -20
- package/dist/components/rds.js +0 -42
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebServer = void 0;
|
|
4
|
+
const pulumi = require("@pulumi/pulumi");
|
|
5
|
+
const aws = require("@pulumi/aws");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const acm_certificate_1 = require("./acm-certificate");
|
|
8
|
+
const config = new pulumi.Config('aws');
|
|
9
|
+
const awsRegion = config.require('region');
|
|
10
|
+
const assumeRolePolicy = {
|
|
11
|
+
Version: '2012-10-17',
|
|
12
|
+
Statement: [
|
|
13
|
+
{
|
|
14
|
+
Action: 'sts:AssumeRole',
|
|
15
|
+
Principal: {
|
|
16
|
+
Service: 'ecs-tasks.amazonaws.com',
|
|
17
|
+
},
|
|
18
|
+
Effect: 'Allow',
|
|
19
|
+
Sid: '',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
const defaults = {
|
|
24
|
+
desiredCount: 1,
|
|
25
|
+
minCount: 1,
|
|
26
|
+
maxCount: 10,
|
|
27
|
+
size: 'small',
|
|
28
|
+
environment: [],
|
|
29
|
+
healtCheckPath: '/healtcheck',
|
|
30
|
+
taskExecutionRoleInlinePolicies: [],
|
|
31
|
+
taskRoleInlinePolicies: [],
|
|
32
|
+
};
|
|
33
|
+
class WebServer extends pulumi.ComponentResource {
|
|
34
|
+
constructor(name, args, opts = {}) {
|
|
35
|
+
super('studion:WebServer', name, {}, opts);
|
|
36
|
+
const argsWithDefaults = Object.assign({}, defaults, args);
|
|
37
|
+
this.certificate = new acm_certificate_1.AcmCertificate(`${argsWithDefaults.domain}-acm-certificate`, {
|
|
38
|
+
domain: argsWithDefaults.domain,
|
|
39
|
+
hostedZoneId: argsWithDefaults.hostedZoneId,
|
|
40
|
+
}, { parent: this });
|
|
41
|
+
this.logGroup = new aws.cloudwatch.LogGroup(`${name}-log-group`, {
|
|
42
|
+
retentionInDays: 14,
|
|
43
|
+
name: `/ecs/${name}`,
|
|
44
|
+
}, { parent: this });
|
|
45
|
+
this.lbSecurityGroup = new aws.ec2.SecurityGroup(`${name}-lb-security-group`, {
|
|
46
|
+
vpcId: argsWithDefaults.vpc.vpcId,
|
|
47
|
+
ingress: [
|
|
48
|
+
{
|
|
49
|
+
protocol: 'tcp',
|
|
50
|
+
fromPort: 80,
|
|
51
|
+
toPort: 80,
|
|
52
|
+
cidrBlocks: ['0.0.0.0/0'],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
protocol: 'tcp',
|
|
56
|
+
fromPort: 443,
|
|
57
|
+
toPort: 443,
|
|
58
|
+
cidrBlocks: ['0.0.0.0/0'],
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
egress: [
|
|
62
|
+
{
|
|
63
|
+
fromPort: 0,
|
|
64
|
+
toPort: 0,
|
|
65
|
+
protocol: '-1',
|
|
66
|
+
cidrBlocks: ['0.0.0.0/0'],
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
}, { parent: this });
|
|
70
|
+
this.lb = new aws.lb.LoadBalancer(`${name}-lb`, {
|
|
71
|
+
name: `${name}-lb`,
|
|
72
|
+
loadBalancerType: 'application',
|
|
73
|
+
subnets: argsWithDefaults.vpc.publicSubnetIds,
|
|
74
|
+
securityGroups: [this.lbSecurityGroup.id],
|
|
75
|
+
internal: false,
|
|
76
|
+
ipAddressType: 'ipv4',
|
|
77
|
+
}, { parent: this });
|
|
78
|
+
this.lbTargetGroup = new aws.lb.TargetGroup(`${name}-lb-tg`, {
|
|
79
|
+
name: `${name}-lb-tg`,
|
|
80
|
+
port: argsWithDefaults.port,
|
|
81
|
+
protocol: 'HTTP',
|
|
82
|
+
targetType: 'ip',
|
|
83
|
+
vpcId: argsWithDefaults.vpc.vpcId,
|
|
84
|
+
healthCheck: {
|
|
85
|
+
healthyThreshold: 3,
|
|
86
|
+
unhealthyThreshold: 2,
|
|
87
|
+
interval: 60,
|
|
88
|
+
timeout: 5,
|
|
89
|
+
path: argsWithDefaults.healtCheckPath,
|
|
90
|
+
},
|
|
91
|
+
}, { parent: this, dependsOn: [this.lb] });
|
|
92
|
+
this.lbHttpListener = new aws.lb.Listener(`${name}-lb-listener-80`, {
|
|
93
|
+
loadBalancerArn: this.lb.arn,
|
|
94
|
+
port: 80,
|
|
95
|
+
defaultActions: [
|
|
96
|
+
{
|
|
97
|
+
type: 'redirect',
|
|
98
|
+
redirect: {
|
|
99
|
+
port: '443',
|
|
100
|
+
protocol: 'HTTPS',
|
|
101
|
+
statusCode: 'HTTP_301',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
}, { parent: this });
|
|
106
|
+
this.lbTlsListener = new aws.lb.Listener(`${name}-lb-listener-443`, {
|
|
107
|
+
loadBalancerArn: this.lb.arn,
|
|
108
|
+
port: 443,
|
|
109
|
+
protocol: 'HTTPS',
|
|
110
|
+
sslPolicy: 'ELBSecurityPolicy-2016-08',
|
|
111
|
+
certificateArn: this.certificate.certificate.arn,
|
|
112
|
+
defaultActions: [
|
|
113
|
+
{
|
|
114
|
+
type: 'forward',
|
|
115
|
+
targetGroupArn: this.lbTargetGroup.arn,
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
}, { parent: this });
|
|
119
|
+
const albAliasRecord = new aws.route53.Record(`${name}-route53-record`, {
|
|
120
|
+
type: 'A',
|
|
121
|
+
name: argsWithDefaults.domain,
|
|
122
|
+
zoneId: argsWithDefaults.hostedZoneId,
|
|
123
|
+
aliases: [
|
|
124
|
+
{
|
|
125
|
+
name: this.lb.dnsName,
|
|
126
|
+
zoneId: this.lb.zoneId,
|
|
127
|
+
evaluateTargetHealth: true,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
}, { parent: this });
|
|
131
|
+
const taskExecutionRole = new aws.iam.Role(`${name}-ecs-task-exec-role`, {
|
|
132
|
+
name: `${name}-ecs-task-exec-role`,
|
|
133
|
+
assumeRolePolicy,
|
|
134
|
+
managedPolicyArns: [
|
|
135
|
+
'arn:aws:iam::aws:policy/CloudWatchFullAccess',
|
|
136
|
+
'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess',
|
|
137
|
+
],
|
|
138
|
+
inlinePolicies: argsWithDefaults.taskExecutionRoleInlinePolicies,
|
|
139
|
+
}, { parent: this });
|
|
140
|
+
const execCmdInlinePolicy = {
|
|
141
|
+
name: 'ecs-exec',
|
|
142
|
+
policy: JSON.stringify({
|
|
143
|
+
Version: '2012-10-17',
|
|
144
|
+
Statement: [
|
|
145
|
+
{
|
|
146
|
+
Sid: 'AllowContainerToCreateECSExecSSMChannel',
|
|
147
|
+
Effect: 'Allow',
|
|
148
|
+
Action: [
|
|
149
|
+
'ssmmessages:CreateControlChannel',
|
|
150
|
+
'ssmmessages:CreateDataChannel',
|
|
151
|
+
'ssmmessages:OpenControlChannel',
|
|
152
|
+
'ssmmessages:OpenDataChannel',
|
|
153
|
+
],
|
|
154
|
+
Resource: '*',
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
}),
|
|
158
|
+
};
|
|
159
|
+
const taskRole = new aws.iam.Role(`${name}-ecs-task-role`, {
|
|
160
|
+
name: `${name}-ecs-task-role`,
|
|
161
|
+
assumeRolePolicy,
|
|
162
|
+
inlinePolicies: [
|
|
163
|
+
execCmdInlinePolicy,
|
|
164
|
+
...argsWithDefaults.taskRoleInlinePolicies,
|
|
165
|
+
],
|
|
166
|
+
}, { parent: this });
|
|
167
|
+
const parsedSize = pulumi.all([argsWithDefaults.size]).apply(([size]) => {
|
|
168
|
+
const mapCapabilities = ({ cpu, memory }) => ({
|
|
169
|
+
cpu: String(cpu),
|
|
170
|
+
memory: String(memory),
|
|
171
|
+
});
|
|
172
|
+
if (typeof size === 'string') {
|
|
173
|
+
return mapCapabilities(constants_1.PredefinedSize[size]);
|
|
174
|
+
}
|
|
175
|
+
if (typeof size === 'object') {
|
|
176
|
+
return mapCapabilities(size);
|
|
177
|
+
}
|
|
178
|
+
throw Error('Incorrect EcsService size argument');
|
|
179
|
+
});
|
|
180
|
+
this.taskDefinition = new aws.ecs.TaskDefinition(`${name}-task-definition`, {
|
|
181
|
+
family: `${name}-task-definition`,
|
|
182
|
+
networkMode: 'awsvpc',
|
|
183
|
+
executionRoleArn: taskExecutionRole.arn,
|
|
184
|
+
taskRoleArn: taskRole.arn,
|
|
185
|
+
cpu: parsedSize.cpu,
|
|
186
|
+
memory: parsedSize.memory,
|
|
187
|
+
requiresCompatibilities: ['FARGATE'],
|
|
188
|
+
containerDefinitions: pulumi
|
|
189
|
+
.all([
|
|
190
|
+
name,
|
|
191
|
+
argsWithDefaults.image,
|
|
192
|
+
argsWithDefaults.port,
|
|
193
|
+
argsWithDefaults.environment,
|
|
194
|
+
this.logGroup.name,
|
|
195
|
+
awsRegion,
|
|
196
|
+
])
|
|
197
|
+
.apply(([containerName, image, port, environment, logGroup, region]) => {
|
|
198
|
+
return JSON.stringify([
|
|
199
|
+
{
|
|
200
|
+
readonlyRootFilesystem: true,
|
|
201
|
+
name: containerName,
|
|
202
|
+
image,
|
|
203
|
+
essential: true,
|
|
204
|
+
portMappings: [
|
|
205
|
+
{
|
|
206
|
+
containerPort: port,
|
|
207
|
+
protocol: 'tcp',
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
logConfiguration: {
|
|
211
|
+
logDriver: 'awslogs',
|
|
212
|
+
options: {
|
|
213
|
+
'awslogs-group': logGroup,
|
|
214
|
+
'awslogs-region': region,
|
|
215
|
+
'awslogs-stream-prefix': 'ecs',
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
environment,
|
|
219
|
+
},
|
|
220
|
+
]);
|
|
221
|
+
}),
|
|
222
|
+
}, { parent: this });
|
|
223
|
+
this.serviceSecurityGroup = new aws.ec2.SecurityGroup(`${name}-security-group`, {
|
|
224
|
+
vpcId: argsWithDefaults.vpc.vpcId,
|
|
225
|
+
ingress: [
|
|
226
|
+
{
|
|
227
|
+
fromPort: 0,
|
|
228
|
+
toPort: 0,
|
|
229
|
+
protocol: '-1',
|
|
230
|
+
securityGroups: [this.lbSecurityGroup.id],
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
egress: [
|
|
234
|
+
{
|
|
235
|
+
fromPort: 0,
|
|
236
|
+
toPort: 0,
|
|
237
|
+
protocol: '-1',
|
|
238
|
+
cidrBlocks: ['0.0.0.0/0'],
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
}, { parent: this });
|
|
242
|
+
this.service = new aws.ecs.Service(`${name}-service`, {
|
|
243
|
+
name,
|
|
244
|
+
cluster: argsWithDefaults.cluster.id,
|
|
245
|
+
launchType: 'FARGATE',
|
|
246
|
+
desiredCount: argsWithDefaults.desiredCount,
|
|
247
|
+
taskDefinition: this.taskDefinition.arn,
|
|
248
|
+
enableExecuteCommand: true,
|
|
249
|
+
loadBalancers: [
|
|
250
|
+
{
|
|
251
|
+
containerName: name,
|
|
252
|
+
containerPort: argsWithDefaults.port,
|
|
253
|
+
targetGroupArn: this.lbTargetGroup.arn,
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
networkConfiguration: {
|
|
257
|
+
assignPublicIp: true,
|
|
258
|
+
subnets: argsWithDefaults.vpc.publicSubnetIds,
|
|
259
|
+
securityGroups: [this.serviceSecurityGroup.id],
|
|
260
|
+
},
|
|
261
|
+
}, {
|
|
262
|
+
parent: this,
|
|
263
|
+
dependsOn: [
|
|
264
|
+
this.lb,
|
|
265
|
+
this.lbTargetGroup,
|
|
266
|
+
this.lbHttpListener,
|
|
267
|
+
this.lbTlsListener,
|
|
268
|
+
],
|
|
269
|
+
});
|
|
270
|
+
const autoscalingTarget = new aws.appautoscaling.Target(`${name}-autoscale-target`, {
|
|
271
|
+
minCapacity: argsWithDefaults.minCount,
|
|
272
|
+
maxCapacity: argsWithDefaults.maxCount,
|
|
273
|
+
resourceId: pulumi.interpolate `service/${argsWithDefaults.cluster.name}/${this.service.name}`,
|
|
274
|
+
serviceNamespace: 'ecs',
|
|
275
|
+
scalableDimension: 'ecs:service:DesiredCount',
|
|
276
|
+
}, { parent: this });
|
|
277
|
+
const memoryAutoscalingPolicy = new aws.appautoscaling.Policy(`${name}-memory-autoscale-policy`, {
|
|
278
|
+
policyType: 'TargetTrackingScaling',
|
|
279
|
+
resourceId: autoscalingTarget.resourceId,
|
|
280
|
+
scalableDimension: autoscalingTarget.scalableDimension,
|
|
281
|
+
serviceNamespace: autoscalingTarget.serviceNamespace,
|
|
282
|
+
targetTrackingScalingPolicyConfiguration: {
|
|
283
|
+
predefinedMetricSpecification: {
|
|
284
|
+
predefinedMetricType: 'ECSServiceAverageMemoryUtilization',
|
|
285
|
+
},
|
|
286
|
+
targetValue: 80,
|
|
287
|
+
},
|
|
288
|
+
}, { parent: this });
|
|
289
|
+
const cpuAutoscalingPolicy = new aws.appautoscaling.Policy(`${name}-cpu-autoscale-policy`, {
|
|
290
|
+
policyType: 'TargetTrackingScaling',
|
|
291
|
+
resourceId: autoscalingTarget.resourceId,
|
|
292
|
+
scalableDimension: autoscalingTarget.scalableDimension,
|
|
293
|
+
serviceNamespace: autoscalingTarget.serviceNamespace,
|
|
294
|
+
targetTrackingScalingPolicyConfiguration: {
|
|
295
|
+
predefinedMetricSpecification: {
|
|
296
|
+
predefinedMetricType: 'ECSServiceAverageCPUUtilization',
|
|
297
|
+
},
|
|
298
|
+
targetValue: 60,
|
|
299
|
+
},
|
|
300
|
+
}, { parent: this });
|
|
301
|
+
this.registerOutputs();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
exports.WebServer = WebServer;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export * from './components/
|
|
2
|
-
export * from './components/
|
|
1
|
+
export * from './components/web-server';
|
|
2
|
+
export * from './components/static-site';
|
|
3
|
+
export * from './components/database';
|
|
3
4
|
export * from './components/redis';
|
|
4
5
|
export * from './components/project';
|
|
6
|
+
export * from './components/ec2-ssm-connect';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./components/
|
|
18
|
-
__exportStar(require("./components/
|
|
17
|
+
__exportStar(require("./components/web-server"), exports);
|
|
18
|
+
__exportStar(require("./components/static-site"), exports);
|
|
19
|
+
__exportStar(require("./components/database"), exports);
|
|
19
20
|
__exportStar(require("./components/redis"), exports);
|
|
20
21
|
__exportStar(require("./components/project"), exports);
|
|
22
|
+
__exportStar(require("./components/ec2-ssm-connect"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@studion/infra-code-blocks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Studion common infra components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"infrastructure",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "npm run clean && tsc",
|
|
28
27
|
"clean": "rm -rf dist",
|
|
28
|
+
"build": "npm run clean && tsc",
|
|
29
29
|
"format": "prettier -w .",
|
|
30
|
-
"release": "release-it",
|
|
30
|
+
"release": "npm run build && release-it",
|
|
31
31
|
"test": ""
|
|
32
32
|
},
|
|
33
33
|
"prettier": "@studion/prettier-config",
|
package/dist/components/ecs.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as pulumi from '@pulumi/pulumi';
|
|
2
|
-
import * as aws from '@pulumi/aws';
|
|
3
|
-
import { Size } from './types';
|
|
4
|
-
export type RoleInlinePolicy = {
|
|
5
|
-
/**
|
|
6
|
-
* Name of the role policy.
|
|
7
|
-
*/
|
|
8
|
-
name?: pulumi.Input<string>;
|
|
9
|
-
/**
|
|
10
|
-
* Policy document as a JSON formatted string.
|
|
11
|
-
*/
|
|
12
|
-
policy?: pulumi.Input<string>;
|
|
13
|
-
};
|
|
14
|
-
export type EcsServiceArgs = {
|
|
15
|
-
image: pulumi.Input<string>;
|
|
16
|
-
port: pulumi.Input<number>;
|
|
17
|
-
cluster: aws.ecs.Cluster;
|
|
18
|
-
subnets: pulumi.Input<pulumi.Input<string>[]>;
|
|
19
|
-
securityGroupIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
20
|
-
lb: aws.lb.LoadBalancer;
|
|
21
|
-
lbTargetGroup: aws.lb.TargetGroup;
|
|
22
|
-
lbListener: aws.lb.Listener;
|
|
23
|
-
desiredCount?: pulumi.Input<number>;
|
|
24
|
-
minCount?: pulumi.Input<number>;
|
|
25
|
-
maxCount?: pulumi.Input<number>;
|
|
26
|
-
size?: pulumi.Input<Size>;
|
|
27
|
-
environment?: aws.ecs.KeyValuePair[];
|
|
28
|
-
taskExecutionRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
29
|
-
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
30
|
-
};
|
|
31
|
-
export declare class EcsService extends pulumi.ComponentResource {
|
|
32
|
-
constructor(name: string, args: EcsServiceArgs, opts?: pulumi.ComponentResourceOptions);
|
|
33
|
-
}
|
package/dist/components/ecs.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EcsService = void 0;
|
|
4
|
-
const pulumi = require("@pulumi/pulumi");
|
|
5
|
-
const aws = require("@pulumi/aws");
|
|
6
|
-
const constants_1 = require("../constants");
|
|
7
|
-
const config = new pulumi.Config('aws');
|
|
8
|
-
const awsRegion = config.get('region');
|
|
9
|
-
const assumeRolePolicy = {
|
|
10
|
-
Version: '2012-10-17',
|
|
11
|
-
Statement: [
|
|
12
|
-
{
|
|
13
|
-
Action: 'sts:AssumeRole',
|
|
14
|
-
Principal: {
|
|
15
|
-
Service: 'ecs-tasks.amazonaws.com',
|
|
16
|
-
},
|
|
17
|
-
Effect: 'Allow',
|
|
18
|
-
Sid: '',
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
};
|
|
22
|
-
class EcsService extends pulumi.ComponentResource {
|
|
23
|
-
constructor(name, args, opts = {}) {
|
|
24
|
-
super('studion:ecs:Service', name, {}, opts);
|
|
25
|
-
const logGroup = new aws.cloudwatch.LogGroup(`${name}-log-group`, {
|
|
26
|
-
retentionInDays: 14,
|
|
27
|
-
name: `/ecs/${name}`,
|
|
28
|
-
}, { parent: this });
|
|
29
|
-
const taskExecutionRole = new aws.iam.Role(`${name}-ecs-task-exec-role`, {
|
|
30
|
-
name: `${name}-ecs-task-exec-role`,
|
|
31
|
-
assumeRolePolicy,
|
|
32
|
-
managedPolicyArns: [
|
|
33
|
-
'arn:aws:iam::aws:policy/CloudWatchFullAccess',
|
|
34
|
-
'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess',
|
|
35
|
-
],
|
|
36
|
-
inlinePolicies: args.taskExecutionRoleInlinePolicies || [],
|
|
37
|
-
}, { parent: this });
|
|
38
|
-
const taskRole = new aws.iam.Role(`${name}-ecs-task-role`, {
|
|
39
|
-
name: `${name}-ecs-task-role`,
|
|
40
|
-
assumeRolePolicy,
|
|
41
|
-
inlinePolicies: args.taskRoleInlinePolicies || [],
|
|
42
|
-
}, { parent: this });
|
|
43
|
-
const parsedSize = pulumi.all([args.size || 'small']).apply(([size]) => {
|
|
44
|
-
const mapCapabilities = ({ cpu, memory }) => ({
|
|
45
|
-
cpu: String(cpu),
|
|
46
|
-
memory: String(memory),
|
|
47
|
-
});
|
|
48
|
-
if (typeof size === 'string') {
|
|
49
|
-
return mapCapabilities(constants_1.PredefinedSize[size]);
|
|
50
|
-
}
|
|
51
|
-
if (typeof size === 'object') {
|
|
52
|
-
return mapCapabilities(size);
|
|
53
|
-
}
|
|
54
|
-
throw Error('Incorrect EcsService size argument');
|
|
55
|
-
});
|
|
56
|
-
const taskDefinition = new aws.ecs.TaskDefinition(`${name}-task-definition`, {
|
|
57
|
-
family: `${name}-task-definition`,
|
|
58
|
-
networkMode: 'awsvpc',
|
|
59
|
-
executionRoleArn: taskExecutionRole.arn,
|
|
60
|
-
taskRoleArn: taskRole.arn,
|
|
61
|
-
cpu: parsedSize.cpu,
|
|
62
|
-
memory: parsedSize.memory,
|
|
63
|
-
requiresCompatibilities: ['FARGATE'],
|
|
64
|
-
containerDefinitions: pulumi
|
|
65
|
-
.all([
|
|
66
|
-
name,
|
|
67
|
-
args.image,
|
|
68
|
-
args.port,
|
|
69
|
-
args.environment || [],
|
|
70
|
-
logGroup.name,
|
|
71
|
-
awsRegion,
|
|
72
|
-
])
|
|
73
|
-
.apply(([containerName, image, port, environment, logGroup, region]) => {
|
|
74
|
-
return JSON.stringify([
|
|
75
|
-
{
|
|
76
|
-
name: containerName,
|
|
77
|
-
image,
|
|
78
|
-
essential: true,
|
|
79
|
-
portMappings: [
|
|
80
|
-
{
|
|
81
|
-
containerPort: port,
|
|
82
|
-
protocol: 'tcp',
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
logConfiguration: {
|
|
86
|
-
logDriver: 'awslogs',
|
|
87
|
-
options: {
|
|
88
|
-
'awslogs-group': logGroup,
|
|
89
|
-
'awslogs-region': region,
|
|
90
|
-
'awslogs-stream-prefix': 'ecs',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
environment,
|
|
94
|
-
},
|
|
95
|
-
]);
|
|
96
|
-
}),
|
|
97
|
-
}, { parent: this });
|
|
98
|
-
const service = new aws.ecs.Service(`${name}-service`, {
|
|
99
|
-
name,
|
|
100
|
-
cluster: args.cluster.id,
|
|
101
|
-
launchType: 'FARGATE',
|
|
102
|
-
desiredCount: args.desiredCount || 1,
|
|
103
|
-
taskDefinition: taskDefinition.arn,
|
|
104
|
-
loadBalancers: [
|
|
105
|
-
{
|
|
106
|
-
containerName: name,
|
|
107
|
-
containerPort: args.port,
|
|
108
|
-
targetGroupArn: args.lbTargetGroup.arn,
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
networkConfiguration: {
|
|
112
|
-
assignPublicIp: true,
|
|
113
|
-
subnets: args.subnets,
|
|
114
|
-
securityGroups: args.securityGroupIds,
|
|
115
|
-
},
|
|
116
|
-
}, {
|
|
117
|
-
parent: this,
|
|
118
|
-
dependsOn: [args.lb, args.lbTargetGroup, args.lbListener],
|
|
119
|
-
});
|
|
120
|
-
const autoscalingTarget = new aws.appautoscaling.Target(`${name}-autoscale-target`, {
|
|
121
|
-
minCapacity: args.minCount || 1,
|
|
122
|
-
maxCapacity: args.maxCount || 10,
|
|
123
|
-
resourceId: pulumi.interpolate `service/${args.cluster.name}/${service.name}`,
|
|
124
|
-
serviceNamespace: 'ecs',
|
|
125
|
-
scalableDimension: 'ecs:service:DesiredCount',
|
|
126
|
-
}, { parent: this });
|
|
127
|
-
const memoryAutoscalingPolicy = new aws.appautoscaling.Policy(`${name}-memory-autoscale-policy`, {
|
|
128
|
-
policyType: 'TargetTrackingScaling',
|
|
129
|
-
resourceId: autoscalingTarget.resourceId,
|
|
130
|
-
scalableDimension: autoscalingTarget.scalableDimension,
|
|
131
|
-
serviceNamespace: autoscalingTarget.serviceNamespace,
|
|
132
|
-
targetTrackingScalingPolicyConfiguration: {
|
|
133
|
-
predefinedMetricSpecification: {
|
|
134
|
-
predefinedMetricType: 'ECSServiceAverageMemoryUtilization',
|
|
135
|
-
},
|
|
136
|
-
targetValue: 80,
|
|
137
|
-
},
|
|
138
|
-
}, { parent: this });
|
|
139
|
-
const cpuAutoscalingPolicy = new aws.appautoscaling.Policy(`${name}-cpu-autoscale-policy`, {
|
|
140
|
-
policyType: 'TargetTrackingScaling',
|
|
141
|
-
resourceId: autoscalingTarget.resourceId,
|
|
142
|
-
scalableDimension: autoscalingTarget.scalableDimension,
|
|
143
|
-
serviceNamespace: autoscalingTarget.serviceNamespace,
|
|
144
|
-
targetTrackingScalingPolicyConfiguration: {
|
|
145
|
-
predefinedMetricSpecification: {
|
|
146
|
-
predefinedMetricType: 'ECSServiceAverageCPUUtilization',
|
|
147
|
-
},
|
|
148
|
-
targetValue: 60,
|
|
149
|
-
},
|
|
150
|
-
}, { parent: this });
|
|
151
|
-
this.registerOutputs();
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
exports.EcsService = EcsService;
|
package/dist/components/rds.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as aws from '@pulumi/aws';
|
|
2
|
-
import * as pulumi from '@pulumi/pulumi';
|
|
3
|
-
export type RdsArgs = {
|
|
4
|
-
dbName: pulumi.Input<string>;
|
|
5
|
-
username: pulumi.Input<string>;
|
|
6
|
-
password: pulumi.Input<string>;
|
|
7
|
-
subnetGroupName: pulumi.Input<string>;
|
|
8
|
-
securityGroupIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
9
|
-
publiclyAccessible?: pulumi.Input<boolean>;
|
|
10
|
-
applyImmediately?: pulumi.Input<boolean>;
|
|
11
|
-
skipFinalSnapshot?: pulumi.Input<boolean>;
|
|
12
|
-
allocatedStorage?: pulumi.Input<number>;
|
|
13
|
-
maxAllocatedStorage?: pulumi.Input<number>;
|
|
14
|
-
instanceClass?: pulumi.Input<string>;
|
|
15
|
-
};
|
|
16
|
-
export type RdsInstance = aws.rds.Instance;
|
|
17
|
-
export declare class Rds extends pulumi.ComponentResource {
|
|
18
|
-
instance: RdsInstance;
|
|
19
|
-
constructor(name: string, args: RdsArgs, opts?: pulumi.ComponentResourceOptions);
|
|
20
|
-
}
|
package/dist/components/rds.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Rds = void 0;
|
|
4
|
-
const aws = require("@pulumi/aws");
|
|
5
|
-
const pulumi = require("@pulumi/pulumi");
|
|
6
|
-
class Rds extends pulumi.ComponentResource {
|
|
7
|
-
constructor(name, args, opts = {}) {
|
|
8
|
-
super('studion:rds:Instance', name, {}, opts);
|
|
9
|
-
const kms = new aws.kms.Key(`${name}-rds-key`, {
|
|
10
|
-
customerMasterKeySpec: 'SYMMETRIC_DEFAULT',
|
|
11
|
-
isEnabled: true,
|
|
12
|
-
keyUsage: 'ENCRYPT_DECRYPT',
|
|
13
|
-
multiRegion: false,
|
|
14
|
-
enableKeyRotation: true,
|
|
15
|
-
}, { parent: this });
|
|
16
|
-
this.instance = new aws.rds.Instance(`${name}-rds`, {
|
|
17
|
-
identifier: name,
|
|
18
|
-
engine: 'postgres',
|
|
19
|
-
engineVersion: '14.9',
|
|
20
|
-
allocatedStorage: args.allocatedStorage || 20,
|
|
21
|
-
maxAllocatedStorage: args.maxAllocatedStorage || 100,
|
|
22
|
-
instanceClass: args.instanceClass || 'db.t3.micro',
|
|
23
|
-
dbName: args.dbName,
|
|
24
|
-
username: args.username,
|
|
25
|
-
password: args.password,
|
|
26
|
-
dbSubnetGroupName: args.subnetGroupName,
|
|
27
|
-
vpcSecurityGroupIds: args.securityGroupIds,
|
|
28
|
-
storageEncrypted: true,
|
|
29
|
-
kmsKeyId: kms.arn,
|
|
30
|
-
publiclyAccessible: args.publiclyAccessible || false,
|
|
31
|
-
skipFinalSnapshot: args.skipFinalSnapshot || false,
|
|
32
|
-
applyImmediately: args.applyImmediately || false,
|
|
33
|
-
autoMinorVersionUpgrade: true,
|
|
34
|
-
maintenanceWindow: 'Mon:07:00-Mon:07:30',
|
|
35
|
-
finalSnapshotIdentifier: `${name}-final-snapshot`,
|
|
36
|
-
backupWindow: '06:00-06:30',
|
|
37
|
-
backupRetentionPeriod: 14,
|
|
38
|
-
}, { parent: this });
|
|
39
|
-
this.registerOutputs();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.Rds = Rds;
|