UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 4.9 kB
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.NestedStack=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var crypto=()=>{var tmp=require("crypto");return crypto=()=>tmp,tmp},constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},assets_1=()=>{var tmp=require("./assets");return assets_1=()=>tmp,tmp},cfn_fn_1=()=>{var tmp=require("./cfn-fn");return cfn_fn_1=()=>tmp,tmp},cfn_pseudo_1=()=>{var tmp=require("./cfn-pseudo");return cfn_pseudo_1=()=>tmp,tmp},cloudformation_generated_1=()=>{var tmp=require("./cloudformation.generated");return cloudformation_generated_1=()=>tmp,tmp},lazy_1=()=>{var tmp=require("./lazy");return lazy_1=()=>tmp,tmp},names_1=()=>{var tmp=require("./names");return names_1=()=>tmp,tmp},removal_policy_1=()=>{var tmp=require("./removal-policy");return removal_policy_1=()=>tmp,tmp},stack_1=()=>{var tmp=require("./stack");return stack_1=()=>tmp,tmp},stack_synthesizers_1=()=>{var tmp=require("./stack-synthesizers");return stack_synthesizers_1=()=>tmp,tmp},token_1=()=>{var tmp=require("./token");return token_1=()=>tmp,tmp},cxapi=()=>{var tmp=require("../../cx-api");return cxapi=()=>tmp,tmp};const NESTED_STACK_SYMBOL=Symbol.for("@aws-cdk/core.NestedStack");class NestedStack extends stack_1().Stack{static isNestedStack(x){return x!=null&&typeof x=="object"&&NESTED_STACK_SYMBOL in x}constructor(scope,id,props={}){try{jsiiDeprecationWarnings().aws_cdk_lib_NestedStackProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,NestedStack),error}const parentStack=findParentStack(scope);super(scope,id,{env:{account:parentStack.account,region:parentStack.region},synthesizer:new(stack_synthesizers_1()).NestedStackSynthesizer(parentStack.synthesizer),description:props.description,crossRegionReferences:parentStack._crossRegionReferences}),this._parentStack=parentStack;const parentScope=new(constructs_1()).Construct(scope,id+".NestedStack");Object.defineProperty(this,NESTED_STACK_SYMBOL,{value:!0}),this.templateFile=`${names_1().Names.uniqueId(this)}.nested.template.json`,this.parameters=props.parameters||{},this.resource=new(cloudformation_generated_1()).CfnStack(parentScope,`${id}.NestedStackResource`,{templateUrl:lazy_1().Lazy.uncachedString({produce:()=>this._templateUrl||"<unresolved>"}),parameters:lazy_1().Lazy.any({produce:()=>Object.keys(this.parameters).length>0?this.parameters:void 0}),notificationArns:props.notificationArns,timeoutInMinutes:props.timeout?props.timeout.toMinutes():void 0}),this.resource.applyRemovalPolicy(props.removalPolicy??removal_policy_1().RemovalPolicy.DESTROY),this.nestedStackResource=this.resource,this.node.defaultChild=this.resource,this._contextualStackName=this.contextualAttribute(cfn_pseudo_1().Aws.STACK_NAME,cfn_fn_1().Fn.select(1,cfn_fn_1().Fn.split("/",this.resource.ref))),this._contextualStackId=this.contextualAttribute(cfn_pseudo_1().Aws.STACK_ID,this.resource.ref)}get stackName(){return this._contextualStackName}get stackId(){return this._contextualStackId}setParameter(name,value){this.parameters[name]=value}_prepareTemplateAsset(){if(this._templateUrl)return!1;Object.entries(this.tags.tagValues()).forEach(([key,value])=>{this.resource.tags.setTag(key,value)});const cfn=JSON.stringify(this._toCloudFormation()),templateHash=crypto().createHash("sha256").update(cfn).digest("hex"),templateLocation=this._parentStack.synthesizer.addFileAsset({packaging:assets_1().FileAssetPackaging.FILE,sourceHash:templateHash,fileName:this.templateFile});return this.addResourceMetadata(this.resource,"TemplateURL"),this._templateUrl=`https://s3.${this._parentStack.region}.${this._parentStack.urlSuffix}/${templateLocation.bucketName}/${templateLocation.objectKey}`,!0}contextualAttribute(innerValue,outerValue){return token_1().Token.asString({resolve:context=>stack_1().Stack.of(context.scope)===this?innerValue:outerValue})}addResourceMetadata(resource,resourceProperty){this.node.tryGetContext(cxapi().ASSET_RESOURCE_METADATA_ENABLED_CONTEXT)&&(resource.cfnOptions.metadata=resource.cfnOptions.metadata||{},resource.cfnOptions.metadata[cxapi().ASSET_RESOURCE_METADATA_PATH_KEY]=this.templateFile,resource.cfnOptions.metadata[cxapi().ASSET_RESOURCE_METADATA_PROPERTY_KEY]=resourceProperty)}}exports.NestedStack=NestedStack,_a=JSII_RTTI_SYMBOL_1,NestedStack[_a]={fqn:"aws-cdk-lib.NestedStack",version:"2.185.0"};function findParentStack(scope){if(!scope)throw new Error("Nested stacks cannot be defined as a root construct");const parentStack=constructs_1().Node.of(scope).scopes.reverse().find(p=>stack_1().Stack.isStack(p));if(!parentStack)throw new Error("Nested stacks must be defined within scope of another non-nested stack");return parentStack}