@studion/infra-code-blocks 0.0.2 → 0.0.3

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.
@@ -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;
@@ -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
- }
@@ -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;