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,84 @@
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.CloudWatchLogGroupFactory = void 0;
37
+ const aws = __importStar(require("@pulumi/aws"));
38
+ const resourceFactory_1 = require("./resourceFactory");
39
+ const dataProtectionPolicyBuilder_1 = require("./dataProtectionPolicyBuilder");
40
+ class CloudWatchLogGroupFactory extends resourceFactory_1.ResourceFactory {
41
+ async createResource(config, provider) {
42
+ this.validateConfig(config);
43
+ const logGroup = new aws.cloudwatch.LogGroup(`${config.id}-log-group`, {
44
+ name: config.configuration.name,
45
+ retentionInDays: config.configuration.retentionInDays || 365,
46
+ kmsKeyId: config.configuration.kmsKeyId,
47
+ tags: config.configuration.tags,
48
+ }, provider ? { provider } : undefined);
49
+ if (config.configuration.dataProtection?.enabled) {
50
+ const dataProtectionPolicy = this.buildDataProtectionPolicy(config);
51
+ const policy = new aws.cloudwatch.LogDataProtectionPolicy(`${config.id}-data-protection-policy`, {
52
+ logGroupName: logGroup.name,
53
+ policyDocument: JSON.stringify(dataProtectionPolicy),
54
+ }, {
55
+ provider: provider,
56
+ dependsOn: [logGroup]
57
+ });
58
+ logGroup.dataProtectionPolicy = policy;
59
+ }
60
+ return logGroup;
61
+ }
62
+ getOutputs(resource) {
63
+ return {
64
+ arn: resource.arn,
65
+ name: resource.name,
66
+ dataProtectionPolicyExists: !!resource.dataProtectionPolicy,
67
+ };
68
+ }
69
+ buildDataProtectionPolicy(config) {
70
+ return (0, dataProtectionPolicyBuilder_1.buildDataProtectionPolicy)(config.configuration.dataProtection, config.configuration.name, dataProtectionPolicyBuilder_1.DEFAULT_DATA_IDENTIFIERS.GENERAL, "CloudWatch Log Group");
71
+ }
72
+ validateConfig(config) {
73
+ if (!config.configuration?.name) {
74
+ throw new Error("CloudWatch Log Group must have a name configured");
75
+ }
76
+ if (config.configuration.retentionInDays &&
77
+ ![
78
+ 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653,
79
+ ].includes(config.configuration.retentionInDays)) {
80
+ throw new Error("CloudWatch Log Group retentionInDays must be one of: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653");
81
+ }
82
+ }
83
+ }
84
+ exports.CloudWatchLogGroupFactory = CloudWatchLogGroupFactory;
@@ -0,0 +1,357 @@
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.CloudFrontCodePipelineFactory = 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 CloudFrontCodePipelineFactory 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
+ "s3:*",
50
+ "cloudfront:*",
51
+ "cloudformation:*",
52
+ "codebuild:*",
53
+ "codestar-connections:UseConnection",
54
+ "logs:CreateLogGroup",
55
+ "logs:CreateLogStream",
56
+ "logs:PutLogEvents",
57
+ "iam:PassRole"
58
+ ],
59
+ Resource: "*"
60
+ }
61
+ ]
62
+ });
63
+ }
64
+ createCodeBuildPolicyDoc(config) {
65
+ const baseActions = [
66
+ "logs:CreateLogGroup",
67
+ "logs:CreateLogStream",
68
+ "logs:PutLogEvents",
69
+ "s3:GetBucketAcl",
70
+ "s3:GetBucketLocation",
71
+ "s3:GetObject",
72
+ "s3:GetObjectVersion",
73
+ "s3:PutObject",
74
+ "s3:DeleteObject",
75
+ "s3:ListBucket",
76
+ "cloudfront:CreateInvalidation",
77
+ "cloudfront:GetDistribution",
78
+ "cloudfront:GetInvalidation",
79
+ "codebuild:CreateReportGroup",
80
+ "codebuild:CreateReport",
81
+ "codebuild:UpdateReport",
82
+ "codebuild:BatchPutTestCases",
83
+ "codebuild:BatchPutCodeCoverages",
84
+ "secretsmanager:GetSecretValue",
85
+ "secretsmanager:DescribeSecret"
86
+ ];
87
+ if (config.configuration.deployCodePipelineInVpc) {
88
+ baseActions.push("ec2:DescribeSecurityGroups", "ec2:DescribeSubnets", "ec2:DescribeVpcs", "ec2:DescribeNetworkInterfaces", "ec2:CreateNetworkInterface", "ec2:DeleteNetworkInterface", "ec2:CreateNetworkInterfacePermission", "ec2:DescribeDhcpOptions", "ec2:AttachNetworkInterface", "ec2:DetachNetworkInterface");
89
+ }
90
+ return JSON.stringify({
91
+ Version: "2012-10-17",
92
+ Statement: [
93
+ {
94
+ Effect: "Allow",
95
+ Action: baseActions,
96
+ Resource: "*"
97
+ }
98
+ ]
99
+ });
100
+ }
101
+ async createResource(config, provider) {
102
+ const { configuration } = config;
103
+ const envPrefix = `${config.meta.environment}-${config.id}`;
104
+ const { codebuildRole, pipelineRole } = this.createIamRoles(config, envPrefix, provider);
105
+ const artifactBucket = this.createArtifactBucket(config, envPrefix, provider);
106
+ const codebuildProject = this.createCodeBuildProject(config, envPrefix, codebuildRole, provider);
107
+ const pipeline = this.createCodePipeline(config, envPrefix, pipelineRole, artifactBucket, codebuildProject, provider);
108
+ return pipeline;
109
+ }
110
+ createIamRoles(config, envPrefix, provider) {
111
+ const codebuildRole = new aws.iam.Role(`${envPrefix}-codebuild-role`, {
112
+ assumeRolePolicy: JSON.stringify({
113
+ Version: "2012-10-17",
114
+ Statement: [
115
+ {
116
+ Effect: "Allow",
117
+ Principal: { Service: "codebuild.amazonaws.com" },
118
+ Action: "sts:AssumeRole"
119
+ }
120
+ ]
121
+ }),
122
+ tags: config.configuration.tags,
123
+ }, provider ? { provider } : undefined);
124
+ const codebuildPolicy = new aws.iam.Policy(`${envPrefix}-codebuild-policy`, {
125
+ description: "Policy for CloudFront CodeBuild project",
126
+ policy: this.createCodeBuildPolicyDoc(config)
127
+ }, provider ? { provider } : undefined);
128
+ new aws.iam.RolePolicyAttachment(`${envPrefix}-codebuild-policy-attach`, {
129
+ role: codebuildRole.name,
130
+ policyArn: codebuildPolicy.arn
131
+ }, provider ? { provider } : undefined);
132
+ const pipelineRole = new aws.iam.Role(`${envPrefix}-pipeline-role`, {
133
+ assumeRolePolicy: JSON.stringify({
134
+ Version: "2012-10-17",
135
+ Statement: [
136
+ {
137
+ Effect: "Allow",
138
+ Principal: { Service: "codepipeline.amazonaws.com" },
139
+ Action: "sts:AssumeRole"
140
+ }
141
+ ]
142
+ }),
143
+ tags: config.configuration.tags,
144
+ }, provider ? { provider } : undefined);
145
+ const pipelinePolicy = new aws.iam.Policy(`${envPrefix}-pipeline-policy`, {
146
+ description: "Policy for CloudFront CodePipeline",
147
+ policy: this.createPipelinePolicyDoc(config)
148
+ }, provider ? { provider } : undefined);
149
+ new aws.iam.RolePolicyAttachment(`${envPrefix}-pipeline-policy-attach`, {
150
+ role: pipelineRole.name,
151
+ policyArn: pipelinePolicy.arn
152
+ }, provider ? { provider } : undefined);
153
+ return { codebuildRole, pipelineRole };
154
+ }
155
+ createArtifactBucket(config, envPrefix, provider) {
156
+ return new aws.s3.Bucket(`${envPrefix}-artifacts`, {
157
+ forceDestroy: config.configuration.s3BucketForceDestroy ?? true,
158
+ tags: config.configuration.tags,
159
+ serverSideEncryptionConfiguration: {
160
+ rule: {
161
+ applyServerSideEncryptionByDefault: {
162
+ sseAlgorithm: "AES256",
163
+ },
164
+ },
165
+ },
166
+ versioning: {
167
+ enabled: true,
168
+ },
169
+ }, provider ? { provider } : undefined);
170
+ }
171
+ createCodeBuildProject(config, envPrefix, codebuildRole, provider) {
172
+ let buildspec = undefined;
173
+ if (config.configuration.buildspecPath) {
174
+ const buildspecPath = config.configuration.buildspecPath;
175
+ const isExternal = path.isAbsolute(buildspecPath) || buildspecPath.startsWith("../") || buildspecPath.includes("/assets/cicd/buildspecs/");
176
+ if (isExternal) {
177
+ try {
178
+ buildspec = fs.readFileSync(buildspecPath, "utf8");
179
+ }
180
+ catch (e) {
181
+ throw new Error(`Failed to read external buildspec at ${buildspecPath}: ${e}`);
182
+ }
183
+ }
184
+ else {
185
+ buildspec = buildspecPath;
186
+ }
187
+ }
188
+ else {
189
+ buildspec = this.getDefaultBuildspec(config);
190
+ }
191
+ let vpcConfig = undefined;
192
+ if (config.configuration.deployCodePipelineInVpc && config.inputs?.vpcId) {
193
+ vpcConfig = {
194
+ vpcId: config.inputs.vpcId,
195
+ subnets: config.inputs.subnetIds,
196
+ securityGroupIds: config.inputs.securityGroupIds,
197
+ };
198
+ }
199
+ return new aws.codebuild.Project(`${envPrefix}-build`, {
200
+ source: {
201
+ type: "CODEPIPELINE",
202
+ buildspec,
203
+ },
204
+ artifacts: {
205
+ type: "CODEPIPELINE",
206
+ },
207
+ environment: {
208
+ computeType: config.configuration.computeType || "BUILD_GENERAL1_LARGE",
209
+ image: config.configuration.buildImage || "aws/codebuild/amazonlinux2-x86_64-standard:4.0",
210
+ type: config.configuration.environmentType || "LINUX_CONTAINER",
211
+ privilegedMode: config.configuration.privilegedMode || false,
212
+ environmentVariables: [
213
+ ...(config.configuration.buildEnvironmentVariables || []),
214
+ {
215
+ name: "CLOUDFRONT_DISTRIBUTION_ID",
216
+ value: config.configuration.cloudfrontDistributionId,
217
+ type: "PLAINTEXT"
218
+ },
219
+ {
220
+ name: "S3_BUCKET_NAME",
221
+ value: config.configuration.s3BucketName,
222
+ type: "PLAINTEXT"
223
+ },
224
+ {
225
+ name: "INVALIDATION_PATHS",
226
+ value: (config.configuration.cacheInvalidationPaths || ["/*"]).join(" "),
227
+ type: "PLAINTEXT"
228
+ }
229
+ ],
230
+ },
231
+ serviceRole: codebuildRole.arn,
232
+ tags: config.configuration.tags,
233
+ vpcConfig,
234
+ }, provider ? { provider } : undefined);
235
+ }
236
+ createCodePipeline(config, envPrefix, pipelineRole, artifactBucket, codebuildProject, provider) {
237
+ const sourceAction = {
238
+ name: "Source",
239
+ category: "Source",
240
+ owner: "AWS",
241
+ provider: "CodeStarSourceConnection",
242
+ version: "1",
243
+ outputArtifacts: ["source_output"],
244
+ configuration: {
245
+ ConnectionArn: config.configuration.codestarConnectionArn,
246
+ FullRepositoryId: `${config.configuration.repoOwner}/${config.configuration.repoName}`,
247
+ BranchName: config.configuration.branch,
248
+ DetectChanges: config.configuration.pollSourceChanges ? "true" : "false",
249
+ OutputArtifactFormat: config.configuration.outputArtifactFormat ?? "CODE_ZIP",
250
+ },
251
+ };
252
+ const buildAction = {
253
+ name: "Build",
254
+ category: "Build",
255
+ owner: "AWS",
256
+ provider: "CodeBuild",
257
+ inputArtifacts: ["source_output"],
258
+ outputArtifacts: ["build_output"],
259
+ version: "1",
260
+ configuration: {
261
+ ProjectName: codebuildProject.name,
262
+ },
263
+ };
264
+ const deployAction = {
265
+ name: "Deploy",
266
+ category: "Deploy",
267
+ owner: "AWS",
268
+ provider: "S3",
269
+ inputArtifacts: ["build_output"],
270
+ version: "1",
271
+ configuration: {
272
+ BucketName: config.configuration.s3BucketName,
273
+ Extract: "true",
274
+ },
275
+ runOrder: 1,
276
+ };
277
+ const stages = config.configuration.stages || [
278
+ {
279
+ name: "Source",
280
+ actions: [sourceAction],
281
+ },
282
+ {
283
+ name: "Build",
284
+ actions: [buildAction],
285
+ },
286
+ {
287
+ name: "Deploy",
288
+ actions: [deployAction],
289
+ },
290
+ ];
291
+ return new aws.codepipeline.Pipeline(`${envPrefix}-pipeline`, {
292
+ roleArn: pipelineRole.arn,
293
+ artifactStores: [{
294
+ location: artifactBucket.bucket,
295
+ type: "S3"
296
+ }],
297
+ stages,
298
+ tags: config.configuration.tags,
299
+ name: `${envPrefix}`,
300
+ }, provider ? { provider } : undefined);
301
+ }
302
+ getDefaultBuildspec(config) {
303
+ return `version: 0.2
304
+
305
+ phases:
306
+ install:
307
+ runtime-versions:
308
+ nodejs: 18
309
+ commands:
310
+ - echo "Installing dependencies..."
311
+ - npm ci --production
312
+
313
+ pre_build:
314
+ commands:
315
+ - echo "Starting build process for static site..."
316
+ - echo "Build started on \$(date)"
317
+
318
+ build:
319
+ commands:
320
+ - echo "Building static site..."
321
+ - npm run build
322
+ - echo "Build completed on \$(date)"
323
+
324
+ post_build:
325
+ commands:
326
+ - echo "Syncing to S3 bucket..."
327
+ - aws s3 sync ./dist s3://\$S3_BUCKET_NAME --delete --exact-timestamps
328
+ - echo "Creating CloudFront invalidation..."
329
+ - aws cloudfront create-invalidation --distribution-id \$CLOUDFRONT_DISTRIBUTION_ID --paths \$INVALIDATION_PATHS
330
+ - echo "Deployment completed on \$(date)"
331
+
332
+ artifacts:
333
+ files:
334
+ - '**/*'
335
+ base-directory: 'dist'
336
+ `;
337
+ }
338
+ getOutputs(resource) {
339
+ const region = resource.region || resource.location || "us-east-1";
340
+ return {
341
+ arn: resource.arn,
342
+ name: resource.name,
343
+ url: `https://${region}.console.aws.amazon.com/codesuite/codepipeline/pipelines/${resource.name}/view?region=${region}`,
344
+ codebuildProjectName: resource.name.apply ? resource.name.apply(name => `${name}-build`) : `${resource.name}-build`,
345
+ };
346
+ }
347
+ validateConfig(config) {
348
+ const { configuration } = config;
349
+ if (!configuration.repoOwner || !configuration.repoName || !configuration.branch || !configuration.codestarConnectionArn) {
350
+ throw new Error("CloudFront CodePipeline config must include repoOwner, repoName, branch, and codestarConnectionArn");
351
+ }
352
+ if (!configuration.cloudfrontDistributionId || !configuration.s3BucketName) {
353
+ throw new Error("CloudFront CodePipeline config must include cloudfrontDistributionId and s3BucketName");
354
+ }
355
+ }
356
+ }
357
+ exports.CloudFrontCodePipelineFactory = CloudFrontCodePipelineFactory;
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloudWatchAlarmsFactory = void 0;
4
+ const resourceFactory_1 = require("./resourceFactory");
5
+ const buildAwsCloudWatchAlarmsHelper_1 = require("./buildAwsCloudWatchAlarmsHelper");
6
+ class CloudWatchAlarmsFactory extends resourceFactory_1.ResourceFactory {
7
+ currentConfig;
8
+ async createResource(config) {
9
+ this.currentConfig = config;
10
+ function getProp(key) {
11
+ if (!config)
12
+ return undefined;
13
+ if (key in config)
14
+ return config[key];
15
+ if (config.configuration && key in config.configuration)
16
+ return config.configuration[key];
17
+ return undefined;
18
+ }
19
+ const namePrefix = getProp("resourceId") || getProp("resourceType") || "alarm";
20
+ return (0, buildAwsCloudWatchAlarmsHelper_1.buildAwsCloudWatchAlarmsHelper)(namePrefix, config);
21
+ }
22
+ getOutputs(resources) {
23
+ const alarmsByName = {};
24
+ const alarmArnsByName = {};
25
+ const alarmNamesByName = {};
26
+ const groups = {};
27
+ const alarmDict = {};
28
+ const createFriendlyName = (alarmConfig, index) => {
29
+ if (!alarmConfig || !alarmConfig.metricName) {
30
+ return `alarm${index}`;
31
+ }
32
+ const friendlyNames = {
33
+ 'CPUUtilization': 'cpuAlarm',
34
+ 'MemoryUtilization': 'memoryAlarm',
35
+ 'ActiveServicesCount': 'serviceCountAlarm',
36
+ 'DatabaseConnections': 'connectionsAlarm',
37
+ 'ReadLatency': 'readLatencyAlarm',
38
+ 'WriteLatency': 'writeLatencyAlarm',
39
+ 'FreeableMemory': 'memoryAlarm',
40
+ 'DBLoad': 'dbLoadAlarm',
41
+ 'TargetResponseTime': 'responseTimeAlarm',
42
+ 'HTTPCode_ELB_5XX_Count': 'errorAlarm',
43
+ 'UnHealthyHostCount': 'unhealthyHostsAlarm',
44
+ 'BucketSizeBytes': 'bucketSizeAlarm',
45
+ 'NumberOfObjects': 'objectCountAlarm',
46
+ 'StatusCheckFailed': 'statusCheckAlarm',
47
+ 'RunningTaskCount': 'taskCountAlarm',
48
+ 'VolumeBytesUsed': 'volumeUsageAlarm'
49
+ };
50
+ return friendlyNames[alarmConfig.metricName] || `${alarmConfig.metricName.toLowerCase()}Alarm`;
51
+ };
52
+ const getAlarmGroup = (alarmConfig) => {
53
+ if (!alarmConfig)
54
+ return 'default';
55
+ const metricName = alarmConfig.metricName;
56
+ const threshold = alarmConfig.threshold;
57
+ if (['CPUUtilization', 'MemoryUtilization', 'StatusCheckFailed', 'ActiveServicesCount', 'RunningTaskCount'].includes(metricName)) {
58
+ return 'critical';
59
+ }
60
+ if (['ReadLatency', 'WriteLatency', 'TargetResponseTime', 'HTTPCode_ELB_5XX_Count', 'DBLoad'].includes(metricName)) {
61
+ return 'performance';
62
+ }
63
+ if (['DatabaseConnections', 'BucketSizeBytes', 'NumberOfObjects', 'VolumeBytesUsed', 'FreeableMemory'].includes(metricName)) {
64
+ return 'capacity';
65
+ }
66
+ if (['UnHealthyHostCount'].includes(metricName)) {
67
+ return 'health';
68
+ }
69
+ return 'default';
70
+ };
71
+ const getAlarmConfigs = () => {
72
+ if (!this.currentConfig)
73
+ return [];
74
+ const config = this.currentConfig;
75
+ return config.alarms || config.configuration?.alarms || [];
76
+ };
77
+ const alarmConfigs = getAlarmConfigs();
78
+ resources.forEach((alarm, index) => {
79
+ const alarmConfig = alarmConfigs[index];
80
+ const friendlyName = createFriendlyName(alarmConfig, index);
81
+ const groupName = getAlarmGroup(alarmConfig);
82
+ const alarmName = alarmConfig?.name || `alarm-${index}`;
83
+ alarmsByName[friendlyName] = alarm.name;
84
+ alarmArnsByName[friendlyName] = alarm.arn;
85
+ if (alarmName) {
86
+ alarmNamesByName[alarmName] = alarm.name;
87
+ }
88
+ if (!groups[groupName]) {
89
+ groups[groupName] = [];
90
+ }
91
+ groups[groupName].push(alarm.name);
92
+ const dictKey = alarmName.replace(/-/g, '_');
93
+ alarmDict[dictKey] = alarm.name;
94
+ });
95
+ return {
96
+ alarmNames: resources.map(r => r.name),
97
+ alarmArns: resources.map(r => r.arn),
98
+ alarmsByName,
99
+ alarmArnsByName,
100
+ alarmNamesByName,
101
+ groups,
102
+ alarmDict
103
+ };
104
+ }
105
+ validateConfig(config) {
106
+ function getProp(key) {
107
+ if (!config)
108
+ return undefined;
109
+ if (key in config)
110
+ return config[key];
111
+ if (config.configuration && key in config.configuration)
112
+ return config.configuration[key];
113
+ return undefined;
114
+ }
115
+ const alarms = getProp("alarms");
116
+ if (!alarms || !Array.isArray(alarms) || alarms.length === 0) {
117
+ throw new Error("CloudWatchAlarmsFactory: 'alarms' array required in config or configuration");
118
+ }
119
+ }
120
+ }
121
+ exports.CloudWatchAlarmsFactory = CloudWatchAlarmsFactory;