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.
- package/dist/src/core/config.js +2 -0
- package/dist/src/core/configMerge.js +266 -0
- package/dist/src/core/configUtils.js +72 -0
- package/dist/src/core/dependencyResolver.js +17 -0
- package/dist/src/core/deployUtils.js +73 -0
- package/dist/src/core/dynamicResourceManager.js +709 -0
- package/dist/src/core/entrypoint.js +56 -0
- package/dist/src/core/generateFinalConfig.js +45 -0
- package/dist/src/core/index.js +24 -0
- package/dist/src/core/resourceMap.js +99 -0
- package/dist/src/factories/accountPermissions.js +134 -0
- package/dist/src/factories/acmFactory.js +30 -0
- package/dist/src/factories/albFactory.js +331 -0
- package/dist/src/factories/attachSecretAccessPolicy.js +56 -0
- package/dist/src/factories/auroraFactory.js +619 -0
- package/dist/src/factories/backupPolicy.js +152 -0
- package/dist/src/factories/bastionFactory.js +91 -0
- package/dist/src/factories/bedrockFactory.js +334 -0
- package/dist/src/factories/budgetFactory.js +64 -0
- package/dist/src/factories/buildAlbCloudWatchAlarmsHelper.js +79 -0
- package/dist/src/factories/buildAlbCloudWatchDashboardHelper.js +106 -0
- package/dist/src/factories/buildAlbListenerRulesHelper.js +45 -0
- package/dist/src/factories/buildAlbListenersHelper.js +64 -0
- package/dist/src/factories/buildAlbResourceHelper.js +54 -0
- package/dist/src/factories/buildAlbRoute53RecordHelper.js +49 -0
- package/dist/src/factories/buildAlbTargetGroupsHelper.js +47 -0
- package/dist/src/factories/buildAlbWafAssociationHelper.js +43 -0
- package/dist/src/factories/buildAndPushDockerImage.js +57 -0
- package/dist/src/factories/buildAwsCloudWatchAlarmsHelper.js +118 -0
- package/dist/src/factories/buildCloudFrontRoute53RecordHelper.js +49 -0
- package/dist/src/factories/buildEcsClusterArgs.js +32 -0
- package/dist/src/factories/buildEcsSecrets.js +48 -0
- package/dist/src/factories/buildForceRedeployEnv.js +8 -0
- package/dist/src/factories/buildResourceOptions.js +11 -0
- package/dist/src/factories/buildS3StaticHostingCicdHelper.js +142 -0
- package/dist/src/factories/buildS3StaticHostingCloudWatchDashboardHelper.js +122 -0
- package/dist/src/factories/cloudTrailFactory.js +22 -0
- package/dist/src/factories/cloudWatchCompositeAlarmFactory.js +91 -0
- package/dist/src/factories/cloudWatchInsightsQueryFactory.js +83 -0
- package/dist/src/factories/cloudWatchLogGroupFactory.js +84 -0
- package/dist/src/factories/cloudfrontCodePipelineFactory.js +357 -0
- package/dist/src/factories/cloudwatchAlarmsFactory.js +121 -0
- package/dist/src/factories/codePipelineNotificationFactory.js +193 -0
- package/dist/src/factories/codePipelineNotificationRulesFactory.js +117 -0
- package/dist/src/factories/codeStarConnectionFactory.js +56 -0
- package/dist/src/factories/collectSecretKeys.js +18 -0
- package/dist/src/factories/comprehensiveNotificationFactory.js +250 -0
- package/dist/src/factories/costAndUsageReportFactory.js +32 -0
- package/dist/src/factories/createAwsAcmCertificate.js +40 -0
- package/dist/src/factories/createAwsBudget.js +40 -0
- package/dist/src/factories/createAwsCloudTrail.js +59 -0
- package/dist/src/factories/createAwsCloudwatchDashboard.js +59 -0
- package/dist/src/factories/createAwsEc2Instance.js +40 -0
- package/dist/src/factories/createAwsEventBridgeEventBus.js +40 -0
- package/dist/src/factories/createAwsGuardDutyDetector.js +40 -0
- package/dist/src/factories/createAwsGuardDutyDetectorFeature.js +45 -0
- package/dist/src/factories/createAwsGuardDutyFilter.js +46 -0
- package/dist/src/factories/createAwsGuardDutyPublishingDestination.js +50 -0
- package/dist/src/factories/createAwsHostedZone.js +40 -0
- package/dist/src/factories/createAwsIamRole.js +49 -0
- package/dist/src/factories/createAwsIamRoleInlinePolicies.js +48 -0
- package/dist/src/factories/createAwsIdentitystoreGroup.js +44 -0
- package/dist/src/factories/createAwsIdentitystoreGroupMembership.js +56 -0
- package/dist/src/factories/createAwsIdentitystoreUser.js +47 -0
- package/dist/src/factories/createAwsInspectorAssessmentTarget.js +47 -0
- package/dist/src/factories/createAwsInspectorDelegatedAdminAccount.js +47 -0
- package/dist/src/factories/createAwsInspectorEnabler.js +49 -0
- package/dist/src/factories/createAwsInspectorOrganizationConfiguration.js +55 -0
- package/dist/src/factories/createAwsKmsAliases.js +47 -0
- package/dist/src/factories/createAwsKmsKey.js +51 -0
- package/dist/src/factories/createAwsMacieAccount.js +45 -0
- package/dist/src/factories/createAwsMacieClassificationJob.js +53 -0
- package/dist/src/factories/createAwsMacieMember.js +49 -0
- package/dist/src/factories/createAwsMacieOrganizationConfiguration.js +44 -0
- package/dist/src/factories/createAwsRdsCluster.js +40 -0
- package/dist/src/factories/createAwsRdsClusterInstance.js +40 -0
- package/dist/src/factories/createAwsRdsInstance.js +40 -0
- package/dist/src/factories/createAwsRdsSubnetGroup.js +40 -0
- package/dist/src/factories/createAwsRoute53Record.js +40 -0
- package/dist/src/factories/createAwsSecret.js +40 -0
- package/dist/src/factories/createAwsSecretRotation.js +40 -0
- package/dist/src/factories/createAwsSecretVersion.js +40 -0
- package/dist/src/factories/createAwsSecurityGroup.js +40 -0
- package/dist/src/factories/createAwsSecurityGroupRule.js +40 -0
- package/dist/src/factories/createAwsSecurityHubAccount.js +40 -0
- package/dist/src/factories/createAwsSecurityHubAutomationRule.js +48 -0
- package/dist/src/factories/createAwsSecurityHubStandardsControl.js +44 -0
- package/dist/src/factories/createAwsSecurityHubStandardsSubscription.js +42 -0
- package/dist/src/factories/createAwsSesDomainDkim.js +40 -0
- package/dist/src/factories/createAwsSesDomainIdentity.js +40 -0
- package/dist/src/factories/createAwsSesEmailIdentity.js +40 -0
- package/dist/src/factories/createAwsSnsSubscription.js +62 -0
- package/dist/src/factories/createAwsSnsTopic.js +41 -0
- package/dist/src/factories/createAwsSqsQueue.js +40 -0
- package/dist/src/factories/createAwsSsmParameters.js +66 -0
- package/dist/src/factories/createAwsSsoAccountAssignment.js +66 -0
- package/dist/src/factories/createAwsSsoPermissionSet.js +64 -0
- package/dist/src/factories/createAwsStepFunctionsStateMachine.js +40 -0
- package/dist/src/factories/createBudget.js +56 -0
- package/dist/src/factories/createBudgetWithSnsAlert.js +79 -0
- package/dist/src/factories/createCostAndUsageReport.js +40 -0
- package/dist/src/factories/createEcrRepo.js +69 -0
- package/dist/src/factories/createEcsRolesAndPolicies.js +84 -0
- package/dist/src/factories/createEcsService.js +71 -0
- package/dist/src/factories/createEnvSecret.js +60 -0
- package/dist/src/factories/createGithubCodeStarConnection.js +44 -0
- package/dist/src/factories/createIamUserWithAccessKey.js +44 -0
- package/dist/src/factories/createLambdaFunction.js +89 -0
- package/dist/src/factories/createLambdaPermission.js +57 -0
- package/dist/src/factories/createListenerRule.js +68 -0
- package/dist/src/factories/createLogGroup.js +44 -0
- package/dist/src/factories/createSlackChannelConfiguration.js +49 -0
- package/dist/src/factories/createTargetGroup.js +50 -0
- package/dist/src/factories/createTaskDefinition.js +49 -0
- package/dist/src/factories/createVpcEndpoint.js +49 -0
- package/dist/src/factories/dashboardFactory.js +94 -0
- package/dist/src/factories/dataProtectionPolicyBuilder.js +103 -0
- package/dist/src/factories/ec2Factory.js +67 -0
- package/dist/src/factories/ecsClusterFactory.js +90 -0
- package/dist/src/factories/ecsCodePipelineFactory.js +308 -0
- package/dist/src/factories/ecsServiceFactory.js +350 -0
- package/dist/src/factories/enhancedCloudFrontCodePipelineFactory.js +205 -0
- package/dist/src/factories/enhancedEcsCodePipelineFactory.js +189 -0
- package/dist/src/factories/eventBridgeBusFactory.js +84 -0
- package/dist/src/factories/eventBridgeFactory.js +26 -0
- package/dist/src/factories/eventBridgeRuleFactory.js +114 -0
- package/dist/src/factories/fetchAllSecrets.js +51 -0
- package/dist/src/factories/getDeterministicPriority.js +13 -0
- package/dist/src/factories/getOrCreateSshKeyPair.js +57 -0
- package/dist/src/factories/guardDutyFactory.js +151 -0
- package/dist/src/factories/hostedZoneFactory.js +30 -0
- package/dist/src/factories/iamRoleFactory.js +29 -0
- package/dist/src/factories/inspectorFactory.js +109 -0
- package/dist/src/factories/kmsKeyFactory.js +32 -0
- package/dist/src/factories/lambdaFactory.js +133 -0
- package/dist/src/factories/lambdaPermissionFactory.js +32 -0
- package/dist/src/factories/logDataProtectionPolicyFactory.js +81 -0
- package/dist/src/factories/macieFactory.js +85 -0
- package/dist/src/factories/networkingFactory.js +429 -0
- package/dist/src/factories/opensearchCollectionFactory.js +109 -0
- package/dist/src/factories/organizationFactory.js +221 -0
- package/dist/src/factories/processReservedInstances.js +6 -0
- package/dist/src/factories/processSavingsPlans.js +43 -0
- package/dist/src/factories/rdsFactory.js +40 -0
- package/dist/src/factories/recordFactory.js +36 -0
- package/dist/src/factories/resolveEnvSecrets.js +14 -0
- package/dist/src/factories/resourceFactory.js +12 -0
- package/dist/src/factories/s3Factory.js +262 -0
- package/dist/src/factories/s3StaticHostingFactory.backup.js +424 -0
- package/dist/src/factories/s3StaticHostingFactory.js +348 -0
- package/dist/src/factories/s3StaticHostingFactory.refactored.js +334 -0
- package/dist/src/factories/savingsPlanFactory.js +26 -0
- package/dist/src/factories/secretsManagerFactory.js +107 -0
- package/dist/src/factories/securityGroupFactory.js +28 -0
- package/dist/src/factories/securityGroupRuleFactory.js +43 -0
- package/dist/src/factories/securityHubFactory.js +96 -0
- package/dist/src/factories/sesDomainDkimFactory.js +25 -0
- package/dist/src/factories/sesFactory.js +25 -0
- package/dist/src/factories/sesIdentitiesFactory.js +134 -0
- package/dist/src/factories/simpleNotificationFactory.js +112 -0
- package/dist/src/factories/smtpUserFactory.js +108 -0
- package/dist/src/factories/snsFactory.js +87 -0
- package/dist/src/factories/sqsFactory.js +41 -0
- package/dist/src/factories/ssmParameterFactory.js +67 -0
- package/dist/src/factories/ssoFactory.js +32 -0
- package/dist/src/factories/ssoGroupFactory.js +41 -0
- package/dist/src/factories/ssoPermissionSetFactory.js +29 -0
- package/dist/src/factories/ssoUserFactory.js +30 -0
- package/dist/src/factories/stepFunctionsFactory.js +32 -0
- package/dist/src/factories/tagPolicies.js +99 -0
- package/dist/src/factories/transformBudgetCostFilters.js +8 -0
- package/dist/src/factories/transformBudgetNotifications.js +12 -0
- package/dist/src/factories/transformBudgetPlannedLimits.js +8 -0
- package/dist/src/factories/types.js +2 -0
- package/dist/src/factories/validateAcmConfig.js +26 -0
- package/dist/src/factories/validateAuroraConfig.js +8 -0
- package/dist/src/factories/validateBedrockConfig.js +124 -0
- package/dist/src/factories/validateDashboardConfig.js +28 -0
- package/dist/src/factories/validateEventBridgeConfig.js +14 -0
- package/dist/src/factories/validateHostedZoneConfig.js +26 -0
- package/dist/src/factories/validateIamRoleConfig.js +8 -0
- package/dist/src/factories/validateKmsKeyConfig.js +8 -0
- package/dist/src/factories/validateRdsConfig.js +17 -0
- package/dist/src/factories/validateRoute53RecordConfig.js +41 -0
- package/dist/src/factories/validateS3Config.js +8 -0
- package/dist/src/factories/validateSecretsManagerConfig.js +8 -0
- package/dist/src/factories/validateSecurityGroupConfig.js +8 -0
- package/dist/src/factories/validateSecurityGroupRuleConfig.js +8 -0
- package/dist/src/factories/validateSesDomainDkimConfig.js +8 -0
- package/dist/src/factories/validateSesDomainIdentityConfig.js +8 -0
- package/dist/src/factories/validateSesIdentitiesConfig.js +40 -0
- package/dist/src/factories/validateSnsConfig.js +11 -0
- package/dist/src/factories/validateSqsConfig.js +11 -0
- package/dist/src/factories/validateSsmParameterFactoryConfig.js +9 -0
- package/dist/src/factories/validateStepFunctionsConfig.js +8 -0
- package/dist/src/factories/vpcEndpointFactory.js +98 -0
- package/dist/src/factories/wafFactory.js +499 -0
- package/package.json +71 -0
- package/scripts/copy-assets.js +136 -0
|
@@ -0,0 +1,348 @@
|
|
|
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 buildCloudFrontRoute53RecordHelper_1 = require("./buildCloudFrontRoute53RecordHelper");
|
|
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
|
+
const bucket = this.createS3Bucket(config, provider);
|
|
49
|
+
let cloudfrontDomain;
|
|
50
|
+
let distributionId;
|
|
51
|
+
if (config.configuration.cloudfront?.enabled) {
|
|
52
|
+
const route53Provider = this.resolveRoute53Provider(config, providerRegistry);
|
|
53
|
+
const { domain, distribution, route53Record } = await this.setupCloudFront(config, bucket, provider, route53Provider);
|
|
54
|
+
cloudfrontDomain = domain;
|
|
55
|
+
distributionId = distribution.id;
|
|
56
|
+
bucket.cloudfrontDomain = cloudfrontDomain;
|
|
57
|
+
bucket.distributionId = distributionId;
|
|
58
|
+
bucket.route53Record = route53Record;
|
|
59
|
+
}
|
|
60
|
+
this.setupMonitoring(config, bucket, distributionId, provider);
|
|
61
|
+
return bucket;
|
|
62
|
+
}
|
|
63
|
+
getOutputs(resource) {
|
|
64
|
+
return {
|
|
65
|
+
bucket: resource.bucket,
|
|
66
|
+
websiteUrl: resource.websiteUrl || resource.websiteEndpoint,
|
|
67
|
+
cloudfrontDomain: resource.cloudfrontDomain,
|
|
68
|
+
distributionId: resource.distributionId,
|
|
69
|
+
monitoringAlarmArns: resource.monitoringResources?.map((a) => a.arn),
|
|
70
|
+
dashboardName: resource.dashboardResource?.dashboardName,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
validateConfig(config) {
|
|
74
|
+
if (!config.configuration?.bucket) {
|
|
75
|
+
throw new Error("S3StaticHosting config must include bucket name");
|
|
76
|
+
}
|
|
77
|
+
const cf = config.configuration.cloudfront;
|
|
78
|
+
if (cf?.enabled && cf.enableCertProvisioning && cf.aliases?.length && !config.inputs?.hostedZoneId) {
|
|
79
|
+
throw new Error("hostedZoneId is required for ACM certificate provisioning");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
resolveRoute53Provider(config, registry) {
|
|
83
|
+
const ref = config.inputs?.route53Provider;
|
|
84
|
+
if (typeof ref === "object")
|
|
85
|
+
return ref;
|
|
86
|
+
if (typeof ref === "string") {
|
|
87
|
+
return registry[ref] || (() => {
|
|
88
|
+
throw new Error(`Route53 provider '${ref}' not found in registry`);
|
|
89
|
+
})();
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
createS3Bucket(config, provider) {
|
|
94
|
+
const { configuration } = config;
|
|
95
|
+
const envPrefix = `${config.meta.environment}-${configuration.bucket}`;
|
|
96
|
+
const bucket = new aws.s3.Bucket(envPrefix, {
|
|
97
|
+
bucket: configuration.bucket,
|
|
98
|
+
acl: configuration.acl || "private",
|
|
99
|
+
website: configuration.website,
|
|
100
|
+
tags: configuration.tags,
|
|
101
|
+
versioning: configuration.versioning ? { enabled: true } : undefined,
|
|
102
|
+
serverSideEncryptionConfiguration: configuration.encryption?.enabled ? {
|
|
103
|
+
rule: {
|
|
104
|
+
applyServerSideEncryptionByDefault: {
|
|
105
|
+
sseAlgorithm: configuration.encryption.type || "AES256",
|
|
106
|
+
kmsMasterKeyId: configuration.encryption.kmsKeyId,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
} : undefined,
|
|
110
|
+
corsRules: configuration.cors ? [configuration.cors] : undefined,
|
|
111
|
+
lifecycleRules: configuration.lifecycleRules,
|
|
112
|
+
forceDestroy: true,
|
|
113
|
+
}, provider ? { provider } : undefined);
|
|
114
|
+
if (configuration.blockPublicAccess !== false) {
|
|
115
|
+
new aws.s3.BucketPublicAccessBlock(`${envPrefix}-block-public`, {
|
|
116
|
+
bucket: bucket.id,
|
|
117
|
+
blockPublicAcls: true,
|
|
118
|
+
blockPublicPolicy: true,
|
|
119
|
+
ignorePublicAcls: true,
|
|
120
|
+
restrictPublicBuckets: true,
|
|
121
|
+
}, provider ? { provider } : undefined);
|
|
122
|
+
}
|
|
123
|
+
return bucket;
|
|
124
|
+
}
|
|
125
|
+
async setupCloudFront(config, bucket, provider, route53Provider) {
|
|
126
|
+
const cfConfig = config.configuration.cloudfront;
|
|
127
|
+
const envPrefix = `${config.meta.environment}-${config.id}`;
|
|
128
|
+
const oai = new aws.cloudfront.OriginAccessIdentity(`${envPrefix}-oai`, {
|
|
129
|
+
comment: `OAI for ${config.configuration.bucket}`,
|
|
130
|
+
}, provider ? { provider } : undefined);
|
|
131
|
+
new aws.s3.BucketPolicy(`${envPrefix}-cf-policy`, {
|
|
132
|
+
bucket: bucket.id,
|
|
133
|
+
policy: pulumi.all([bucket.id, oai.iamArn]).apply(([bucketId, iamArn]) => JSON.stringify({
|
|
134
|
+
Version: "2012-10-17",
|
|
135
|
+
Statement: [
|
|
136
|
+
{
|
|
137
|
+
Effect: "Allow",
|
|
138
|
+
Principal: { AWS: iamArn },
|
|
139
|
+
Action: ["s3:GetObject"],
|
|
140
|
+
Resource: `arn:aws:s3:::${config.configuration.bucket}/*`,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
})),
|
|
144
|
+
}, provider ? { provider } : undefined);
|
|
145
|
+
const certificateArn = await this.setupAcmCertificate(config, cfConfig, envPrefix, provider, route53Provider);
|
|
146
|
+
const webAclId = await this.setupWaf(config, cfConfig, envPrefix, provider);
|
|
147
|
+
const loggingConfig = this.prepareLoggingConfig(cfConfig);
|
|
148
|
+
const distribution = new aws.cloudfront.Distribution(`${envPrefix}-cf`, {
|
|
149
|
+
enabled: true,
|
|
150
|
+
origins: [
|
|
151
|
+
{
|
|
152
|
+
domainName: bucket.bucketRegionalDomainName,
|
|
153
|
+
originId: bucket.arn,
|
|
154
|
+
s3OriginConfig: {
|
|
155
|
+
originAccessIdentity: oai.cloudfrontAccessIdentityPath,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
defaultRootObject: cfConfig.defaultRootObject || config.configuration.website?.indexDocument || "index.html",
|
|
160
|
+
defaultCacheBehavior: {
|
|
161
|
+
targetOriginId: bucket.arn,
|
|
162
|
+
viewerProtocolPolicy: "redirect-to-https",
|
|
163
|
+
allowedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
164
|
+
cachedMethods: ["GET", "HEAD"],
|
|
165
|
+
forwardedValues: {
|
|
166
|
+
queryString: false,
|
|
167
|
+
cookies: { forward: "none" },
|
|
168
|
+
headers: ["Origin", "Access-Control-Request-Headers", "Access-Control-Request-Method"],
|
|
169
|
+
},
|
|
170
|
+
compress: true,
|
|
171
|
+
minTtl: 0,
|
|
172
|
+
defaultTtl: 86400,
|
|
173
|
+
maxTtl: 31536000,
|
|
174
|
+
},
|
|
175
|
+
aliases: cfConfig.aliases?.filter(alias => alias && !alias.includes("${")) || [],
|
|
176
|
+
restrictions: {
|
|
177
|
+
geoRestriction: cfConfig.geoRestriction || { restrictionType: "none" },
|
|
178
|
+
},
|
|
179
|
+
viewerCertificate: certificateArn ? {
|
|
180
|
+
acmCertificateArn: certificateArn,
|
|
181
|
+
sslSupportMethod: "sni-only",
|
|
182
|
+
minimumProtocolVersion: "TLSv1.2_2021",
|
|
183
|
+
} : {
|
|
184
|
+
cloudfrontDefaultCertificate: true
|
|
185
|
+
},
|
|
186
|
+
priceClass: cfConfig.priceClass || "PriceClass_100",
|
|
187
|
+
customErrorResponses: cfConfig.customErrorResponses || [
|
|
188
|
+
{
|
|
189
|
+
errorCode: 404,
|
|
190
|
+
responseCode: 200,
|
|
191
|
+
responsePagePath: "/index.html",
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
errorCode: 403,
|
|
195
|
+
responseCode: 200,
|
|
196
|
+
responsePagePath: "/index.html",
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
orderedCacheBehaviors: cfConfig.cacheBehaviors,
|
|
200
|
+
loggingConfig,
|
|
201
|
+
webAclId,
|
|
202
|
+
tags: cfConfig.tags || config.configuration.tags,
|
|
203
|
+
comment: `CloudFront distribution for ${config.configuration.bucket}`,
|
|
204
|
+
}, provider ? { provider } : undefined);
|
|
205
|
+
let route53Record;
|
|
206
|
+
if (cfConfig.aliases?.length && config.inputs?.hostedZoneId) {
|
|
207
|
+
const primaryAlias = cfConfig.aliases[0];
|
|
208
|
+
if (primaryAlias && !primaryAlias.includes("$")) {
|
|
209
|
+
route53Record = (0, buildCloudFrontRoute53RecordHelper_1.buildCloudFrontRoute53RecordHelper)(envPrefix, primaryAlias, config.inputs.hostedZoneId, distribution.domainName, distribution.hostedZoneId, route53Provider);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return { domain: distribution.domainName, distribution, route53Record };
|
|
213
|
+
}
|
|
214
|
+
async setupAcmCertificate(config, cfConfig, envPrefix, provider, route53Provider) {
|
|
215
|
+
if (cfConfig.acmCertificateArn) {
|
|
216
|
+
return cfConfig.acmCertificateArn;
|
|
217
|
+
}
|
|
218
|
+
if (!cfConfig.enableCertProvisioning || !cfConfig.aliases?.length || !config.inputs?.hostedZoneId) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
const usEast1Provider = config.inputs?.providers?.["dev-us-east-1"];
|
|
222
|
+
if (!usEast1Provider) {
|
|
223
|
+
throw new Error("US East 1 provider required for ACM certificate with CloudFront");
|
|
224
|
+
}
|
|
225
|
+
const aliases = cfConfig.aliases.filter(alias => alias && !alias.includes("$"));
|
|
226
|
+
const cert = new aws.acm.Certificate(`${envPrefix}-cert`, {
|
|
227
|
+
domainName: aliases[0],
|
|
228
|
+
subjectAlternativeNames: aliases.slice(1),
|
|
229
|
+
validationMethod: "DNS",
|
|
230
|
+
tags: cfConfig.tags || config.configuration.tags,
|
|
231
|
+
}, { provider: usEast1Provider });
|
|
232
|
+
const validationRecords = cert.domainValidationOptions.apply(options => options.map((option, index) => new aws.route53.Record(`${envPrefix}-cert-validation-${index}`, {
|
|
233
|
+
name: option.resourceRecordName,
|
|
234
|
+
zoneId: config.inputs.hostedZoneId,
|
|
235
|
+
type: option.resourceRecordType,
|
|
236
|
+
records: [option.resourceRecordValue],
|
|
237
|
+
ttl: 300,
|
|
238
|
+
}, route53Provider ? { provider: route53Provider } : undefined)));
|
|
239
|
+
const certValidation = new aws.acm.CertificateValidation(`${envPrefix}-cert-validation`, {
|
|
240
|
+
certificateArn: cert.arn,
|
|
241
|
+
validationRecordFqdns: validationRecords.apply(records => records.map(record => record.fqdn)),
|
|
242
|
+
}, { provider: usEast1Provider });
|
|
243
|
+
return certValidation.certificateArn;
|
|
244
|
+
}
|
|
245
|
+
async setupWaf(config, cfConfig, envPrefix, provider) {
|
|
246
|
+
if (!cfConfig.enableWaf || cfConfig.wafArn) {
|
|
247
|
+
return cfConfig.wafArn;
|
|
248
|
+
}
|
|
249
|
+
const wafConfig = cfConfig.wafConfig;
|
|
250
|
+
if (!wafConfig?.enabled) {
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
const usEast1Provider = config.inputs?.providers?.["dev-us-east-1"];
|
|
254
|
+
if (!usEast1Provider) {
|
|
255
|
+
throw new Error("US East 1 provider required for WAF with CloudFront");
|
|
256
|
+
}
|
|
257
|
+
const wafName = `${envPrefix}-waf`;
|
|
258
|
+
const wafFactoryConfig = {
|
|
259
|
+
name: wafName,
|
|
260
|
+
scope: "CLOUDFRONT",
|
|
261
|
+
description: `WAF for CloudFront distribution ${envPrefix}`,
|
|
262
|
+
defaultAction: "allow",
|
|
263
|
+
rateLimiting: {
|
|
264
|
+
enabled: true,
|
|
265
|
+
limit: wafConfig.rateLimitRpm || 1000,
|
|
266
|
+
action: "block",
|
|
267
|
+
},
|
|
268
|
+
geoRestrictions: wafConfig.geoBlockedCountries?.length ? {
|
|
269
|
+
blockedCountries: wafConfig.geoBlockedCountries,
|
|
270
|
+
} : undefined,
|
|
271
|
+
managedRuleGroups: wafConfig.enableManagedRules !== false ? [
|
|
272
|
+
{
|
|
273
|
+
name: "AWSManagedRulesCommonRuleSet",
|
|
274
|
+
vendorName: "AWS",
|
|
275
|
+
priority: 10,
|
|
276
|
+
overrideAction: "count",
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
name: "AWSManagedRulesKnownBadInputsRuleSet",
|
|
280
|
+
vendorName: "AWS",
|
|
281
|
+
priority: 20,
|
|
282
|
+
overrideAction: "count",
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "AWSManagedRulesAmazonIpReputationList",
|
|
286
|
+
vendorName: "AWS",
|
|
287
|
+
priority: 30,
|
|
288
|
+
overrideAction: "count",
|
|
289
|
+
},
|
|
290
|
+
] : [],
|
|
291
|
+
customRegexRules: wafConfig.customRules?.map(rule => ({
|
|
292
|
+
name: rule.name,
|
|
293
|
+
priority: rule.priority,
|
|
294
|
+
regex: rule.regex || "/.*",
|
|
295
|
+
action: rule.action,
|
|
296
|
+
fieldToMatch: { type: "uri" },
|
|
297
|
+
})),
|
|
298
|
+
logging: {
|
|
299
|
+
enabled: true,
|
|
300
|
+
logGroupName: `aws-waf-logs-${wafName}`,
|
|
301
|
+
retentionDays: 365,
|
|
302
|
+
},
|
|
303
|
+
visibilityConfig: {
|
|
304
|
+
cloudwatchMetricsEnabled: true,
|
|
305
|
+
sampledRequestsEnabled: true,
|
|
306
|
+
},
|
|
307
|
+
tags: cfConfig.tags || config.configuration.tags,
|
|
308
|
+
};
|
|
309
|
+
const waf = wafFactory_1.WafFactory.createWaf(wafFactoryConfig, usEast1Provider);
|
|
310
|
+
return waf.arn;
|
|
311
|
+
}
|
|
312
|
+
prepareLoggingConfig(cfConfig) {
|
|
313
|
+
const logging = cfConfig.logging;
|
|
314
|
+
if (!logging?.enabled || !logging.bucket) {
|
|
315
|
+
return undefined;
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
bucket: logging.bucket,
|
|
319
|
+
prefix: logging.prefix || "",
|
|
320
|
+
includeCookies: logging.includeCookies || false,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
setupMonitoring(config, bucket, distributionId, provider) {
|
|
324
|
+
const monitoring = config.configuration.monitoring;
|
|
325
|
+
if (!monitoring?.enabled)
|
|
326
|
+
return;
|
|
327
|
+
if (monitoring.alarms?.length && distributionId) {
|
|
328
|
+
const distributionIdString = distributionId.apply ? distributionId.apply(id => id) : distributionId;
|
|
329
|
+
bucket.monitoringResources = (0, buildAwsCloudWatchAlarmsHelper_1.buildAwsCloudWatchAlarmsHelper)(`${config.meta.environment}-${config.id}`, {
|
|
330
|
+
resourceType: "cloudfront",
|
|
331
|
+
resourceId: distributionIdString,
|
|
332
|
+
alarms: monitoring.alarms,
|
|
333
|
+
alarmActions: monitoring.alarms.map(a => a.alarmActionArn).filter((v) => typeof v === "string"),
|
|
334
|
+
okActions: monitoring.alarms.map(a => a.okActionArn).filter((v) => typeof v === "string"),
|
|
335
|
+
tags: config.configuration.tags,
|
|
336
|
+
provider,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
if (monitoring.dashboard) {
|
|
340
|
+
bucket.dashboardResource = (0, buildS3StaticHostingCloudWatchDashboardHelper_1.buildS3StaticHostingCloudWatchDashboardHelper)(`${config.meta.environment}-${config.id}`, {
|
|
341
|
+
bucketName: config.configuration.bucket,
|
|
342
|
+
cloudfrontDistributionId: distributionId,
|
|
343
|
+
tags: config.configuration.tags,
|
|
344
|
+
}, provider);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
exports.S3StaticHostingFactory = S3StaticHostingFactory;
|
|
@@ -0,0 +1,334 @@
|
|
|
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 wafFactory_1 = require("./wafFactory");
|
|
43
|
+
class S3StaticHostingFactory extends resourceFactory_1.ResourceFactory {
|
|
44
|
+
static supportsProviderRegistry = true;
|
|
45
|
+
async createResource(config, provider, providerRegistry = {}) {
|
|
46
|
+
this.validateConfig(config);
|
|
47
|
+
const bucket = this.createS3Bucket(config, provider);
|
|
48
|
+
let cloudfrontDomain;
|
|
49
|
+
let distributionId;
|
|
50
|
+
if (config.configuration.cloudfront?.enabled) {
|
|
51
|
+
const route53Provider = this.resolveRoute53Provider(config, providerRegistry);
|
|
52
|
+
const { domain, distribution } = await this.setupCloudFront(config, bucket, provider, route53Provider);
|
|
53
|
+
cloudfrontDomain = domain;
|
|
54
|
+
distributionId = distribution.id;
|
|
55
|
+
bucket.cloudfrontDomain = cloudfrontDomain;
|
|
56
|
+
bucket.distributionId = distributionId;
|
|
57
|
+
}
|
|
58
|
+
this.setupMonitoring(config, bucket, distributionId, provider);
|
|
59
|
+
return bucket;
|
|
60
|
+
}
|
|
61
|
+
getOutputs(resource) {
|
|
62
|
+
return {
|
|
63
|
+
bucket: resource.bucket,
|
|
64
|
+
websiteUrl: resource.websiteUrl || resource.websiteEndpoint,
|
|
65
|
+
cloudfrontDomain: resource.cloudfrontDomain,
|
|
66
|
+
distributionId: resource.distributionId,
|
|
67
|
+
monitoringAlarmArns: resource.monitoringResources?.map((a) => a.arn),
|
|
68
|
+
dashboardName: resource.dashboardResource?.dashboardName,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
validateConfig(config) {
|
|
72
|
+
if (!config.configuration?.bucket) {
|
|
73
|
+
throw new Error("S3StaticHosting config must include bucket name");
|
|
74
|
+
}
|
|
75
|
+
const cf = config.configuration.cloudfront;
|
|
76
|
+
if (cf?.enabled && cf.enableCertProvisioning && cf.aliases?.length && !config.inputs?.hostedZoneId) {
|
|
77
|
+
throw new Error("hostedZoneId is required for ACM certificate provisioning");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
resolveRoute53Provider(config, registry) {
|
|
81
|
+
const ref = config.inputs?.route53Provider;
|
|
82
|
+
if (typeof ref === "object")
|
|
83
|
+
return ref;
|
|
84
|
+
if (typeof ref === "string") {
|
|
85
|
+
return registry[ref] || (() => {
|
|
86
|
+
throw new Error(`Route53 provider '${ref}' not found in registry`);
|
|
87
|
+
})();
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
createS3Bucket(config, provider) {
|
|
92
|
+
const { configuration } = config;
|
|
93
|
+
const envPrefix = `${config.meta.environment}-${configuration.bucket}`;
|
|
94
|
+
const bucket = new aws.s3.Bucket(envPrefix, {
|
|
95
|
+
bucket: configuration.bucket,
|
|
96
|
+
acl: configuration.acl || "private",
|
|
97
|
+
website: configuration.website,
|
|
98
|
+
tags: configuration.tags,
|
|
99
|
+
versioning: configuration.versioning ? { enabled: true } : undefined,
|
|
100
|
+
serverSideEncryptionConfiguration: configuration.encryption?.enabled ? {
|
|
101
|
+
rule: {
|
|
102
|
+
applyServerSideEncryptionByDefault: {
|
|
103
|
+
sseAlgorithm: configuration.encryption.type || "AES256",
|
|
104
|
+
kmsMasterKeyId: configuration.encryption.kmsKeyId,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
} : undefined,
|
|
108
|
+
corsRules: configuration.cors ? [configuration.cors] : undefined,
|
|
109
|
+
lifecycleRules: configuration.lifecycleRules,
|
|
110
|
+
forceDestroy: true,
|
|
111
|
+
}, provider ? { provider } : undefined);
|
|
112
|
+
if (configuration.blockPublicAccess !== false) {
|
|
113
|
+
new aws.s3.BucketPublicAccessBlock(`${envPrefix}-block-public`, {
|
|
114
|
+
bucket: bucket.id,
|
|
115
|
+
blockPublicAcls: true,
|
|
116
|
+
blockPublicPolicy: true,
|
|
117
|
+
ignorePublicAcls: true,
|
|
118
|
+
restrictPublicBuckets: true,
|
|
119
|
+
}, provider ? { provider } : undefined);
|
|
120
|
+
}
|
|
121
|
+
return bucket;
|
|
122
|
+
}
|
|
123
|
+
async setupCloudFront(config, bucket, provider, route53Provider) {
|
|
124
|
+
const cfConfig = config.configuration.cloudfront;
|
|
125
|
+
const envPrefix = `${config.meta.environment}-${config.id}`;
|
|
126
|
+
const oai = new aws.cloudfront.OriginAccessIdentity(`${envPrefix}-oai`, {
|
|
127
|
+
comment: `OAI for ${config.configuration.bucket}`,
|
|
128
|
+
}, provider ? { provider } : undefined);
|
|
129
|
+
new aws.s3.BucketPolicy(`${envPrefix}-cf-policy`, {
|
|
130
|
+
bucket: bucket.id,
|
|
131
|
+
policy: pulumi.all([bucket.id, oai.iamArn]).apply(([bucketId, iamArn]) => JSON.stringify({
|
|
132
|
+
Version: "2012-10-17",
|
|
133
|
+
Statement: [
|
|
134
|
+
{
|
|
135
|
+
Effect: "Allow",
|
|
136
|
+
Principal: { AWS: iamArn },
|
|
137
|
+
Action: ["s3:GetObject"],
|
|
138
|
+
Resource: `arn:aws:s3:::${config.configuration.bucket}/*`,
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
})),
|
|
142
|
+
}, provider ? { provider } : undefined);
|
|
143
|
+
const certificateArn = await this.setupAcmCertificate(config, cfConfig, envPrefix, provider, route53Provider);
|
|
144
|
+
const webAclId = await this.setupWaf(config, cfConfig, envPrefix, provider);
|
|
145
|
+
const loggingConfig = this.prepareLoggingConfig(cfConfig);
|
|
146
|
+
const distribution = new aws.cloudfront.Distribution(`${envPrefix}-cf`, {
|
|
147
|
+
enabled: true,
|
|
148
|
+
origins: [
|
|
149
|
+
{
|
|
150
|
+
domainName: bucket.bucketRegionalDomainName,
|
|
151
|
+
originId: bucket.arn,
|
|
152
|
+
s3OriginConfig: {
|
|
153
|
+
originAccessIdentity: oai.cloudfrontAccessIdentityPath,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
defaultRootObject: cfConfig.defaultRootObject || config.configuration.website?.indexDocument || "index.html",
|
|
158
|
+
defaultCacheBehavior: {
|
|
159
|
+
targetOriginId: bucket.arn,
|
|
160
|
+
viewerProtocolPolicy: "redirect-to-https",
|
|
161
|
+
allowedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
162
|
+
cachedMethods: ["GET", "HEAD"],
|
|
163
|
+
forwardedValues: {
|
|
164
|
+
queryString: false,
|
|
165
|
+
cookies: { forward: "none" },
|
|
166
|
+
headers: ["Origin", "Access-Control-Request-Headers", "Access-Control-Request-Method"],
|
|
167
|
+
},
|
|
168
|
+
compress: true,
|
|
169
|
+
minTtl: 0,
|
|
170
|
+
defaultTtl: 86400,
|
|
171
|
+
maxTtl: 31536000,
|
|
172
|
+
},
|
|
173
|
+
aliases: cfConfig.aliases?.filter(alias => alias && !alias.includes("${")) || [],
|
|
174
|
+
restrictions: {
|
|
175
|
+
geoRestriction: cfConfig.geoRestriction || { restrictionType: "none" },
|
|
176
|
+
},
|
|
177
|
+
viewerCertificate: certificateArn ? {
|
|
178
|
+
acmCertificateArn: certificateArn,
|
|
179
|
+
sslSupportMethod: "sni-only",
|
|
180
|
+
minimumProtocolVersion: "TLSv1.2_2021",
|
|
181
|
+
} : {
|
|
182
|
+
cloudfrontDefaultCertificate: true
|
|
183
|
+
},
|
|
184
|
+
priceClass: cfConfig.priceClass || "PriceClass_100",
|
|
185
|
+
customErrorResponses: cfConfig.customErrorResponses || [
|
|
186
|
+
{
|
|
187
|
+
errorCode: 404,
|
|
188
|
+
responseCode: 200,
|
|
189
|
+
responsePagePath: "/index.html",
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
errorCode: 403,
|
|
193
|
+
responseCode: 200,
|
|
194
|
+
responsePagePath: "/index.html",
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
orderedCacheBehaviors: cfConfig.cacheBehaviors,
|
|
198
|
+
loggingConfig,
|
|
199
|
+
webAclId,
|
|
200
|
+
tags: cfConfig.tags || config.configuration.tags,
|
|
201
|
+
comment: `CloudFront distribution for ${config.configuration.bucket}`,
|
|
202
|
+
}, provider ? { provider } : undefined);
|
|
203
|
+
return { domain: distribution.domainName, distribution };
|
|
204
|
+
}
|
|
205
|
+
async setupAcmCertificate(config, cfConfig, envPrefix, provider, route53Provider) {
|
|
206
|
+
if (cfConfig.acmCertificateArn) {
|
|
207
|
+
return cfConfig.acmCertificateArn;
|
|
208
|
+
}
|
|
209
|
+
if (!cfConfig.enableCertProvisioning || !cfConfig.aliases?.length || !config.inputs?.hostedZoneId) {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
const usEast1Provider = config.inputs?.providers?.["dev-us-east-1"];
|
|
213
|
+
if (!usEast1Provider) {
|
|
214
|
+
throw new Error("US East 1 provider required for ACM certificate with CloudFront");
|
|
215
|
+
}
|
|
216
|
+
const aliases = cfConfig.aliases.filter(alias => alias && !alias.includes("$"));
|
|
217
|
+
const cert = new aws.acm.Certificate(`${envPrefix}-cert`, {
|
|
218
|
+
domainName: aliases[0],
|
|
219
|
+
subjectAlternativeNames: aliases.slice(1),
|
|
220
|
+
validationMethod: "DNS",
|
|
221
|
+
tags: cfConfig.tags || config.configuration.tags,
|
|
222
|
+
}, { provider: usEast1Provider });
|
|
223
|
+
const validationRecords = cert.domainValidationOptions.apply(options => options.map((option, index) => new aws.route53.Record(`${envPrefix}-cert-validation-${index}`, {
|
|
224
|
+
name: option.resourceRecordName,
|
|
225
|
+
zoneId: config.inputs.hostedZoneId,
|
|
226
|
+
type: option.resourceRecordType,
|
|
227
|
+
records: [option.resourceRecordValue],
|
|
228
|
+
ttl: 300,
|
|
229
|
+
}, route53Provider ? { provider: route53Provider } : undefined)));
|
|
230
|
+
const certValidation = new aws.acm.CertificateValidation(`${envPrefix}-cert-validation`, {
|
|
231
|
+
certificateArn: cert.arn,
|
|
232
|
+
validationRecordFqdns: validationRecords.apply(records => records.map(record => record.fqdn)),
|
|
233
|
+
}, { provider: usEast1Provider });
|
|
234
|
+
return certValidation.certificateArn;
|
|
235
|
+
}
|
|
236
|
+
async setupWaf(config, cfConfig, envPrefix, provider) {
|
|
237
|
+
if (!cfConfig.enableWaf || cfConfig.wafArn) {
|
|
238
|
+
return cfConfig.wafArn;
|
|
239
|
+
}
|
|
240
|
+
const wafConfig = cfConfig.wafConfig;
|
|
241
|
+
if (!wafConfig?.enabled) {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
const usEast1Provider = config.inputs?.providers?.["dev-us-east-1"];
|
|
245
|
+
if (!usEast1Provider) {
|
|
246
|
+
throw new Error("US East 1 provider required for WAF with CloudFront");
|
|
247
|
+
}
|
|
248
|
+
const wafName = `${envPrefix}-waf`;
|
|
249
|
+
const wafFactoryConfig = {
|
|
250
|
+
name: wafName,
|
|
251
|
+
scope: "CLOUDFRONT",
|
|
252
|
+
description: `WAF for CloudFront distribution ${envPrefix}`,
|
|
253
|
+
defaultAction: "allow",
|
|
254
|
+
rateLimiting: {
|
|
255
|
+
enabled: true,
|
|
256
|
+
limit: wafConfig.rateLimitRpm || 1000,
|
|
257
|
+
action: "block",
|
|
258
|
+
},
|
|
259
|
+
geoRestrictions: wafConfig.geoBlockedCountries?.length ? {
|
|
260
|
+
blockedCountries: wafConfig.geoBlockedCountries,
|
|
261
|
+
} : undefined,
|
|
262
|
+
managedRuleGroups: wafConfig.enableManagedRules !== false ? [
|
|
263
|
+
{
|
|
264
|
+
name: "AWSManagedRulesCommonRuleSet",
|
|
265
|
+
vendorName: "AWS",
|
|
266
|
+
priority: 10,
|
|
267
|
+
overrideAction: "count",
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
name: "AWSManagedRulesKnownBadInputsRuleSet",
|
|
271
|
+
vendorName: "AWS",
|
|
272
|
+
priority: 20,
|
|
273
|
+
overrideAction: "count",
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
name: "AWSManagedRulesAmazonIpReputationList",
|
|
277
|
+
vendorName: "AWS",
|
|
278
|
+
priority: 30,
|
|
279
|
+
overrideAction: "count",
|
|
280
|
+
},
|
|
281
|
+
] : [],
|
|
282
|
+
customRegexRules: wafConfig.customRules?.map(rule => ({
|
|
283
|
+
name: rule.name,
|
|
284
|
+
priority: rule.priority,
|
|
285
|
+
regex: rule.regex || "/.*",
|
|
286
|
+
action: rule.action,
|
|
287
|
+
fieldToMatch: { type: "uri" },
|
|
288
|
+
})),
|
|
289
|
+
visibilityConfig: {
|
|
290
|
+
cloudwatchMetricsEnabled: true,
|
|
291
|
+
sampledRequestsEnabled: true,
|
|
292
|
+
},
|
|
293
|
+
tags: cfConfig.tags || config.configuration.tags,
|
|
294
|
+
};
|
|
295
|
+
const waf = wafFactory_1.WafFactory.createWaf(wafFactoryConfig, usEast1Provider);
|
|
296
|
+
return waf.arn;
|
|
297
|
+
}
|
|
298
|
+
prepareLoggingConfig(cfConfig) {
|
|
299
|
+
const logging = cfConfig.logging;
|
|
300
|
+
if (!logging?.bucket || logging.bucket.includes("${")) {
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
bucket: logging.bucket,
|
|
305
|
+
prefix: logging.prefix || "",
|
|
306
|
+
includeCookies: logging.includeCookies || false,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
setupMonitoring(config, bucket, distributionId, provider) {
|
|
310
|
+
const monitoring = config.configuration.monitoring;
|
|
311
|
+
if (!monitoring?.enabled)
|
|
312
|
+
return;
|
|
313
|
+
if (monitoring.alarms?.length && distributionId) {
|
|
314
|
+
const distributionIdString = distributionId.apply ? distributionId.apply(id => id) : distributionId;
|
|
315
|
+
bucket.monitoringResources = (0, buildAwsCloudWatchAlarmsHelper_1.buildAwsCloudWatchAlarmsHelper)(`${config.meta.environment}-${config.id}`, {
|
|
316
|
+
resourceType: "cloudfront",
|
|
317
|
+
resourceId: distributionIdString,
|
|
318
|
+
alarms: monitoring.alarms,
|
|
319
|
+
alarmActions: monitoring.alarms.map(a => a.alarmActionArn).filter((v) => typeof v === "string"),
|
|
320
|
+
okActions: monitoring.alarms.map(a => a.okActionArn).filter((v) => typeof v === "string"),
|
|
321
|
+
tags: config.configuration.tags,
|
|
322
|
+
provider,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
if (monitoring.dashboard) {
|
|
326
|
+
bucket.dashboardResource = (0, buildS3StaticHostingCloudWatchDashboardHelper_1.buildS3StaticHostingCloudWatchDashboardHelper)(`${config.meta.environment}-${config.id}`, {
|
|
327
|
+
bucketName: config.configuration.bucket,
|
|
328
|
+
cloudfrontDistributionId: distributionId,
|
|
329
|
+
tags: config.configuration.tags,
|
|
330
|
+
}, provider);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
exports.S3StaticHostingFactory = S3StaticHostingFactory;
|