@studion/infra-code-blocks 0.1.0 → 0.1.2
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 +1 -6
- package/dist/components/acm-certificate.js +2 -1
- package/dist/components/database.js +6 -1
- package/dist/components/ec2-ssm-connect.js +7 -1
- package/dist/components/project.js +3 -0
- package/dist/components/redis.js +2 -0
- package/dist/components/static-site.js +3 -2
- package/dist/components/web-server.js +13 -3
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -500,9 +500,4 @@ const project = new studion.Project('demo-project', {
|
|
|
500
500
|
|
|
501
501
|
- [ ] Add worker service for executing tasks
|
|
502
502
|
- [ ] Add MongoDB service
|
|
503
|
-
- [
|
|
504
|
-
- [x] change db private subnet ids to isolated subnet ids
|
|
505
|
-
- [x] change default instance classes to t4g
|
|
506
|
-
- [x] extract ami images/ instance classes, etc...
|
|
507
|
-
- [x] remove duplicated types
|
|
508
|
-
- [ ] extract constructor code to private methods...
|
|
503
|
+
- [ ] Enable RDS password rotation
|
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AcmCertificate = void 0;
|
|
4
4
|
const pulumi = require("@pulumi/pulumi");
|
|
5
5
|
const aws = require("@pulumi/aws");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
class AcmCertificate extends pulumi.ComponentResource {
|
|
7
8
|
constructor(name, args, opts = {}) {
|
|
8
9
|
super('studion:acm:Certificate', name, {}, opts);
|
|
9
|
-
this.certificate = new aws.acm.Certificate(`${args.domain}-certificate`, { domainName: args.domain, validationMethod: 'DNS' }, { parent: this });
|
|
10
|
+
this.certificate = new aws.acm.Certificate(`${args.domain}-certificate`, { domainName: args.domain, validationMethod: 'DNS', tags: constants_1.commonTags }, { parent: this });
|
|
10
11
|
const certificateValidationDomain = new aws.route53.Record(`${args.domain}-cert-validation-domain`, {
|
|
11
12
|
name: this.certificate.domainValidationOptions[0].resourceRecordName,
|
|
12
13
|
type: this.certificate.domainValidationOptions[0].resourceRecordType,
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Database = void 0;
|
|
4
4
|
const aws = require("@pulumi/aws");
|
|
5
5
|
const pulumi = require("@pulumi/pulumi");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const defaults = {
|
|
7
8
|
applyImmediately: false,
|
|
8
9
|
skipFinalSnapshot: false,
|
|
@@ -25,6 +26,7 @@ class Database extends pulumi.ComponentResource {
|
|
|
25
26
|
createSubnetGroup({ vpc }) {
|
|
26
27
|
const dbSubnetGroup = new aws.rds.SubnetGroup(`${this.name}-subnet-group`, {
|
|
27
28
|
subnetIds: vpc.isolatedSubnetIds,
|
|
29
|
+
tags: constants_1.commonTags,
|
|
28
30
|
}, { parent: this });
|
|
29
31
|
return dbSubnetGroup;
|
|
30
32
|
}
|
|
@@ -39,6 +41,7 @@ class Database extends pulumi.ComponentResource {
|
|
|
39
41
|
cidrBlocks: [vpc.vpc.cidrBlock],
|
|
40
42
|
},
|
|
41
43
|
],
|
|
44
|
+
tags: constants_1.commonTags,
|
|
42
45
|
}, { parent: this });
|
|
43
46
|
return dbSecurityGroup;
|
|
44
47
|
}
|
|
@@ -50,6 +53,7 @@ class Database extends pulumi.ComponentResource {
|
|
|
50
53
|
keyUsage: 'ENCRYPT_DECRYPT',
|
|
51
54
|
multiRegion: false,
|
|
52
55
|
enableKeyRotation: true,
|
|
56
|
+
tags: constants_1.commonTags,
|
|
53
57
|
}, { parent: this });
|
|
54
58
|
return kms;
|
|
55
59
|
}
|
|
@@ -58,6 +62,7 @@ class Database extends pulumi.ComponentResource {
|
|
|
58
62
|
const stack = pulumi.getStack();
|
|
59
63
|
const passwordSecret = new aws.secretsmanager.Secret(`${this.name}-password-secret`, {
|
|
60
64
|
namePrefix: `${stack}/${project}/DatabasePassword-`,
|
|
65
|
+
tags: constants_1.commonTags,
|
|
61
66
|
}, { parent: this });
|
|
62
67
|
const passwordSecretValue = new aws.secretsmanager.SecretVersion(`${this.name}-password-secret-value`, {
|
|
63
68
|
secretId: passwordSecret.id,
|
|
@@ -89,7 +94,7 @@ class Database extends pulumi.ComponentResource {
|
|
|
89
94
|
finalSnapshotIdentifier: `${this.name}-final-snapshot`,
|
|
90
95
|
backupWindow: '06:00-06:30',
|
|
91
96
|
backupRetentionPeriod: 14,
|
|
92
|
-
tags: argsWithDefaults.tags,
|
|
97
|
+
tags: Object.assign(Object.assign({}, constants_1.commonTags), argsWithDefaults.tags),
|
|
93
98
|
}, { parent: this });
|
|
94
99
|
return instance;
|
|
95
100
|
}
|
|
@@ -29,6 +29,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
29
29
|
{ protocol: '-1', fromPort: 0, toPort: 0, cidrBlocks: ['0.0.0.0/0'] },
|
|
30
30
|
],
|
|
31
31
|
vpcId: args.vpc.vpcId,
|
|
32
|
+
tags: constants_1.commonTags,
|
|
32
33
|
}, { parent: this });
|
|
33
34
|
const role = new aws.iam.Role(`${name}-ec2-role`, {
|
|
34
35
|
assumeRolePolicy: {
|
|
@@ -43,6 +44,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
43
44
|
},
|
|
44
45
|
],
|
|
45
46
|
},
|
|
47
|
+
tags: constants_1.commonTags,
|
|
46
48
|
}, { parent: this });
|
|
47
49
|
const ssmPolicyAttachment = new aws.iam.RolePolicyAttachment(`${name}-ssm-policy-attachment`, {
|
|
48
50
|
role: role.name,
|
|
@@ -50,6 +52,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
50
52
|
}, { parent: this });
|
|
51
53
|
const ssmProfile = new aws.iam.InstanceProfile(`${name}-ssm-profile`, {
|
|
52
54
|
role: role.name,
|
|
55
|
+
tags: constants_1.commonTags,
|
|
53
56
|
}, { parent: this, dependsOn: [ssmPolicyAttachment] });
|
|
54
57
|
this.ec2 = new aws.ec2.Instance(`${name}-ec2`, {
|
|
55
58
|
ami: constants_1.Ec2AMI.AmazonLinux2023.ARM,
|
|
@@ -58,7 +61,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
58
61
|
iamInstanceProfile: ssmProfile.name,
|
|
59
62
|
subnetId,
|
|
60
63
|
vpcSecurityGroupIds: [this.ec2SecurityGroup.id],
|
|
61
|
-
tags: Object.assign({ Name: `${name}-ec2` }, args.tags),
|
|
64
|
+
tags: Object.assign(Object.assign(Object.assign({}, constants_1.commonTags), { Name: `${name}-ec2` }), args.tags),
|
|
62
65
|
}, { parent: this });
|
|
63
66
|
this.ssmVpcEndpoint = new aws.ec2.VpcEndpoint(`${name}-ssm-vpc-endpoint`, {
|
|
64
67
|
vpcId: args.vpc.vpcId,
|
|
@@ -68,6 +71,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
68
71
|
subnetIds: [subnetId],
|
|
69
72
|
securityGroupIds: [this.ec2SecurityGroup.id],
|
|
70
73
|
privateDnsEnabled: true,
|
|
74
|
+
tags: constants_1.commonTags,
|
|
71
75
|
}, { parent: this, dependsOn: [this.ec2] });
|
|
72
76
|
this.ec2MessagesVpcEndpoint = new aws.ec2.VpcEndpoint(`${name}-ec2messages-vpc-endpoint`, {
|
|
73
77
|
vpcId: args.vpc.vpcId,
|
|
@@ -77,6 +81,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
77
81
|
subnetIds: [subnetId],
|
|
78
82
|
securityGroupIds: [this.ec2SecurityGroup.id],
|
|
79
83
|
privateDnsEnabled: true,
|
|
84
|
+
tags: constants_1.commonTags,
|
|
80
85
|
}, { parent: this, dependsOn: [this.ec2] });
|
|
81
86
|
this.ssmMessagesVpcEndpoint = new aws.ec2.VpcEndpoint(`${name}-ssmmessages-vpc-endpoint`, {
|
|
82
87
|
vpcId: args.vpc.vpcId,
|
|
@@ -86,6 +91,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
86
91
|
subnetIds: [subnetId],
|
|
87
92
|
securityGroupIds: [this.ec2SecurityGroup.id],
|
|
88
93
|
privateDnsEnabled: true,
|
|
94
|
+
tags: constants_1.commonTags,
|
|
89
95
|
}, { parent: this, dependsOn: [this.ec2] });
|
|
90
96
|
this.registerOutputs();
|
|
91
97
|
}
|
|
@@ -21,6 +21,7 @@ const web_server_1 = require("./web-server");
|
|
|
21
21
|
const redis_1 = require("./redis");
|
|
22
22
|
const static_site_1 = require("./static-site");
|
|
23
23
|
const ec2_ssm_connect_1 = require("./ec2-ssm-connect");
|
|
24
|
+
const constants_1 = require("../constants");
|
|
24
25
|
class MissingHostedZoneId extends Error {
|
|
25
26
|
constructor(serviceType) {
|
|
26
27
|
super(`Project::hostedZoneId argument must be provided
|
|
@@ -55,6 +56,7 @@ class Project extends pulumi.ComponentResource {
|
|
|
55
56
|
{ type: awsx.ec2.SubnetType.Private, cidrMask: 24 },
|
|
56
57
|
{ type: awsx.ec2.SubnetType.Isolated, cidrMask: 24 },
|
|
57
58
|
],
|
|
59
|
+
tags: constants_1.commonTags,
|
|
58
60
|
}, { parent: this });
|
|
59
61
|
return vpc;
|
|
60
62
|
}
|
|
@@ -86,6 +88,7 @@ class Project extends pulumi.ComponentResource {
|
|
|
86
88
|
createWebServerPrerequisites() {
|
|
87
89
|
this.cluster = new aws.ecs.Cluster(`${this.name}-cluster`, {
|
|
88
90
|
name: this.name,
|
|
91
|
+
tags: constants_1.commonTags,
|
|
89
92
|
}, { parent: this });
|
|
90
93
|
}
|
|
91
94
|
createDatabaseService(options) {
|
package/dist/components/redis.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Redis = void 0;
|
|
|
4
4
|
const pulumi = require("@pulumi/pulumi");
|
|
5
5
|
const upstash = require("@upstash/pulumi");
|
|
6
6
|
const aws = require("@pulumi/aws");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
7
8
|
const defaults = {
|
|
8
9
|
region: 'us-east-1',
|
|
9
10
|
};
|
|
@@ -22,6 +23,7 @@ class Redis extends pulumi.ComponentResource {
|
|
|
22
23
|
}, { provider: opts.provider, parent: this });
|
|
23
24
|
this.passwordSecret = new aws.secretsmanager.Secret(`${name}-password-secret`, {
|
|
24
25
|
namePrefix: `${stack}/${project}/RedisPassword-`,
|
|
26
|
+
tags: constants_1.commonTags,
|
|
25
27
|
}, { parent: this, dependsOn: [this.instance] });
|
|
26
28
|
const passwordSecretValue = new aws.secretsmanager.SecretVersion(`${name}-password-secret-value`, {
|
|
27
29
|
secretId: this.passwordSecret.id,
|
|
@@ -4,6 +4,7 @@ exports.StaticSite = void 0;
|
|
|
4
4
|
const aws = require("@pulumi/aws");
|
|
5
5
|
const pulumi = require("@pulumi/pulumi");
|
|
6
6
|
const acm_certificate_1 = require("./acm-certificate");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
7
8
|
class StaticSite extends pulumi.ComponentResource {
|
|
8
9
|
constructor(name, args, opts = {}) {
|
|
9
10
|
super('studion:StaticSite', name, {}, opts);
|
|
@@ -29,7 +30,7 @@ class StaticSite extends pulumi.ComponentResource {
|
|
|
29
30
|
indexDocument: 'index.html',
|
|
30
31
|
errorDocument: 'index.html',
|
|
31
32
|
},
|
|
32
|
-
tags,
|
|
33
|
+
tags: Object.assign(Object.assign({}, constants_1.commonTags), tags),
|
|
33
34
|
}, { parent: this });
|
|
34
35
|
const bucketPublicAccessBlock = new aws.s3.BucketPublicAccessBlock(`${this.name}-bucket-access-block`, {
|
|
35
36
|
bucket: bucket.id,
|
|
@@ -102,7 +103,7 @@ class StaticSite extends pulumi.ComponentResource {
|
|
|
102
103
|
restrictions: {
|
|
103
104
|
geoRestriction: { restrictionType: 'none' },
|
|
104
105
|
},
|
|
105
|
-
tags,
|
|
106
|
+
tags: Object.assign(Object.assign({}, constants_1.commonTags), tags),
|
|
106
107
|
}, { parent: this });
|
|
107
108
|
return cloudfront;
|
|
108
109
|
}
|
|
@@ -61,6 +61,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
61
61
|
const logGroup = new aws.cloudwatch.LogGroup(`${this.name}-log-group`, {
|
|
62
62
|
retentionInDays: 14,
|
|
63
63
|
namePrefix: `/ecs/${this.name}-`,
|
|
64
|
+
tags: constants_1.commonTags,
|
|
64
65
|
}, { parent: this });
|
|
65
66
|
return logGroup;
|
|
66
67
|
}
|
|
@@ -89,6 +90,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
89
90
|
cidrBlocks: ['0.0.0.0/0'],
|
|
90
91
|
},
|
|
91
92
|
],
|
|
93
|
+
tags: constants_1.commonTags,
|
|
92
94
|
}, { parent: this });
|
|
93
95
|
const lb = new aws.lb.LoadBalancer(`${this.name}-lb`, {
|
|
94
96
|
namePrefix: `${this.name}-lb-`,
|
|
@@ -97,9 +99,10 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
97
99
|
securityGroups: [lbSecurityGroup.id],
|
|
98
100
|
internal: false,
|
|
99
101
|
ipAddressType: 'ipv4',
|
|
102
|
+
tags: constants_1.commonTags,
|
|
100
103
|
}, { parent: this });
|
|
101
104
|
const lbTargetGroup = new aws.lb.TargetGroup(`${this.name}-lb-tg`, {
|
|
102
|
-
namePrefix:
|
|
105
|
+
namePrefix: 'lb-tg-',
|
|
103
106
|
port,
|
|
104
107
|
protocol: 'HTTP',
|
|
105
108
|
targetType: 'ip',
|
|
@@ -111,6 +114,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
111
114
|
timeout: 5,
|
|
112
115
|
path: healtCheckPath || defaults.healtCheckPath,
|
|
113
116
|
},
|
|
117
|
+
tags: Object.assign(Object.assign({}, constants_1.commonTags), { Name: `${this.name}-lb-target-group` }),
|
|
114
118
|
}, { parent: this, dependsOn: [this.lb] });
|
|
115
119
|
const lbHttpListener = new aws.lb.Listener(`${this.name}-lb-listener-80`, {
|
|
116
120
|
loadBalancerArn: this.lb.arn,
|
|
@@ -125,6 +129,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
125
129
|
},
|
|
126
130
|
},
|
|
127
131
|
],
|
|
132
|
+
tags: constants_1.commonTags,
|
|
128
133
|
}, { parent: this });
|
|
129
134
|
const lbTlsListener = new aws.lb.Listener(`${this.name}-lb-listener-443`, {
|
|
130
135
|
loadBalancerArn: this.lb.arn,
|
|
@@ -138,6 +143,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
138
143
|
targetGroupArn: this.lbTargetGroup.arn,
|
|
139
144
|
},
|
|
140
145
|
],
|
|
146
|
+
tags: constants_1.commonTags,
|
|
141
147
|
}, { parent: this });
|
|
142
148
|
return {
|
|
143
149
|
lb,
|
|
@@ -174,6 +180,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
174
180
|
secretManagerSecretsInlinePolicy,
|
|
175
181
|
...argsWithDefaults.taskExecutionRoleInlinePolicies,
|
|
176
182
|
],
|
|
183
|
+
tags: constants_1.commonTags,
|
|
177
184
|
}, { parent: this });
|
|
178
185
|
const execCmdInlinePolicy = {
|
|
179
186
|
name: `${this.name}-ecs-exec`,
|
|
@@ -201,6 +208,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
201
208
|
execCmdInlinePolicy,
|
|
202
209
|
...argsWithDefaults.taskRoleInlinePolicies,
|
|
203
210
|
],
|
|
211
|
+
tags: constants_1.commonTags,
|
|
204
212
|
}, { parent: this });
|
|
205
213
|
const parsedSize = pulumi.all([argsWithDefaults.size]).apply(([size]) => {
|
|
206
214
|
const mapCapabilities = ({ cpu, memory }) => ({
|
|
@@ -259,7 +267,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
259
267
|
},
|
|
260
268
|
]);
|
|
261
269
|
}),
|
|
262
|
-
tags: argsWithDefaults.tags,
|
|
270
|
+
tags: Object.assign(Object.assign({}, constants_1.commonTags), argsWithDefaults.tags),
|
|
263
271
|
}, { parent: this });
|
|
264
272
|
return taskDefinition;
|
|
265
273
|
}
|
|
@@ -283,6 +291,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
283
291
|
cidrBlocks: ['0.0.0.0/0'],
|
|
284
292
|
},
|
|
285
293
|
],
|
|
294
|
+
tags: constants_1.commonTags,
|
|
286
295
|
}, { parent: this });
|
|
287
296
|
const service = new aws.ecs.Service(`${this.name}-service`, {
|
|
288
297
|
name: this.name,
|
|
@@ -303,7 +312,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
303
312
|
subnets: argsWithDefaults.vpc.publicSubnetIds,
|
|
304
313
|
securityGroups: [serviceSecurityGroup.id],
|
|
305
314
|
},
|
|
306
|
-
tags: argsWithDefaults.tags,
|
|
315
|
+
tags: Object.assign(Object.assign({}, constants_1.commonTags), argsWithDefaults.tags),
|
|
307
316
|
}, {
|
|
308
317
|
parent: this,
|
|
309
318
|
dependsOn: [
|
|
@@ -337,6 +346,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
337
346
|
resourceId: pulumi.interpolate `service/${argsWithDefaults.cluster.name}/${this.service.name}`,
|
|
338
347
|
serviceNamespace: 'ecs',
|
|
339
348
|
scalableDimension: 'ecs:service:DesiredCount',
|
|
349
|
+
tags: constants_1.commonTags,
|
|
340
350
|
}, { parent: this });
|
|
341
351
|
const memoryAutoscalingPolicy = new aws.appautoscaling.Policy(`${this.name}-memory-autoscale-policy`, {
|
|
342
352
|
policyType: 'TargetTrackingScaling',
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Ec2AMI = exports.PredefinedSize = void 0;
|
|
3
|
+
exports.commonTags = exports.Ec2AMI = exports.PredefinedSize = void 0;
|
|
4
|
+
const pulumi = require("@pulumi/pulumi");
|
|
4
5
|
const CPU_1_VCPU = 1024;
|
|
5
6
|
const MEMORY_1GB = 1024;
|
|
6
7
|
exports.PredefinedSize = {
|
|
@@ -26,3 +27,7 @@ exports.Ec2AMI = {
|
|
|
26
27
|
ARM: 'ami-0b40baa8c6b882e6c',
|
|
27
28
|
},
|
|
28
29
|
};
|
|
30
|
+
exports.commonTags = {
|
|
31
|
+
Env: pulumi.getStack(),
|
|
32
|
+
Project: pulumi.getProject(),
|
|
33
|
+
};
|