terruvim-core-test 0.0.1

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.
Files changed (199) hide show
  1. package/dist/src/core/config.js +2 -0
  2. package/dist/src/core/configMerge.js +266 -0
  3. package/dist/src/core/configUtils.js +72 -0
  4. package/dist/src/core/dependencyResolver.js +17 -0
  5. package/dist/src/core/deployUtils.js +73 -0
  6. package/dist/src/core/dynamicResourceManager.js +709 -0
  7. package/dist/src/core/entrypoint.js +56 -0
  8. package/dist/src/core/generateFinalConfig.js +45 -0
  9. package/dist/src/core/index.js +24 -0
  10. package/dist/src/core/resourceMap.js +99 -0
  11. package/dist/src/factories/accountPermissions.js +134 -0
  12. package/dist/src/factories/acmFactory.js +30 -0
  13. package/dist/src/factories/albFactory.js +331 -0
  14. package/dist/src/factories/attachSecretAccessPolicy.js +56 -0
  15. package/dist/src/factories/auroraFactory.js +619 -0
  16. package/dist/src/factories/backupPolicy.js +152 -0
  17. package/dist/src/factories/bastionFactory.js +91 -0
  18. package/dist/src/factories/bedrockFactory.js +334 -0
  19. package/dist/src/factories/budgetFactory.js +64 -0
  20. package/dist/src/factories/buildAlbCloudWatchAlarmsHelper.js +79 -0
  21. package/dist/src/factories/buildAlbCloudWatchDashboardHelper.js +106 -0
  22. package/dist/src/factories/buildAlbListenerRulesHelper.js +45 -0
  23. package/dist/src/factories/buildAlbListenersHelper.js +64 -0
  24. package/dist/src/factories/buildAlbResourceHelper.js +54 -0
  25. package/dist/src/factories/buildAlbRoute53RecordHelper.js +49 -0
  26. package/dist/src/factories/buildAlbTargetGroupsHelper.js +47 -0
  27. package/dist/src/factories/buildAlbWafAssociationHelper.js +43 -0
  28. package/dist/src/factories/buildAndPushDockerImage.js +57 -0
  29. package/dist/src/factories/buildAwsCloudWatchAlarmsHelper.js +118 -0
  30. package/dist/src/factories/buildCloudFrontRoute53RecordHelper.js +49 -0
  31. package/dist/src/factories/buildEcsClusterArgs.js +32 -0
  32. package/dist/src/factories/buildEcsSecrets.js +48 -0
  33. package/dist/src/factories/buildForceRedeployEnv.js +8 -0
  34. package/dist/src/factories/buildResourceOptions.js +11 -0
  35. package/dist/src/factories/buildS3StaticHostingCicdHelper.js +142 -0
  36. package/dist/src/factories/buildS3StaticHostingCloudWatchDashboardHelper.js +122 -0
  37. package/dist/src/factories/cloudTrailFactory.js +22 -0
  38. package/dist/src/factories/cloudWatchCompositeAlarmFactory.js +91 -0
  39. package/dist/src/factories/cloudWatchInsightsQueryFactory.js +83 -0
  40. package/dist/src/factories/cloudWatchLogGroupFactory.js +84 -0
  41. package/dist/src/factories/cloudfrontCodePipelineFactory.js +357 -0
  42. package/dist/src/factories/cloudwatchAlarmsFactory.js +121 -0
  43. package/dist/src/factories/codePipelineNotificationFactory.js +193 -0
  44. package/dist/src/factories/codePipelineNotificationRulesFactory.js +117 -0
  45. package/dist/src/factories/codeStarConnectionFactory.js +56 -0
  46. package/dist/src/factories/collectSecretKeys.js +18 -0
  47. package/dist/src/factories/comprehensiveNotificationFactory.js +250 -0
  48. package/dist/src/factories/costAndUsageReportFactory.js +32 -0
  49. package/dist/src/factories/createAwsAcmCertificate.js +40 -0
  50. package/dist/src/factories/createAwsBudget.js +40 -0
  51. package/dist/src/factories/createAwsCloudTrail.js +59 -0
  52. package/dist/src/factories/createAwsCloudwatchDashboard.js +59 -0
  53. package/dist/src/factories/createAwsEc2Instance.js +40 -0
  54. package/dist/src/factories/createAwsEventBridgeEventBus.js +40 -0
  55. package/dist/src/factories/createAwsGuardDutyDetector.js +40 -0
  56. package/dist/src/factories/createAwsGuardDutyDetectorFeature.js +45 -0
  57. package/dist/src/factories/createAwsGuardDutyFilter.js +46 -0
  58. package/dist/src/factories/createAwsGuardDutyPublishingDestination.js +50 -0
  59. package/dist/src/factories/createAwsHostedZone.js +40 -0
  60. package/dist/src/factories/createAwsIamRole.js +49 -0
  61. package/dist/src/factories/createAwsIamRoleInlinePolicies.js +48 -0
  62. package/dist/src/factories/createAwsIdentitystoreGroup.js +44 -0
  63. package/dist/src/factories/createAwsIdentitystoreGroupMembership.js +56 -0
  64. package/dist/src/factories/createAwsIdentitystoreUser.js +47 -0
  65. package/dist/src/factories/createAwsInspectorAssessmentTarget.js +47 -0
  66. package/dist/src/factories/createAwsInspectorDelegatedAdminAccount.js +47 -0
  67. package/dist/src/factories/createAwsInspectorEnabler.js +49 -0
  68. package/dist/src/factories/createAwsInspectorOrganizationConfiguration.js +55 -0
  69. package/dist/src/factories/createAwsKmsAliases.js +47 -0
  70. package/dist/src/factories/createAwsKmsKey.js +51 -0
  71. package/dist/src/factories/createAwsMacieAccount.js +45 -0
  72. package/dist/src/factories/createAwsMacieClassificationJob.js +53 -0
  73. package/dist/src/factories/createAwsMacieMember.js +49 -0
  74. package/dist/src/factories/createAwsMacieOrganizationConfiguration.js +44 -0
  75. package/dist/src/factories/createAwsRdsCluster.js +40 -0
  76. package/dist/src/factories/createAwsRdsClusterInstance.js +40 -0
  77. package/dist/src/factories/createAwsRdsInstance.js +40 -0
  78. package/dist/src/factories/createAwsRdsSubnetGroup.js +40 -0
  79. package/dist/src/factories/createAwsRoute53Record.js +40 -0
  80. package/dist/src/factories/createAwsSecret.js +40 -0
  81. package/dist/src/factories/createAwsSecretRotation.js +40 -0
  82. package/dist/src/factories/createAwsSecretVersion.js +40 -0
  83. package/dist/src/factories/createAwsSecurityGroup.js +40 -0
  84. package/dist/src/factories/createAwsSecurityGroupRule.js +40 -0
  85. package/dist/src/factories/createAwsSecurityHubAccount.js +40 -0
  86. package/dist/src/factories/createAwsSecurityHubAutomationRule.js +48 -0
  87. package/dist/src/factories/createAwsSecurityHubStandardsControl.js +44 -0
  88. package/dist/src/factories/createAwsSecurityHubStandardsSubscription.js +42 -0
  89. package/dist/src/factories/createAwsSesDomainDkim.js +40 -0
  90. package/dist/src/factories/createAwsSesDomainIdentity.js +40 -0
  91. package/dist/src/factories/createAwsSesEmailIdentity.js +40 -0
  92. package/dist/src/factories/createAwsSnsSubscription.js +62 -0
  93. package/dist/src/factories/createAwsSnsTopic.js +41 -0
  94. package/dist/src/factories/createAwsSqsQueue.js +40 -0
  95. package/dist/src/factories/createAwsSsmParameters.js +66 -0
  96. package/dist/src/factories/createAwsSsoAccountAssignment.js +66 -0
  97. package/dist/src/factories/createAwsSsoPermissionSet.js +64 -0
  98. package/dist/src/factories/createAwsStepFunctionsStateMachine.js +40 -0
  99. package/dist/src/factories/createBudget.js +56 -0
  100. package/dist/src/factories/createBudgetWithSnsAlert.js +79 -0
  101. package/dist/src/factories/createCostAndUsageReport.js +40 -0
  102. package/dist/src/factories/createEcrRepo.js +69 -0
  103. package/dist/src/factories/createEcsRolesAndPolicies.js +84 -0
  104. package/dist/src/factories/createEcsService.js +71 -0
  105. package/dist/src/factories/createEnvSecret.js +60 -0
  106. package/dist/src/factories/createGithubCodeStarConnection.js +44 -0
  107. package/dist/src/factories/createIamUserWithAccessKey.js +44 -0
  108. package/dist/src/factories/createLambdaFunction.js +89 -0
  109. package/dist/src/factories/createLambdaPermission.js +57 -0
  110. package/dist/src/factories/createListenerRule.js +68 -0
  111. package/dist/src/factories/createLogGroup.js +44 -0
  112. package/dist/src/factories/createSlackChannelConfiguration.js +49 -0
  113. package/dist/src/factories/createTargetGroup.js +50 -0
  114. package/dist/src/factories/createTaskDefinition.js +49 -0
  115. package/dist/src/factories/createVpcEndpoint.js +49 -0
  116. package/dist/src/factories/dashboardFactory.js +94 -0
  117. package/dist/src/factories/dataProtectionPolicyBuilder.js +103 -0
  118. package/dist/src/factories/ec2Factory.js +67 -0
  119. package/dist/src/factories/ecsClusterFactory.js +90 -0
  120. package/dist/src/factories/ecsCodePipelineFactory.js +308 -0
  121. package/dist/src/factories/ecsServiceFactory.js +350 -0
  122. package/dist/src/factories/enhancedCloudFrontCodePipelineFactory.js +205 -0
  123. package/dist/src/factories/enhancedEcsCodePipelineFactory.js +189 -0
  124. package/dist/src/factories/eventBridgeBusFactory.js +84 -0
  125. package/dist/src/factories/eventBridgeFactory.js +26 -0
  126. package/dist/src/factories/eventBridgeRuleFactory.js +114 -0
  127. package/dist/src/factories/fetchAllSecrets.js +51 -0
  128. package/dist/src/factories/getDeterministicPriority.js +13 -0
  129. package/dist/src/factories/getOrCreateSshKeyPair.js +57 -0
  130. package/dist/src/factories/guardDutyFactory.js +151 -0
  131. package/dist/src/factories/hostedZoneFactory.js +30 -0
  132. package/dist/src/factories/iamRoleFactory.js +29 -0
  133. package/dist/src/factories/inspectorFactory.js +109 -0
  134. package/dist/src/factories/kmsKeyFactory.js +32 -0
  135. package/dist/src/factories/lambdaFactory.js +133 -0
  136. package/dist/src/factories/lambdaPermissionFactory.js +32 -0
  137. package/dist/src/factories/logDataProtectionPolicyFactory.js +81 -0
  138. package/dist/src/factories/macieFactory.js +85 -0
  139. package/dist/src/factories/networkingFactory.js +429 -0
  140. package/dist/src/factories/opensearchCollectionFactory.js +109 -0
  141. package/dist/src/factories/organizationFactory.js +221 -0
  142. package/dist/src/factories/processReservedInstances.js +6 -0
  143. package/dist/src/factories/processSavingsPlans.js +43 -0
  144. package/dist/src/factories/rdsFactory.js +40 -0
  145. package/dist/src/factories/recordFactory.js +36 -0
  146. package/dist/src/factories/resolveEnvSecrets.js +14 -0
  147. package/dist/src/factories/resourceFactory.js +12 -0
  148. package/dist/src/factories/s3Factory.js +262 -0
  149. package/dist/src/factories/s3StaticHostingFactory.backup.js +424 -0
  150. package/dist/src/factories/s3StaticHostingFactory.js +348 -0
  151. package/dist/src/factories/s3StaticHostingFactory.refactored.js +334 -0
  152. package/dist/src/factories/savingsPlanFactory.js +26 -0
  153. package/dist/src/factories/secretsManagerFactory.js +107 -0
  154. package/dist/src/factories/securityGroupFactory.js +28 -0
  155. package/dist/src/factories/securityGroupRuleFactory.js +43 -0
  156. package/dist/src/factories/securityHubFactory.js +96 -0
  157. package/dist/src/factories/sesDomainDkimFactory.js +25 -0
  158. package/dist/src/factories/sesFactory.js +25 -0
  159. package/dist/src/factories/sesIdentitiesFactory.js +134 -0
  160. package/dist/src/factories/simpleNotificationFactory.js +112 -0
  161. package/dist/src/factories/smtpUserFactory.js +108 -0
  162. package/dist/src/factories/snsFactory.js +87 -0
  163. package/dist/src/factories/sqsFactory.js +41 -0
  164. package/dist/src/factories/ssmParameterFactory.js +67 -0
  165. package/dist/src/factories/ssoFactory.js +32 -0
  166. package/dist/src/factories/ssoGroupFactory.js +41 -0
  167. package/dist/src/factories/ssoPermissionSetFactory.js +29 -0
  168. package/dist/src/factories/ssoUserFactory.js +30 -0
  169. package/dist/src/factories/stepFunctionsFactory.js +32 -0
  170. package/dist/src/factories/tagPolicies.js +99 -0
  171. package/dist/src/factories/transformBudgetCostFilters.js +8 -0
  172. package/dist/src/factories/transformBudgetNotifications.js +12 -0
  173. package/dist/src/factories/transformBudgetPlannedLimits.js +8 -0
  174. package/dist/src/factories/types.js +2 -0
  175. package/dist/src/factories/validateAcmConfig.js +26 -0
  176. package/dist/src/factories/validateAuroraConfig.js +8 -0
  177. package/dist/src/factories/validateBedrockConfig.js +124 -0
  178. package/dist/src/factories/validateDashboardConfig.js +28 -0
  179. package/dist/src/factories/validateEventBridgeConfig.js +14 -0
  180. package/dist/src/factories/validateHostedZoneConfig.js +26 -0
  181. package/dist/src/factories/validateIamRoleConfig.js +8 -0
  182. package/dist/src/factories/validateKmsKeyConfig.js +8 -0
  183. package/dist/src/factories/validateRdsConfig.js +17 -0
  184. package/dist/src/factories/validateRoute53RecordConfig.js +41 -0
  185. package/dist/src/factories/validateS3Config.js +8 -0
  186. package/dist/src/factories/validateSecretsManagerConfig.js +8 -0
  187. package/dist/src/factories/validateSecurityGroupConfig.js +8 -0
  188. package/dist/src/factories/validateSecurityGroupRuleConfig.js +8 -0
  189. package/dist/src/factories/validateSesDomainDkimConfig.js +8 -0
  190. package/dist/src/factories/validateSesDomainIdentityConfig.js +8 -0
  191. package/dist/src/factories/validateSesIdentitiesConfig.js +40 -0
  192. package/dist/src/factories/validateSnsConfig.js +11 -0
  193. package/dist/src/factories/validateSqsConfig.js +11 -0
  194. package/dist/src/factories/validateSsmParameterFactoryConfig.js +9 -0
  195. package/dist/src/factories/validateStepFunctionsConfig.js +8 -0
  196. package/dist/src/factories/vpcEndpointFactory.js +98 -0
  197. package/dist/src/factories/wafFactory.js +499 -0
  198. package/package.json +71 -0
  199. package/scripts/copy-assets.js +136 -0
