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,262 @@
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.S3Factory = void 0;
37
+ const aws = __importStar(require("@pulumi/aws"));
38
+ const resourceFactory_1 = require("./resourceFactory");
39
+ const validateS3Config_1 = require("./validateS3Config");
40
+ class S3Factory extends resourceFactory_1.ResourceFactory {
41
+ async createResource(config, provider) {
42
+ (0, validateS3Config_1.validateS3Config)(config);
43
+ const opts = provider ? { provider } : undefined;
44
+ const bucketName = config.configuration.bucket ||
45
+ `${config.meta.environment}-${config.meta.variables.project}-${config.id}`;
46
+ const bucket = new aws.s3.BucketV2(`${config.id}-bucket`, {
47
+ bucket: bucketName,
48
+ forceDestroy: true,
49
+ tags: config.configuration.tags,
50
+ }, opts);
51
+ if (config.configuration.versioning?.enabled) {
52
+ new aws.s3.BucketVersioningV2(`${config.id}-versioning`, {
53
+ bucket: bucket.id,
54
+ versioningConfiguration: {
55
+ status: "Enabled"
56
+ }
57
+ }, opts);
58
+ }
59
+ let ownershipControls;
60
+ if (config.configuration.objectOwnership || config.configuration.enableAcl) {
61
+ ownershipControls = new aws.s3.BucketOwnershipControls(`${config.id}-ownership`, {
62
+ bucket: bucket.id,
63
+ rule: {
64
+ objectOwnership: config.configuration.objectOwnership || "BucketOwnerPreferred"
65
+ }
66
+ }, opts);
67
+ }
68
+ if (config.configuration.acl && config.configuration.enableAcl) {
69
+ const aclConfig = {
70
+ bucket: bucket.id,
71
+ acl: config.configuration.acl
72
+ };
73
+ const aclOpts = { ...opts };
74
+ if (ownershipControls) {
75
+ aclOpts.dependsOn = [ownershipControls];
76
+ }
77
+ new aws.s3.BucketAclV2(`${config.id}-acl`, aclConfig, aclOpts);
78
+ }
79
+ if (config.configuration.encryption?.enabled) {
80
+ const encryptionConfig = {
81
+ bucket: bucket.id,
82
+ rules: [{
83
+ applyServerSideEncryptionByDefault: {
84
+ sseAlgorithm: config.configuration.encryption.algorithm || "AES256"
85
+ },
86
+ bucketKeyEnabled: true
87
+ }]
88
+ };
89
+ if (config.configuration.encryption.kmsMasterKeyId) {
90
+ encryptionConfig.rules[0].applyServerSideEncryptionByDefault.kmsMasterKeyId =
91
+ config.configuration.encryption.kmsMasterKeyId;
92
+ }
93
+ new aws.s3.BucketServerSideEncryptionConfigurationV2(`${config.id}-encryption`, encryptionConfig, opts);
94
+ }
95
+ if (config.configuration.lifecycle?.enabled && config.configuration.lifecycle.rules) {
96
+ new aws.s3.BucketLifecycleConfigurationV2(`${config.id}-lifecycle`, {
97
+ bucket: bucket.id,
98
+ rules: config.configuration.lifecycle.rules.map((rule, index) => ({
99
+ id: rule.id || `rule-${index}`,
100
+ status: rule.enabled ? "Enabled" : "Disabled",
101
+ filter: rule.filter || {},
102
+ transitions: rule.transitions || [],
103
+ expiration: rule.expiration ? {
104
+ days: rule.expiration.days
105
+ } : undefined
106
+ }))
107
+ }, opts);
108
+ }
109
+ if (config.configuration.publicAccessBlock) {
110
+ new aws.s3.BucketPublicAccessBlock(`${config.id}-public-access-block`, {
111
+ bucket: bucket.id,
112
+ blockPublicAcls: config.configuration.publicAccessBlock.blockPublicAcls,
113
+ blockPublicPolicy: config.configuration.publicAccessBlock.blockPublicPolicy,
114
+ ignorePublicAcls: config.configuration.publicAccessBlock.ignorePublicAcls,
115
+ restrictPublicBuckets: config.configuration.publicAccessBlock.restrictPublicBuckets
116
+ }, opts);
117
+ }
118
+ if (config.configuration.serverAccessLogging?.enabled) {
119
+ new aws.s3.BucketLoggingV2(`${config.id}-logging`, {
120
+ bucket: bucket.id,
121
+ targetBucket: config.configuration.serverAccessLogging.targetBucket || bucket.id,
122
+ targetPrefix: config.configuration.serverAccessLogging.targetPrefix || "access-logs/",
123
+ ...(config.configuration.serverAccessLogging.targetGrants && {
124
+ targetGrants: config.configuration.serverAccessLogging.targetGrants
125
+ })
126
+ }, opts);
127
+ }
128
+ if (config.configuration.policy?.enabled && config.configuration.policy.statements) {
129
+ const policyDocument = {
130
+ Version: "2012-10-17",
131
+ Statement: config.configuration.policy.statements.map((stmt) => {
132
+ let principal = {};
133
+ if (stmt.principals) {
134
+ if (stmt.principals.service) {
135
+ principal.Service = stmt.principals.service;
136
+ }
137
+ if (stmt.principals.aws) {
138
+ principal.AWS = stmt.principals.aws;
139
+ }
140
+ if (stmt.principals.federated) {
141
+ principal.Federated = stmt.principals.federated;
142
+ }
143
+ if (stmt.principals.Service || stmt.principals.AWS || stmt.principals.Federated) {
144
+ principal = stmt.principals;
145
+ }
146
+ }
147
+ return {
148
+ Sid: stmt.sid,
149
+ Effect: stmt.effect,
150
+ Principal: principal,
151
+ Action: stmt.actions,
152
+ Resource: stmt.resources,
153
+ ...(stmt.conditions && { Condition: stmt.conditions })
154
+ };
155
+ })
156
+ };
157
+ new aws.s3.BucketPolicy(`${config.id}-policy`, {
158
+ bucket: bucket.id,
159
+ policy: JSON.stringify(policyDocument)
160
+ }, opts);
161
+ }
162
+ if (config.configuration.replication?.enabled) {
163
+ await this.setupReplication(config, bucket, provider);
164
+ }
165
+ return bucket;
166
+ }
167
+ getOutputs(resource) {
168
+ return {
169
+ id: resource.id,
170
+ arn: resource.arn,
171
+ bucket: resource.bucket,
172
+ bucketName: resource.bucket,
173
+ kmsKeyArn: undefined,
174
+ kmsKeyId: undefined,
175
+ };
176
+ }
177
+ validateConfig(config) {
178
+ (0, validateS3Config_1.validateS3Config)(config);
179
+ }
180
+ async setupReplication(config, sourceBucket, provider) {
181
+ const replicationConfig = config.configuration.replication;
182
+ if (!replicationConfig?.enabled)
183
+ return;
184
+ const destinationRegion = replicationConfig.destinationRegion;
185
+ const destinationBucketName = replicationConfig.destinationBucket ||
186
+ `${config.meta.environment}-${config.configuration.bucket}-backup`;
187
+ const destinationBucketArn = `arn:aws:s3:::${destinationBucketName}`;
188
+ const replicationRole = this.createReplicationRole(config, sourceBucket, destinationBucketArn);
189
+ new aws.s3.BucketReplicationConfig(`${config.id}-replication`, {
190
+ bucket: sourceBucket.id,
191
+ role: replicationRole.arn,
192
+ rules: [{
193
+ id: "ReplicateEverything",
194
+ status: "Enabled",
195
+ priority: 1,
196
+ filter: {},
197
+ deleteMarkerReplication: {
198
+ status: "Enabled"
199
+ },
200
+ destination: {
201
+ bucket: destinationBucketArn,
202
+ storageClass: replicationConfig.storageClass || "STANDARD_IA"
203
+ }
204
+ }]
205
+ }, {
206
+ provider: provider,
207
+ dependsOn: [replicationRole]
208
+ });
209
+ return { replicationRole };
210
+ }
211
+ createReplicationRole(config, sourceBucket, destinationBucketArn) {
212
+ const replicationRole = new aws.iam.Role(`${config.id}-replication-role`, {
213
+ assumeRolePolicy: JSON.stringify({
214
+ Version: "2012-10-17",
215
+ Statement: [{
216
+ Action: "sts:AssumeRole",
217
+ Effect: "Allow",
218
+ Principal: {
219
+ Service: "s3.amazonaws.com"
220
+ }
221
+ }]
222
+ }),
223
+ tags: config.configuration.tags
224
+ });
225
+ const replicationPolicy = new aws.iam.Policy(`${config.id}-replication-policy`, {
226
+ policy: sourceBucket.arn.apply(sourceArn => JSON.stringify({
227
+ Version: "2012-10-17",
228
+ Statement: [
229
+ {
230
+ Effect: "Allow",
231
+ Action: [
232
+ "s3:GetObjectVersionForReplication",
233
+ "s3:GetObjectVersionAcl",
234
+ "s3:GetObjectVersionTagging"
235
+ ],
236
+ Resource: [`${sourceArn}/*`]
237
+ },
238
+ {
239
+ Effect: "Allow",
240
+ Action: ["s3:ListBucket"],
241
+ Resource: [sourceArn]
242
+ },
243
+ {
244
+ Effect: "Allow",
245
+ Action: [
246
+ "s3:ReplicateObject",
247
+ "s3:ReplicateDelete",
248
+ "s3:ReplicateTags"
249
+ ],
250
+ Resource: [`${destinationBucketArn}/*`]
251
+ }
252
+ ]
253
+ }))
254
+ });
255
+ new aws.iam.RolePolicyAttachment(`${config.id}-replication-policy-attachment`, {
256
+ role: replicationRole.name,
257
+ policyArn: replicationPolicy.arn
258
+ });
259
+ return replicationRole;
260
+ }
261
+ }
262
+ exports.S3Factory = S3Factory;
@@ -0,0 +1,424 @@
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.S3StaticHostingFactory = void 0;
37
+ const aws = __importStar(require("@pulumi/aws"));
38
+ const pulumi = __importStar(require("@pulumi/pulumi"));
39
+ const resourceFactory_1 = require("./resourceFactory");
40
+ const buildAwsCloudWatchAlarmsHelper_1 = require("./buildAwsCloudWatchAlarmsHelper");
41
+ const buildS3StaticHostingCloudWatchDashboardHelper_1 = require("./buildS3StaticHostingCloudWatchDashboardHelper");
42
+ const buildS3StaticHostingCicdHelper_1 = require("./buildS3StaticHostingCicdHelper");
43
+ const wafFactory_1 = require("./wafFactory");
44
+ class S3StaticHostingFactory extends resourceFactory_1.ResourceFactory {
45
+ static supportsProviderRegistry = true;
46
+ async createResource(config, provider, providerRegistry = {}) {
47
+ this.validateConfig(config);
48
+ this.validateHostedZoneRequirement(config);
49
+ const route53Provider = this.resolveRoute53Provider(config, providerRegistry);
50
+ const s3Client = this.createS3Client(config);
51
+ const bucket = this.createMainBucket(config, provider);
52
+ const artifactBucket = this.createArtifactBucketIfDefined(config, provider);
53
+ this.blockPublicAccessIfRequired(config, bucket, provider);
54
+ const cloudfrontDomain = await this.setupCloudFront(config, bucket, s3Client, provider, route53Provider);
55
+ bucket.cloudfrontDomain = cloudfrontDomain;
56
+ this.createEventNotifications(config, bucket, provider);
57
+ this.setupMonitoring(config, bucket, provider);
58
+ this.setupCicd(config, bucket, artifactBucket, provider);
59
+ return bucket;
60
+ }
61
+ getOutputs(resource) {
62
+ const getOutputName = (output) => output?.apply ? output.apply((x) => x.name) : output?.name;
63
+ return {
64
+ bucket: resource.bucket,
65
+ websiteUrl: resource.websiteUrl || resource.websiteEndpoint,
66
+ cloudfrontDomain: resource.cloudfrontDomain,
67
+ monitoringAlarmArns: resource.monitoringResources?.map((a) => a.arn),
68
+ dashboardName: resource.dashboardResource?.dashboardName,
69
+ codebuildProjectName: getOutputName(resource.cicdResources?.codebuild),
70
+ codepipelineName: getOutputName(resource.cicdResources?.pipeline),
71
+ };
72
+ }
73
+ validateConfig(config) {
74
+ if (!config.configuration?.bucket) {
75
+ throw new Error("S3StaticHosting config must include configuration with bucket");
76
+ }
77
+ }
78
+ validateHostedZoneRequirement(config) {
79
+ const cf = config.configuration.cloudfront;
80
+ if (cf?.enabled && cf.enableCertProvisioning && cf.aliases?.length && !config.meta?.hostedZoneId) {
81
+ throw new Error("[ERROR] meta.hostedZoneId is required for ACM automation.");
82
+ }
83
+ }
84
+ resolveRoute53Provider(config, registry) {
85
+ const ref = config.inputs?.route53Provider;
86
+ if (typeof ref === "object")
87
+ return ref;
88
+ if (typeof ref === "string") {
89
+ return registry[ref] || config.inputs.providers?.[ref] || (() => {
90
+ throw new Error(`[ERROR] route53Provider '${ref}' not found in registry`);
91
+ })();
92
+ }
93
+ return undefined;
94
+ }
95
+ createS3Client(config) {
96
+ const awsSdk = require("aws-sdk");
97
+ const bucket = config.configuration.cloudfront?.logging?.bucket;
98
+ const region = bucket === "cf-logs-bucket" ? "eu-central-1" : undefined;
99
+ return new awsSdk.S3(region ? { region } : {});
100
+ }
101
+ createMainBucket(config, provider) {
102
+ return new aws.s3.Bucket(`${config.meta.environment}-${config.configuration.bucket}`, {
103
+ bucket: config.configuration.bucket,
104
+ acl: config.configuration.acl || "private",
105
+ website: config.configuration.website,
106
+ tags: config.configuration.tags,
107
+ versioning: config.configuration.versioning ? { enabled: true } : undefined,
108
+ serverSideEncryptionConfiguration: config.configuration.encryption?.enabled
109
+ ? {
110
+ rule: {
111
+ applyServerSideEncryptionByDefault: {
112
+ sseAlgorithm: config.configuration.encryption.type || "AES256",
113
+ kmsMasterKeyId: config.configuration.encryption.kmsKeyId,
114
+ },
115
+ },
116
+ }
117
+ : undefined,
118
+ corsRules: config.configuration.cors ? [config.configuration.cors] : undefined,
119
+ lifecycleRules: config.configuration.lifecycleRules,
120
+ replicationConfiguration: config.configuration.replication,
121
+ forceDestroy: true,
122
+ }, provider ? { provider } : undefined);
123
+ }
124
+ createArtifactBucketIfDefined(config, provider) {
125
+ if (!config.configuration.cicd?.artifactBucket)
126
+ return undefined;
127
+ return new aws.s3.Bucket(`${config.meta.environment}-${config.configuration.cicd.artifactBucket}`, {
128
+ bucket: config.configuration.cicd.artifactBucket,
129
+ acl: "private",
130
+ versioning: { enabled: true },
131
+ tags: config.configuration.tags,
132
+ forceDestroy: true,
133
+ }, provider ? { provider } : undefined);
134
+ }
135
+ blockPublicAccessIfRequired(config, bucket, provider) {
136
+ if (config.configuration.blockPublicAccess === false)
137
+ return;
138
+ new aws.s3.BucketPublicAccessBlock(`${config.meta.environment}-${config.configuration.bucket}-block-public`, {
139
+ bucket: bucket.id,
140
+ blockPublicAcls: true,
141
+ blockPublicPolicy: true,
142
+ ignorePublicAcls: true,
143
+ restrictPublicBuckets: true,
144
+ }, provider ? { provider } : undefined);
145
+ }
146
+ async setupCloudFront(config, bucket, s3, provider, route53Provider) {
147
+ const cfConfig = config.configuration.cloudfront;
148
+ if (!cfConfig?.enabled)
149
+ return;
150
+ const envPrefix = `${config.meta.environment}-${config.id}`;
151
+ const oai = new aws.cloudfront.OriginAccessIdentity(`${envPrefix}-oai`, {}, provider ? { provider } : undefined);
152
+ new aws.s3.BucketPolicy(`${envPrefix}-policy`, {
153
+ bucket: bucket.id,
154
+ policy: pulumi.all([bucket.id, oai.iamArn]).apply(([id, iamArn]) => JSON.stringify({
155
+ Version: "2012-10-17",
156
+ Statement: [
157
+ {
158
+ Effect: "Allow",
159
+ Principal: { AWS: iamArn },
160
+ Action: ["s3:GetObject"],
161
+ Resource: `arn:aws:s3:::${config.configuration.bucket}/*`,
162
+ },
163
+ ],
164
+ })),
165
+ }, provider ? { provider } : undefined);
166
+ const usEast1Provider = config.inputs?.providers?.["dev-us-east-1"] || undefined;
167
+ let effectiveCertArn = cfConfig.acmCertificateArn;
168
+ const aliases = (cfConfig.aliases || [])
169
+ .map((a) => a.trim())
170
+ .filter((a) => !!a && !a.includes("*") && !a.includes("${"));
171
+ if ((!effectiveCertArn || effectiveCertArn === "") && aliases.length && cfConfig.enableCertProvisioning && config.meta.hostedZoneId) {
172
+ if (!usEast1Provider)
173
+ throw new Error("usEast1Provider required for ACM with CloudFront");
174
+ const cert = new aws.acm.Certificate(`${envPrefix}-cf-cert`, {
175
+ domainName: aliases[0],
176
+ subjectAlternativeNames: aliases.slice(1),
177
+ validationMethod: "DNS",
178
+ tags: cfConfig.tags || config.configuration.tags,
179
+ }, { provider: usEast1Provider });
180
+ const validationRecord = pulumi.all([cert.domainValidationOptions]).apply(([options]) => {
181
+ const opt = options[0];
182
+ return new aws.route53.Record(`${envPrefix}-cf-cert-validation`, {
183
+ name: opt.resourceRecordName,
184
+ zoneId: config.meta.hostedZoneId,
185
+ type: opt.resourceRecordType,
186
+ records: [opt.resourceRecordValue],
187
+ ttl: 300,
188
+ }, route53Provider ? { provider: route53Provider } : provider ? { provider } : undefined);
189
+ });
190
+ const certValidation = pulumi.all([cert.arn, cert.domainValidationOptions]).apply(([arn, options]) => {
191
+ const fqdns = options.map((o) => o.resourceRecordName);
192
+ return new aws.acm.CertificateValidation(`${envPrefix}-cf-cert-validate`, {
193
+ certificateArn: arn,
194
+ validationRecordFqdns: fqdns,
195
+ }, { provider: usEast1Provider });
196
+ });
197
+ effectiveCertArn = certValidation.apply((v) => v.certificateArn);
198
+ }
199
+ let effectiveWafArn = cfConfig.wafArn;
200
+ if ((!effectiveWafArn || effectiveWafArn === "") && (cfConfig.enableWaf || cfConfig.wafConfig?.enabled)) {
201
+ const wafName = `${envPrefix}-cf-waf`;
202
+ let wafConfig;
203
+ if (cfConfig.wafConfig?.customConfig) {
204
+ wafConfig = {
205
+ name: wafName,
206
+ scope: "CLOUDFRONT",
207
+ defaultAction: "allow",
208
+ ...cfConfig.wafConfig.customConfig,
209
+ };
210
+ }
211
+ else if (cfConfig.wafConfig?.useSecureDefaults !== false) {
212
+ wafConfig = wafFactory_1.WafFactory.createSecureWafConfig(wafName, "CLOUDFRONT");
213
+ if (cfConfig.wafConfig?.rateLimiting) {
214
+ wafConfig.rateLimiting = cfConfig.wafConfig.rateLimiting;
215
+ }
216
+ if (cfConfig.wafConfig?.ipRestrictions) {
217
+ wafConfig.ipRestrictions = cfConfig.wafConfig.ipRestrictions;
218
+ }
219
+ if (cfConfig.wafConfig?.geoRestrictions) {
220
+ wafConfig.geoRestrictions = cfConfig.wafConfig.geoRestrictions;
221
+ }
222
+ if (cfConfig.wafConfig?.managedRuleGroups) {
223
+ const managedRules = cfConfig.wafConfig.managedRuleGroups;
224
+ wafConfig.managedRuleGroups = [];
225
+ if (managedRules.enableCommonRules !== false) {
226
+ wafConfig.managedRuleGroups.push({
227
+ name: "AWSManagedRulesCommonRuleSet",
228
+ vendorName: "AWS",
229
+ priority: 10,
230
+ overrideAction: "count",
231
+ });
232
+ }
233
+ if (managedRules.enableKnownBadInputs !== false) {
234
+ wafConfig.managedRuleGroups.push({
235
+ name: "AWSManagedRulesKnownBadInputsRuleSet",
236
+ vendorName: "AWS",
237
+ priority: 20,
238
+ overrideAction: "count",
239
+ });
240
+ }
241
+ if (managedRules.enableSQLInjection !== false) {
242
+ wafConfig.managedRuleGroups.push({
243
+ name: "AWSManagedRulesSQLiRuleSet",
244
+ vendorName: "AWS",
245
+ priority: 30,
246
+ overrideAction: "count",
247
+ });
248
+ }
249
+ if (managedRules.enableIpReputation !== false) {
250
+ wafConfig.managedRuleGroups.push({
251
+ name: "AWSManagedRulesAmazonIpReputationList",
252
+ vendorName: "AWS",
253
+ priority: 50,
254
+ overrideAction: "count",
255
+ });
256
+ }
257
+ if (managedRules.enableAnonymousIp !== false) {
258
+ wafConfig.managedRuleGroups.push({
259
+ name: "AWSManagedRulesAnonymousIpList",
260
+ vendorName: "AWS",
261
+ priority: 60,
262
+ overrideAction: "count",
263
+ });
264
+ }
265
+ }
266
+ if (cfConfig.wafConfig?.customRules?.length) {
267
+ wafConfig.customRegexRules = cfConfig.wafConfig.customRules.map(rule => ({
268
+ name: rule.name,
269
+ priority: rule.priority,
270
+ regex: rule.regex || "/.*",
271
+ action: rule.action,
272
+ fieldToMatch: { type: "uri" },
273
+ }));
274
+ }
275
+ if (cfConfig.wafConfig?.logging) {
276
+ wafConfig.logging = cfConfig.wafConfig.logging;
277
+ }
278
+ }
279
+ else {
280
+ wafConfig = {
281
+ name: wafName,
282
+ scope: "CLOUDFRONT",
283
+ description: `WAF for CloudFront distribution ${envPrefix}`,
284
+ defaultAction: "allow",
285
+ rateLimiting: {
286
+ enabled: true,
287
+ limit: 2000,
288
+ action: "block",
289
+ },
290
+ visibilityConfig: {
291
+ cloudwatchMetricsEnabled: true,
292
+ sampledRequestsEnabled: true,
293
+ },
294
+ tags: cfConfig.tags || config.configuration.tags,
295
+ };
296
+ }
297
+ const waf = wafFactory_1.WafFactory.createWaf(wafConfig, usEast1Provider);
298
+ effectiveWafArn = waf.arn;
299
+ }
300
+ let loggingConfig;
301
+ const logBucket = cfConfig.logging?.bucket;
302
+ if (logBucket && !logBucket.includes("${")) {
303
+ try {
304
+ await s3.headBucket({ Bucket: logBucket }).promise();
305
+ loggingConfig = {
306
+ bucket: logBucket,
307
+ prefix: cfConfig.logging?.prefix,
308
+ includeCookies: cfConfig.logging?.includeCookies,
309
+ };
310
+ }
311
+ catch {
312
+ console.warn(`[WARNING] CloudFront logging bucket "${logBucket}" not accessible. Skipping logging.`);
313
+ }
314
+ }
315
+ const distribution = new aws.cloudfront.Distribution(`${envPrefix}-cf`, {
316
+ enabled: true,
317
+ origins: [
318
+ {
319
+ domainName: bucket.bucketRegionalDomainName,
320
+ originId: bucket.arn,
321
+ s3OriginConfig: {
322
+ originAccessIdentity: oai.cloudfrontAccessIdentityPath,
323
+ },
324
+ },
325
+ ],
326
+ defaultRootObject: cfConfig.defaultRootObject || config.configuration.website?.indexDocument || "index.html",
327
+ defaultCacheBehavior: {
328
+ targetOriginId: bucket.arn,
329
+ viewerProtocolPolicy: "redirect-to-https",
330
+ allowedMethods: ["GET", "HEAD"],
331
+ cachedMethods: ["GET", "HEAD"],
332
+ forwardedValues: {
333
+ queryString: false,
334
+ cookies: { forward: "none" },
335
+ },
336
+ },
337
+ aliases,
338
+ restrictions: {
339
+ geoRestriction: cfConfig.geoRestriction || { restrictionType: "none" },
340
+ },
341
+ viewerCertificate: effectiveCertArn
342
+ ? {
343
+ acmCertificateArn: effectiveCertArn,
344
+ sslSupportMethod: "sni-only",
345
+ }
346
+ : { cloudfrontDefaultCertificate: true },
347
+ priceClass: cfConfig.priceClass || "PriceClass_100",
348
+ customErrorResponses: cfConfig.customErrorResponses,
349
+ orderedCacheBehaviors: cfConfig.cacheBehaviors,
350
+ loggingConfig,
351
+ webAclId: effectiveWafArn,
352
+ tags: cfConfig.tags || config.configuration.tags,
353
+ }, provider ? { provider } : undefined);
354
+ bucket.cloudfrontDistribution = distribution;
355
+ return distribution.domainName;
356
+ }
357
+ createEventNotifications(config, bucket, provider) {
358
+ for (const notif of config.configuration.eventNotifications || []) {
359
+ new aws.s3.BucketNotification(`${config.meta.environment}-${config.configuration.bucket}-notif`, {
360
+ bucket: bucket.id,
361
+ ...notif,
362
+ }, provider ? { provider } : undefined);
363
+ }
364
+ }
365
+ setupMonitoring(config, bucket, provider) {
366
+ if (!config.configuration.monitoring?.enabled)
367
+ return;
368
+ const cfId = bucket.cloudfrontDistribution?.id;
369
+ bucket.monitoringResources = (0, buildAwsCloudWatchAlarmsHelper_1.buildAwsCloudWatchAlarmsHelper)(`${config.meta.environment}-${config.id}`, {
370
+ resourceType: "cloudfront",
371
+ resourceId: cfId,
372
+ alarms: config.configuration.monitoring.alarms || [],
373
+ alarmActions: config.configuration.monitoring.alarms?.map(a => a.alarmActionArn).filter((v) => typeof v === "string"),
374
+ okActions: config.configuration.monitoring.alarms?.map(a => a.okActionArn).filter((v) => typeof v === "string"),
375
+ tags: config.configuration.tags,
376
+ provider,
377
+ });
378
+ if (config.configuration.monitoring.dashboard) {
379
+ bucket.dashboardResource = (0, buildS3StaticHostingCloudWatchDashboardHelper_1.buildS3StaticHostingCloudWatchDashboardHelper)(`${config.meta.environment}-${config.id}`, {
380
+ bucketName: config.configuration.bucket,
381
+ cloudfrontDistributionId: cfId,
382
+ tags: config.configuration.tags,
383
+ }, provider);
384
+ }
385
+ }
386
+ setupCicd(config, bucket, artifactBucket, provider) {
387
+ const cicd = config.configuration.cicd;
388
+ if (!cicd?.enabled || !cicd.buildspecPath || !cicd.serviceRoleArn || !cicd.pipelineRoleArn)
389
+ return;
390
+ const cicdAny = cicd;
391
+ let repoOwner = cicdAny.repoOwner;
392
+ let repoName = cicdAny.repoName;
393
+ if ((!repoOwner || !repoName) && cicd.repo) {
394
+ const parts = cicd.repo.split("/");
395
+ if (parts.length === 2) {
396
+ repoOwner = repoOwner || parts[0];
397
+ repoName = repoName || parts[1];
398
+ }
399
+ else {
400
+ repoName = repoName || cicd.repo;
401
+ }
402
+ }
403
+ const cicdResources = (0, buildS3StaticHostingCicdHelper_1.buildS3StaticHostingCicdHelper)({
404
+ name: `${config.meta.environment}-${config.id}`,
405
+ artifactBucket: artifactBucket ? artifactBucket.bucket : cicd.artifactBucket,
406
+ buildspecPath: cicd.buildspecPath,
407
+ buildEnvironmentVariables: cicd.environmentVariables,
408
+ cloudfrontDistributionId: bucket.cloudfrontDistribution?.id,
409
+ bucketName: config.configuration.bucket,
410
+ provider,
411
+ serviceRoleArn: cicd.serviceRoleArn,
412
+ pipelineRoleArn: cicd.pipelineRoleArn,
413
+ repoOwner: repoOwner || "",
414
+ repoName: repoName || "",
415
+ branch: cicd.branch || "main",
416
+ codestarConnectionArn: cicd.codestarConnectionArn || "",
417
+ buildImage: cicd.buildImage,
418
+ buildTimeout: cicd.buildTimeout,
419
+ tags: cicd.tags,
420
+ });
421
+ bucket.cicdResources = cicdResources;
422
+ }
423
+ }
424
+ exports.S3StaticHostingFactory = S3StaticHostingFactory;