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,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;
|