@@ -0,0 +1,308 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ECSCodePipelineFactory = void 0;
37
+ const aws = __importStar(require("@pulumi/aws"));
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const resourceFactory_1 = require("./resourceFactory");
41
+ class ECSCodePipelineFactory extends resourceFactory_1.ResourceFactory {
42
+ createPipelinePolicyDoc(config) {
43
+ return JSON.stringify({
44
+ Version: "2012-10-17",
45
+ Statement: [
46
+ {
47
+ Effect: "Allow",
48
+ Action: [
49
+ "ec2:*",
50
+ "elasticloadbalancing:*",
51
+ "autoscaling:*",
52
+ "cloudwatch:*",
53
+ "s3:*",
54
+ "sns:*",
55
+ "cloudformation:*",
56
+ "rds:*",
57
+ "sqs:*",
58
+ "ecs:*",
59
+ "iam:PassRole",
60
+ "codebuild:*",
61
+ "codestar-connections:UseConnection"
62
+ ],
63
+ Resource: "*"
64
+ }
65
+ ]
66
+ });
67
+ }
68
+ async createResource(config, provider) {
69
+ const { configuration } = config;
70
+ const environment = config.meta?.environment || 'dev';
71
+ const resourceId = config.id || 'pipeline';
72
+ const codebuildRole = new aws.iam.Role(`${environment}-${resourceId}-codebuild-role`, {
73
+ assumeRolePolicy: JSON.stringify({
74
+ Version: "2012-10-17",
75
+ Statement: [
76
+ {
77
+ Effect: "Allow",
78
+ Principal: { Service: "codebuild.amazonaws.com" },
79
+ Action: "sts:AssumeRole"
80
+ }
81
+ ]
82
+ }),
83
+ tags: configuration.tags,
84
+ }, provider ? { provider } : undefined);
85
+ const codebuildPolicy = new aws.iam.Policy(`${environment}-${resourceId}-codebuild-policy`, {
86
+ description: "Minimal policy for CodeBuild project",
87
+ policy: JSON.stringify({
88
+ Version: "2012-10-17",
89
+ Statement: [
90
+ {
91
+ Effect: "Allow",
92
+ Action: [
93
+ "logs:*",
94
+ "s3:*",
95
+ "codebuild:*",
96
+ "ecr:*",
97
+ "ecs:*",
98
+ "iam:PassRole",
99
+ "ec2:DescribeSecurityGroups",
100
+ "ec2:DescribeSubnets",
101
+ "ec2:DescribeVpcs",
102
+ "ec2:DescribeNetworkInterfaces",
103
+ "ec2:CreateNetworkInterface",
104
+ "ec2:DeleteNetworkInterface",
105
+ "ec2:DescribeDhcpOptions",
106
+ "ec2:*",
107
+ "*"
108
+ ],
109
+ Resource: "*"
110
+ }
111
+ ]
112
+ })
113
+ }, provider ? { provider } : undefined);
114
+ new aws.iam.RolePolicyAttachment(`${environment}-${resourceId}-codebuild-policy-attach`, {
115
+ role: codebuildRole.name,
116
+ policyArn: codebuildPolicy.arn
117
+ }, provider ? { provider } : undefined);
118
+ const pipelineRole = new aws.iam.Role(`${environment}-${resourceId}-pipeline-role`, {
119
+ assumeRolePolicy: JSON.stringify({
120
+ Version: "2012-10-17",
121
+ Statement: [
122
+ {
123
+ Effect: "Allow",
124
+ Principal: { Service: "codepipeline.amazonaws.com" },
125
+ Action: "sts:AssumeRole"
126
+ }
127
+ ]
128
+ }),
129
+ tags: configuration.tags,
130
+ }, provider ? { provider } : undefined);
131
+ const pipelinePolicy = new aws.iam.Policy(`${environment}-${resourceId}-pipeline-policy`, {
132
+ description: "Minimal policy for CodePipeline",
133
+ policy: this.createPipelinePolicyDoc(config)
134
+ }, provider ? { provider } : undefined);
135
+ new aws.iam.RolePolicyAttachment(`${environment}-${resourceId}-pipeline-policy-attach`, {
136
+ role: pipelineRole.name,
137
+ policyArn: pipelinePolicy.arn
138
+ }, provider ? { provider } : undefined);
139
+ const artifactBucket = new aws.s3.Bucket(`${environment}-${resourceId}-artifacts`, {
140
+ forceDestroy: configuration.s3BucketForceDestroy ?? true,
141
+ tags: configuration.tags,
142
+ }, provider ? { provider } : undefined);
143
+ let buildspec = undefined;
144
+ if (configuration.buildspecPath) {
145
+ const buildspecPath = configuration.buildspecPath;
146
+ const isExternal = path.isAbsolute(buildspecPath) || buildspecPath.startsWith("../") || buildspecPath.includes("/assets/cicd/buildspecs/");
147
+ if (isExternal) {
148
+ try {
149
+ buildspec = fs.readFileSync(buildspecPath, "utf8");
150
+ }
151
+ catch (e) {
152
+ throw new Error(`Failed to read external buildspec at ${buildspecPath}: ${e}`);
153
+ }
154
+ }
155
+ else {
156
+ buildspec = buildspecPath;
157
+ }
158
+ }
159
+ else {
160
+ buildspec = "buildspec.yml";
161
+ }
162
+ let vpcConfig = undefined;
163
+ if (configuration.deployCodePipelineInVpc && config.inputs?.vpcId) {
164
+ vpcConfig = {
165
+ vpcId: config.inputs.vpcId,
166
+ subnets: config.inputs.subnetIds,
167
+ securityGroupIds: config.inputs.securityGroupIds,
168
+ };
169
+ }
170
+ const codebuildProject = new aws.codebuild.Project(`${environment}-${resourceId}-build`, {
171
+ source: {
172
+ type: "CODEPIPELINE",
173
+ buildspec,
174
+ },
175
+ artifacts: {
176
+ type: "CODEPIPELINE",
177
+ },
178
+ environment: {
179
+ computeType: configuration.computeType || "BUILD_GENERAL1_LARGE",
180
+ image: configuration.buildImage || "aws/codebuild/amazonlinux2-x86_64-standard:4.0",
181
+ type: configuration.environmentType || "LINUX_CONTAINER",
182
+ privilegedMode: configuration.privilegedMode || false,
183
+ environmentVariables: configuration.buildEnvironmentVariables,
184
+ },
185
+ serviceRole: codebuildRole.arn,
186
+ tags: configuration.tags,
187
+ vpcConfig,
188
+ }, provider ? { provider } : undefined);
189
+ const sourceAction = {
190
+ name: "Source",
191
+ category: "Source",
192
+ owner: "AWS",
193
+ provider: "CodeStarSourceConnection",
194
+ version: "1",
195
+ outputArtifacts: ["source_output"],
196
+ configuration: {
197
+ ConnectionArn: configuration.codestarConnectionArn,
198
+ FullRepositoryId: `${configuration.repoOwner}/${configuration.repoName}`,
199
+ BranchName: configuration.branch,
200
+ DetectChanges: configuration.pollSourceChanges ? "true" : "false",
201
+ OutputArtifactFormat: configuration.outputArtifactFormat ?? "CODEBUILD_CLONE_REF",
202
+ },
203
+ };
204
+ const checkoutStage = {
205
+ name: "Checkout",
206
+ actions: [sourceAction],
207
+ };
208
+ const buildAction = {
209
+ name: "Build",
210
+ category: "Build",
211
+ owner: "AWS",
212
+ provider: "CodeBuild",
213
+ inputArtifacts: ["source_output"],
214
+ outputArtifacts: ["build_output"],
215
+ version: "1",
216
+ configuration: {
217
+ ProjectName: codebuildProject.name,
218
+ },
219
+ };
220
+ const buildStage = {
221
+ name: "Build",
222
+ actions: [buildAction],
223
+ };
224
+ let deployAction;
225
+ if (configuration.ecsClusterName && configuration.ecsServiceName) {
226
+ deployAction = {
227
+ name: "Deploy",
228
+ category: "Deploy",
229
+ owner: "AWS",
230
+ provider: "ECS",
231
+ inputArtifacts: ["build_output"],
232
+ version: "1",
233
+ configuration: {
234
+ ClusterName: configuration.ecsClusterName,
235
+ ServiceName: configuration.ecsServiceName,
236
+ },
237
+ runOrder: 1,
238
+ };
239
+ }
240
+ else {
241
+ deployAction = {
242
+ name: "Deploy",
243
+ category: "Deploy",
244
+ owner: "AWS",
245
+ provider: "CloudFormation",
246
+ inputArtifacts: ["build_output"],
247
+ version: "1",
248
+ configuration: {
249
+ ActionMode: "CHANGE_SET_REPLACE",
250
+ StackName: `${environment}-${resourceId}-stack`,
251
+ Capabilities: "CAPABILITY_NAMED_IAM",
252
+ TemplatePath: "build_output::template.yaml",
253
+ },
254
+ runOrder: 1,
255
+ };
256
+ }
257
+ const deployStage = {
258
+ name: "Deploy",
259
+ actions: [deployAction],
260
+ };
261
+ const stages = configuration.stages && configuration.stages.length > 0
262
+ ? configuration.stages
263
+ : [checkoutStage, buildStage, deployStage];
264
+ const pipeline = new aws.codepipeline.Pipeline(`${environment}-${resourceId}-pipeline`, {
265
+ roleArn: pipelineRole.arn,
266
+ artifactStores: [{
267
+ location: artifactBucket.bucket,
268
+ type: "S3"
269
+ }],
270
+ stages,
271
+ tags: configuration.tags,
272
+ name: `${environment}-${resourceId}`,
273
+ }, provider ? { provider } : undefined);
274
+ let webhook;
275
+ if (configuration.webhookEnabled) {
276
+ const webhookConfig = configuration.webhookConfig || {};
277
+ webhook = new aws.codepipeline.Webhook(`${environment}-${resourceId}-webhook`, {
278
+ authentication: webhookConfig.authentication || "GITHUB_HMAC",
279
+ targetAction: webhookConfig.targetAction || "Source",
280
+ targetPipeline: `${environment}-${resourceId}-pipeline`,
281
+ authenticationConfiguration: webhookConfig.secretToken ? {
282
+ secretToken: webhookConfig.secretToken,
283
+ } : undefined,
284
+ filters: [
285
+ {
286
+ jsonPath: webhookConfig.filterJsonPath || "$.ref",
287
+ matchEquals: webhookConfig.filterMatchEquals || `refs/heads/${configuration.branch}`,
288
+ },
289
+ ],
290
+ }, provider ? { provider } : undefined);
291
+ }
292
+ return pipeline;
293
+ }
294
+ getOutputs(resource) {
295
+ const region = resource.region || resource.location || "us-east-1";
296
+ return {
297
+ arn: resource.arn,
298
+ name: resource.name,
299
+ url: `https://${region}.console.aws.amazon.com/codesuite/codepipeline/pipelines/${resource.name}/view?region=${region}`,
300
+ };
301
+ }
302
+ validateConfig(config) {
303
+ if (!config.configuration || !config.configuration.repoOwner || !config.configuration.repoName || !config.configuration.branch || !config.configuration.codestarConnectionArn) {
304
+ throw new Error("CodePipeline config must include repoOwner, repoName, branch, codestarConnectionArn");
305
+ }
306
+ }
307
+ }
308
+ exports.ECSCodePipelineFactory = ECSCodePipelineFactory;
@@ -0,0 +1,350 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ServiceFactory = void 0;
37
+ const aws = __importStar(require("@pulumi/aws"));
38
+ const pulumi = __importStar(require("@pulumi/pulumi"));
39
+ const resourceFactory_1 = require("./resourceFactory");
40
+ const getDeterministicPriority_1 = require("./getDeterministicPriority");
41
+ const buildForceRedeployEnv_1 = require("./buildForceRedeployEnv");
42
+ const collectSecretKeys_1 = require("./collectSecretKeys");
43
+ const fetchAllSecrets_1 = require("./fetchAllSecrets");
44
+ const resolveEnvSecrets_1 = require("./resolveEnvSecrets");
45
+ const createEnvSecret_1 = require("./createEnvSecret");
46
+ const buildEcsSecrets_1 = require("./buildEcsSecrets");
47
+ const createEcsRolesAndPolicies_1 = require("./createEcsRolesAndPolicies");
48
+ const createTaskDefinition_1 = require("./createTaskDefinition");
49
+ const createEcsService_1 = require("./createEcsService");
50
+ const buildAndPushDockerImage_1 = require("./buildAndPushDockerImage");
51
+ const attachSecretAccessPolicy_1 = require("./attachSecretAccessPolicy");
52
+ const createLogGroup_1 = require("./createLogGroup");
53
+ const createEcrRepo_1 = require("./createEcrRepo");
54
+ const createTargetGroup_1 = require("./createTargetGroup");
55
+ const createListenerRule_1 = require("./createListenerRule");
56
+ const dataProtectionPolicyBuilder_1 = require("./dataProtectionPolicyBuilder");
57
+ function createAutoScaling(service, clusterName, autoScalingConfig, resourceNamePrefix, provider) {
58
+ const resourceId = pulumi.interpolate `service/${clusterName}/${service.name}`;
59
+ const targetResourceName = `${resourceNamePrefix}-autoscaling-target`;
60
+ const scalingTarget = new aws.appautoscaling.Target(targetResourceName, {
61
+ maxCapacity: autoScalingConfig.maxCapacity || 10,
62
+ minCapacity: autoScalingConfig.minCapacity || 1,
63
+ resourceId: resourceId,
64
+ scalableDimension: "ecs:service:DesiredCount",
65
+ serviceNamespace: "ecs",
66
+ }, { provider, dependsOn: [service] });
67
+ const policies = [];
68
+ if (autoScalingConfig.targetCPUUtilization) {
69
+ const cpuPolicyResourceName = `${resourceNamePrefix}-cpu-scaling-policy`;
70
+ const cpuPolicy = new aws.appautoscaling.Policy(cpuPolicyResourceName, {
71
+ name: `${resourceNamePrefix}-cpu-scaling`,
72
+ policyType: "TargetTrackingScaling",
73
+ resourceId: resourceId,
74
+ scalableDimension: "ecs:service:DesiredCount",
75
+ serviceNamespace: "ecs",
76
+ targetTrackingScalingPolicyConfiguration: {
77
+ targetValue: autoScalingConfig.targetCPUUtilization,
78
+ predefinedMetricSpecification: {
79
+ predefinedMetricType: "ECSServiceAverageCPUUtilization",
80
+ },
81
+ scaleInCooldown: autoScalingConfig.scaleInCooldown || 300,
82
+ scaleOutCooldown: autoScalingConfig.scaleOutCooldown || 300,
83
+ },
84
+ }, {
85
+ provider,
86
+ dependsOn: [scalingTarget]
87
+ });
88
+ policies.push(cpuPolicy);
89
+ }
90
+ if (autoScalingConfig.targetMemoryUtilization) {
91
+ const memoryPolicyResourceName = `${resourceNamePrefix}-memory-scaling-policy`;
92
+ const memoryPolicy = new aws.appautoscaling.Policy(memoryPolicyResourceName, {
93
+ name: `${resourceNamePrefix}-memory-scaling`,
94
+ policyType: "TargetTrackingScaling",
95
+ resourceId: resourceId,
96
+ scalableDimension: "ecs:service:DesiredCount",
97
+ serviceNamespace: "ecs",
98
+ targetTrackingScalingPolicyConfiguration: {
99
+ targetValue: autoScalingConfig.targetMemoryUtilization,
100
+ predefinedMetricSpecification: {
101
+ predefinedMetricType: "ECSServiceAverageMemoryUtilization",
102
+ },
103
+ scaleInCooldown: autoScalingConfig.scaleInCooldown || 300,
104
+ scaleOutCooldown: autoScalingConfig.scaleOutCooldown || 300,
105
+ },
106
+ }, {
107
+ provider,
108
+ dependsOn: [scalingTarget]
109
+ });
110
+ policies.push(memoryPolicy);
111
+ }
112
+ return {
113
+ scalingTarget,
114
+ policies
115
+ };
116
+ }
117
+ class ServiceFactory extends resourceFactory_1.ResourceFactory {
118
+ async createResource(config, provider) {
119
+ const { configuration, inputs, meta } = config;
120
+ const { taskRolePolicyStatements, executionRolePolicyStatements } = configuration;
121
+ if (!configuration.name) {
122
+ throw new Error("Invalid service configuration: Missing 'name' property.");
123
+ }
124
+ if (!inputs.albListenerArn || !inputs.albSgId || !inputs.subnets || !inputs.clusterArn) {
125
+ throw new Error("Missing required inputs for service deployment (albListenerArn, albSgId, subnets, clusterArn)");
126
+ }
127
+ const enableTargetGroup = configuration.enableTargetGroup !== false;
128
+ const enableAlbListenerRules = configuration.enableAlbListenerRules !== false;
129
+ let tg = undefined;
130
+ if (enableTargetGroup) {
131
+ tg = (0, createTargetGroup_1.createTargetGroup)({
132
+ name: configuration.name,
133
+ environment: meta.environment,
134
+ port: configuration.port,
135
+ vpcId: inputs.vpcId,
136
+ healthCheckPath: configuration.healthCheckPath,
137
+ protocol: configuration.protocol
138
+ }, provider);
139
+ }
140
+ let listenerRules = [];
141
+ if (enableTargetGroup && enableAlbListenerRules && tg) {
142
+ const listenerRulePriority = (0, getDeterministicPriority_1.getDeterministicPriority)(config.id, configuration.priority);
143
+ if (Array.isArray(configuration.albListenerRules) && configuration.albListenerRules.length > 0) {
144
+ listenerRules = configuration.albListenerRules.map((rule, idx) => tg ? (0, createListenerRule_1.createListenerRule)({
145
+ name: configuration.name,
146
+ environment: meta.environment,
147
+ listenerArn: inputs.albListenerArn,
148
+ priority: rule.priority || (0, getDeterministicPriority_1.getDeterministicPriority)(`${config.id}-${idx}`),
149
+ targetGroupArn: tg.arn,
150
+ conditions: rule.conditions
151
+ }, provider) : undefined).filter(Boolean);
152
+ }
153
+ else {
154
+ if (tg) {
155
+ listenerRules = [(0, createListenerRule_1.createListenerRule)({
156
+ name: configuration.name,
157
+ environment: meta.environment,
158
+ listenerArn: inputs.albListenerArn,
159
+ priority: listenerRulePriority,
160
+ targetGroupArn: tg.arn,
161
+ path: configuration.path
162
+ }, provider)];
163
+ }
164
+ else {
165
+ listenerRules = [];
166
+ }
167
+ }
168
+ }
169
+ const { taskRole, executionRole } = (0, createEcsRolesAndPolicies_1.createEcsRolesAndPolicies)({
170
+ name: configuration.name,
171
+ environment: meta.environment,
172
+ taskRolePolicyStatements,
173
+ executionRolePolicyStatements
174
+ }, provider);
175
+ const env = configuration.env || [];
176
+ const secretsById = (0, collectSecretKeys_1.collectSecretKeys)(env);
177
+ const allSecrets = await (0, fetchAllSecrets_1.fetchAllSecrets)(secretsById);
178
+ const environment = (0, resolveEnvSecrets_1.resolveEnvSecrets)(env, allSecrets);
179
+ const { envSecret, envSecretVersion } = await (0, createEnvSecret_1.createEnvSecret)({
180
+ id: `${meta.environment}-${config.id}`,
181
+ environment
182
+ });
183
+ const { secrets, environmentVars } = (0, buildEcsSecrets_1.buildEcsSecrets)({
184
+ environment,
185
+ envSecret
186
+ });
187
+ let ecrRepo = undefined;
188
+ let ecrRepoLifecycle = undefined;
189
+ let ecrRepoName = configuration.ecr?.name || configuration.dockerBuild?.repositoryName || `${configuration.name}-ecr-repo`;
190
+ if (configuration.ecr?.enabled) {
191
+ const { repo, repoLifecycle } = await (0, createEcrRepo_1.createEcrRepo)(`${meta.environment}-${ecrRepoName}`, meta.environment, configuration.tags, configuration.ecr.lifecyclePolicy, configuration.ecr);
192
+ ecrRepo = repo;
193
+ ecrRepoLifecycle = repoLifecycle;
194
+ }
195
+ if (configuration.dockerBuild && configuration.dockerBuild.context) {
196
+ if (!ecrRepo) {
197
+ throw new Error("ECR repo must be created for dockerBuild. Check your configuration.ecr block.");
198
+ }
199
+ const ecrCreds = aws.ecr.getAuthorizationTokenOutput({});
200
+ const image = (0, buildAndPushDockerImage_1.buildAndPushDockerImage)({
201
+ name: configuration.name,
202
+ environment: meta.environment,
203
+ repoUrl: ecrRepo.repositoryUrl,
204
+ dockerBuild: configuration.dockerBuild,
205
+ ecrCreds
206
+ });
207
+ configuration.image = image.imageName;
208
+ image.imageName.apply(img => {
209
+ });
210
+ }
211
+ const region = meta.region;
212
+ const logGroupName = `/ecs/${meta.environment}-${configuration.name}`;
213
+ const retentionInDays = configuration.logging?.retentionInDays || 365;
214
+ const logGroup = (0, createLogGroup_1.createLogGroup)(logGroupName, region, retentionInDays, provider);
215
+ if (configuration.logging?.dataProtection?.enabled) {
216
+ const dataProtectionPolicy = (0, dataProtectionPolicyBuilder_1.buildDataProtectionPolicy)(configuration.logging.dataProtection, logGroupName, dataProtectionPolicyBuilder_1.DEFAULT_DATA_IDENTIFIERS.ECS_LOGS, "ECS Service");
217
+ if (dataProtectionPolicy) {
218
+ new aws.cloudwatch.LogDataProtectionPolicy(`${meta.environment}-${configuration.name}-data-protection`, {
219
+ logGroupName: logGroupName,
220
+ policyDocument: JSON.stringify(dataProtectionPolicy),
221
+ }, {
222
+ dependsOn: [logGroup],
223
+ provider
224
+ });
225
+ }
226
+ }
227
+ const redeployEnv = (0, buildForceRedeployEnv_1.buildForceRedeployEnv)(configuration.forceRedeploy);
228
+ const baseContainer = {
229
+ name: `${meta.environment}-${configuration.name}`,
230
+ image: configuration.image,
231
+ portMappings: [{ containerPort: configuration.port }],
232
+ environment: [],
233
+ secrets: [],
234
+ logConfiguration: {
235
+ logDriver: "awslogs",
236
+ options: {
237
+ "awslogs-group": logGroupName,
238
+ "awslogs-region": region,
239
+ "awslogs-stream-prefix": "ecs"
240
+ }
241
+ }
242
+ };
243
+ const containerDef = pulumi.all([
244
+ environmentVars,
245
+ secrets,
246
+ configuration.image
247
+ ]).apply(([envVars, secrets, image]) => {
248
+ let container = { ...baseContainer, image, environment: [...envVars, ...redeployEnv], secrets };
249
+ if (config.containerTemplate) {
250
+ container = config.containerTemplate(container, config);
251
+ }
252
+ return JSON.stringify([container]);
253
+ });
254
+ const taskDef = (0, createTaskDefinition_1.createTaskDefinition)({
255
+ name: `${meta.environment}-${configuration.name}`,
256
+ cpu: configuration.cpu,
257
+ memory: configuration.memory,
258
+ executionRoleArn: executionRole.arn,
259
+ taskRoleArn: taskRole.arn,
260
+ containerDefinitions: containerDef,
261
+ dependsOn: [logGroup]
262
+ }, provider);
263
+ if (!tg) {
264
+ throw new Error("Target group must be created for ECS service. Check your configuration.");
265
+ }
266
+ const service = (0, createEcsService_1.createEcsService)({
267
+ name: `${meta.environment}-${configuration.name}`,
268
+ cluster: inputs.clusterArn,
269
+ taskDefinition: taskDef.arn,
270
+ desiredCount: configuration.desiredCount,
271
+ launchType: configuration.launchType || "FARGATE",
272
+ networkConfiguration: {
273
+ subnets: inputs.subnets,
274
+ securityGroups: [inputs.sgId || pulumi.output("")]
275
+ },
276
+ loadBalancers: [
277
+ {
278
+ targetGroupArn: tg.arn,
279
+ containerName: `${meta.environment}-${configuration.name}`,
280
+ containerPort: configuration.port
281
+ }
282
+ ],
283
+ deploymentCircuitBreaker: configuration.circuitBreaker && configuration.circuitBreaker.enabled ? {
284
+ enable: configuration.circuitBreaker.enable !== false,
285
+ rollback: configuration.circuitBreaker.rollback !== false
286
+ } : undefined,
287
+ dependsOn: [
288
+ tg,
289
+ ...listenerRules
290
+ ]
291
+ });
292
+ if (config.hooks?.beforeCreateTaskDef) {
293
+ await config.hooks.beforeCreateTaskDef(config);
294
+ }
295
+ if (envSecret) {
296
+ (0, attachSecretAccessPolicy_1.attachSecretAccessPolicy)({
297
+ name: `${meta.environment}-${configuration.name}`,
298
+ role: taskRole,
299
+ secretArn: envSecret.arn
300
+ });
301
+ (0, attachSecretAccessPolicy_1.attachSecretAccessPolicy)({
302
+ name: `${meta.environment}-${configuration.name}` + "-exec",
303
+ role: executionRole,
304
+ secretArn: envSecret.arn
305
+ });
306
+ service.envSecret = envSecret;
307
+ }
308
+ if (ecrRepo) {
309
+ service.ecrRepo = ecrRepo;
310
+ }
311
+ let scalingTarget, scalingPolicies;
312
+ if (configuration.autoScaling?.enabled || configuration.minCapacity || configuration.maxCapacity) {
313
+ const autoScalingConfig = {
314
+ enabled: configuration.autoScaling?.enabled ?? true,
315
+ minCapacity: configuration.autoScaling?.minCapacity || configuration.minCapacity || 1,
316
+ maxCapacity: configuration.autoScaling?.maxCapacity || configuration.maxCapacity || 10,
317
+ targetCPUUtilization: configuration.autoScaling?.targetCPUUtilization || 70,
318
+ targetMemoryUtilization: configuration.autoScaling?.targetMemoryUtilization || 80,
319
+ scaleInCooldown: configuration.autoScaling?.scaleInCooldown || 300,
320
+ scaleOutCooldown: configuration.autoScaling?.scaleOutCooldown || 300,
321
+ };
322
+ const staticServiceName = `${meta.environment}-${configuration.name}`;
323
+ const autoScaling = createAutoScaling(service, pulumi.output(inputs.clusterArn).apply(arn => arn.split('/').pop() || ''), autoScalingConfig, staticServiceName, provider);
324
+ scalingTarget = autoScaling.scalingTarget;
325
+ scalingPolicies = autoScaling.policies;
326
+ service.scalingTarget = scalingTarget;
327
+ service.scalingPolicies = scalingPolicies;
328
+ }
329
+ if (config.hooks?.afterCreateService) {
330
+ await config.hooks.afterCreateService(service, config);
331
+ }
332
+ return service;
333
+ }
334
+ getOutputs(resource) {
335
+ return {
336
+ id: resource.id,
337
+ name: resource.name,
338
+ secretArn: resource.envSecret ? resource.envSecret.arn : undefined,
339
+ ecrRepositoryUrl: resource.ecrRepo ? resource.ecrRepo.repositoryUrl : undefined,
340
+ ecrRepositoryArn: resource.ecrRepo ? resource.ecrRepo.arn : undefined,
341
+ scalingTargetArn: resource.scalingTarget ? resource.scalingTarget.arn : undefined,
342
+ };
343
+ }
344
+ validateConfig(config) {
345
+ if (!config.configuration || !config.configuration.name) {
346
+ throw new Error("Service config must include configuration with name");
347
+ }
348
+ }
349
+ }
350
+ exports.ServiceFactory = ServiceFactory;