UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 5.1 kB
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.DeployCdkStackAction=void 0;const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var fs=()=>{var tmp=require("fs");return fs=()=>tmp,tmp},path=()=>{var tmp=require("path");return path=()=>tmp,tmp},constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},cpactions=()=>{var tmp=require("../../../../aws-codepipeline-actions");return cpactions=()=>tmp,tmp},iam=()=>{var tmp=require("../../../../aws-iam");return iam=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../../core");return core_1=()=>tmp,tmp},cxapi=()=>{var tmp=require("../../../../cx-api");return cxapi=()=>tmp,tmp},construct_internals_1=()=>{var tmp=require("../../private/construct-internals");return construct_internals_1=()=>tmp,tmp},fs_1=()=>{var tmp=require("../../private/fs");return fs_1=()=>tmp,tmp};class DeployCdkStackAction{static fromStackArtifact(scope,artifact,options){if(!artifact.assumeRoleArn)throw new Error(`Stack '${artifact.stackName}' does not have deployment role information; use the 'DefaultStackSynthesizer' synthesizer, or set the '@aws-cdk/core:newStyleStackSynthesis' context key.`);const artRegion=artifact.environment.region,region=artRegion===core_1().Stack.of(scope).region||artRegion===cxapi().UNKNOWN_REGION?void 0:artRegion,artAccount=artifact.environment.account,account=artAccount===core_1().Stack.of(scope).account||artAccount===cxapi().UNKNOWN_ACCOUNT?void 0:artAccount,actionRole=roleFromPlaceholderArn(scope,region,account,artifact.assumeRoleArn),cloudFormationExecutionRole=roleFromPlaceholderArn(scope,region,account,artifact.cloudFormationExecutionRoleArn),appAsmRoot=(0,construct_internals_1().assemblyBuilderOf)((0,construct_internals_1().appOf)(scope)).outdir,fullTemplatePath=path().join(artifact.assembly.directory,artifact.templateFile);let fullConfigPath;return Object.keys(artifact.tags).length>0&&(fullConfigPath=`${fullTemplatePath}.config.json`,writeTemplateConfiguration(fullConfigPath,{Tags:artifact.tags})),new DeployCdkStackAction({actionRole,cloudFormationExecutionRole,templatePath:(0,fs_1().toPosixPath)(path().relative(appAsmRoot,fullTemplatePath)),templateConfigurationPath:fullConfigPath?(0,fs_1().toPosixPath)(path().relative(appAsmRoot,fullConfigPath)):void 0,region,stackArtifactId:artifact.id,dependencyStackArtifactIds:artifact.dependencies.filter(isStackArtifact).map(s=>s.id),stackName:options.stackName??artifact.stackName,...options})}constructor(props){if(props.output&&!props.outputFileName)throw new Error("If 'output' is set, 'outputFileName' is also required");this.stackArtifactId=props.stackArtifactId,this.dependencyStackArtifactIds=props.dependencyStackArtifactIds??[],this.prepareRunOrder=props.prepareRunOrder??1,this.executeRunOrder=props.executeRunOrder??this.prepareRunOrder+1,this.stackName=props.stackName;const baseActionName=props.baseActionName??this.stackName,changeSetName=props.changeSetName??"PipelineChange";this.prepareChangeSetAction=new(cpactions()).CloudFormationCreateReplaceChangeSetAction({actionName:`${baseActionName}.Prepare`,changeSetName,runOrder:this.prepareRunOrder,stackName:this.stackName,templatePath:props.cloudAssemblyInput.atPath(props.templatePath),adminPermissions:!1,role:props.actionRole,deploymentRole:props.cloudFormationExecutionRole,region:props.region,cfnCapabilities:[core_1().CfnCapabilities.NAMED_IAM,core_1().CfnCapabilities.AUTO_EXPAND],templateConfiguration:props.templateConfigurationPath?props.cloudAssemblyInput.atPath(props.templateConfigurationPath):void 0}),this.executeChangeSetAction=new(cpactions()).CloudFormationExecuteChangeSetAction({actionName:`${baseActionName}.Deploy`,changeSetName,runOrder:this.executeRunOrder,stackName:this.stackName,role:props.actionRole,region:props.region,outputFileName:props.outputFileName,output:props.output})}bind(scope,stage,options){return stage.addAction(this.prepareChangeSetAction),this.executeChangeSetAction.bind(scope,stage,options)}onStateChange(name,target,options){return this.executeChangeSetAction.onStateChange(name,target,options)}get actionProperties(){return this.executeChangeSetAction.actionProperties}}exports.DeployCdkStackAction=DeployCdkStackAction,_a=JSII_RTTI_SYMBOL_1,DeployCdkStackAction[_a]={fqn:"aws-cdk-lib.pipelines.DeployCdkStackAction",version:"2.113.0"};function roleFromPlaceholderArn(scope,region,account,arn){if(!arn)return;const id=arn;let existingRole=constructs_1().Node.of(scope).tryFindChild(`ImmutableRole${id}`);if(existingRole||(existingRole=constructs_1().Node.of(scope).tryFindChild(id),existingRole))return existingRole;const arnToImport=cxapi().EnvironmentPlaceholders.replace(arn,{region:region??core_1().Aws.REGION,accountId:account??core_1().Aws.ACCOUNT_ID,partition:core_1().Aws.PARTITION});return iam().Role.fromRoleArn(scope,id,arnToImport,{mutable:!1,addGrantsToResources:!0})}function isStackArtifact(a){return a.constructor.name==="CloudFormationStackArtifact"}function writeTemplateConfiguration(filename,config){fs().writeFileSync(filename,JSON.stringify(config,void 0,2),{encoding:"utf-8"})}