@@ -4,26 +4,26 @@ import { ActionContext, EventTypes, ServerlessIac } from '../types';
44import * as fc from '@alicloud/ros-cdk-fc3' ;
55import * as ram from '@alicloud/ros-cdk-ram' ;
66import * as agw from '@alicloud/ros-cdk-apigateway' ;
7- import { evalRefValue , replaceReference , resolveCode } from '../common' ;
7+ import { replaceReference , resolveCode } from '../common' ;
88
99export class IacStack extends ros . Stack {
10- private service : string ;
10+ private readonly service : string ;
1111
1212 constructor ( scope : ros . Construct , iac : ServerlessIac , context : ActionContext ) {
13- super ( scope , evalRefValue ( iac . service , iac , context . stage ) , {
13+ super ( scope , replaceReference ( iac . service , context ) , {
1414 stackName : context . stackName ,
1515 tags : iac . tags ?. reduce ( ( acc : { [ key : string ] : string } , tag ) => {
16- acc [ tag . key ] = replaceReference ( tag . value , context . stage ) ;
16+ acc [ tag . key ] = replaceReference ( tag . value , context ) ;
1717 return acc ;
1818 } , { } ) ,
1919 } ) ;
20- this . service = evalRefValue ( iac . service , iac , context . stage ) ;
20+ this . service = replaceReference ( iac . service , context ) ;
2121
2222 // Define Parameters
2323 if ( iac . vars ) {
2424 Object . entries ( iac . vars ) . map (
25- ( [ key , value ] ) =>
26- new ros . RosParameter ( this , key , {
25+ ( [ id , value ] ) =>
26+ new ros . RosParameter ( this , id , {
2727 type : RosParameterType . STRING ,
2828 defaultValue : value ,
2929 } ) ,
@@ -32,26 +32,26 @@ export class IacStack extends ros.Stack {
3232
3333 // Define Mappings
3434 if ( iac . stages ) {
35- new ros . RosMapping ( this , 'stages' , { mapping : replaceReference ( iac . stages , context . stage ) } ) ;
35+ new ros . RosMapping ( this , 'stages' , { mapping : replaceReference ( iac . stages , context ) } ) ;
3636 }
3737
3838 new ros . RosInfo (
3939 this ,
4040 ros . RosInfo . description ,
41- replaceReference ( `${ this . service } stack` , context . stage ) ,
41+ replaceReference ( `${ this . service } stack` , context ) ,
4242 ) ;
4343
4444 iac . functions . forEach ( ( fnc ) => {
4545 new fc . RosFunction (
4646 this ,
4747 fnc . key ,
4848 {
49- functionName : replaceReference ( fnc . name , context . stage ) ,
50- handler : replaceReference ( fnc . handler , context . stage ) ,
51- runtime : replaceReference ( fnc . runtime , context . stage ) ,
52- memorySize : replaceReference ( fnc . memory , context . stage ) ,
53- timeout : replaceReference ( fnc . timeout , context . stage ) ,
54- environmentVariables : replaceReference ( fnc . environment , context . stage ) ,
49+ functionName : replaceReference ( fnc . name , context ) ,
50+ handler : replaceReference ( fnc . handler , context ) ,
51+ runtime : replaceReference ( fnc . runtime , context ) ,
52+ memorySize : replaceReference ( fnc . memory , context ) ,
53+ timeout : replaceReference ( fnc . timeout , context ) ,
54+ environmentVariables : replaceReference ( fnc . environment , context ) ,
5555 code : {
5656 zipFile : resolveCode ( fnc . code ) ,
5757 } ,
@@ -64,10 +64,10 @@ export class IacStack extends ros.Stack {
6464 if ( apiGateway ?. length ) {
6565 const gatewayAccessRole = new ram . RosRole (
6666 this ,
67- replaceReference ( `${ this . service } _role` , context . stage ) ,
67+ replaceReference ( `${ this . service } _role` , context ) ,
6868 {
69- roleName : replaceReference ( `${ this . service } -gateway-access-role` , context . stage ) ,
70- description : replaceReference ( `${ this . service } role` , context . stage ) ,
69+ roleName : replaceReference ( `${ this . service } -gateway-access-role` , context ) ,
70+ description : replaceReference ( `${ this . service } role` , context ) ,
7171 assumeRolePolicyDocument : {
7272 version : '1' ,
7373 statement : [
@@ -82,7 +82,7 @@ export class IacStack extends ros.Stack {
8282 } ,
8383 policies : [
8484 {
85- policyName : replaceReference ( `${ this . service } -policy` , context . stage ) ,
85+ policyName : replaceReference ( `${ this . service } -policy` , context ) ,
8686 policyDocument : {
8787 version : '1' ,
8888 statement : [
@@ -102,10 +102,10 @@ export class IacStack extends ros.Stack {
102102
103103 const apiGatewayGroup = new agw . RosGroup (
104104 this ,
105- replaceReference ( `${ this . service } _apigroup` , context . stage ) ,
105+ replaceReference ( `${ this . service } _apigroup` , context ) ,
106106 {
107- groupName : replaceReference ( `${ this . service } _apigroup` , context . stage ) ,
108- tags : replaceReference ( iac . tags , context . stage ) ,
107+ groupName : replaceReference ( `${ this . service } _apigroup` , context ) ,
108+ tags : replaceReference ( iac . tags , context ) ,
109109 } ,
110110 true ,
111111 ) ;
@@ -129,29 +129,29 @@ export class IacStack extends ros.Stack {
129129
130130 const api = new agw . RosApi (
131131 this ,
132- replaceReference ( `${ event . key } _api_${ key } ` , context . stage ) ,
132+ replaceReference ( `${ event . key } _api_${ key } ` , context ) ,
133133 {
134- apiName : replaceReference ( `${ event . name } _api_${ key } ` , context . stage ) ,
134+ apiName : replaceReference ( `${ event . name } _api_${ key } ` , context ) ,
135135 groupId : apiGatewayGroup . attrGroupId ,
136136 visibility : 'PRIVATE' ,
137137 requestConfig : {
138138 requestProtocol : 'HTTP' ,
139- requestHttpMethod : replaceReference ( trigger . method , context . stage ) ,
140- requestPath : replaceReference ( trigger . path , context . stage ) ,
139+ requestHttpMethod : replaceReference ( trigger . method , context ) ,
140+ requestPath : replaceReference ( trigger . path , context ) ,
141141 requestMode : 'PASSTHROUGH' ,
142142 } ,
143143 serviceConfig : {
144144 serviceProtocol : 'FunctionCompute' ,
145145 functionComputeConfig : {
146146 fcRegionId : context . region ,
147- functionName : replaceReference ( trigger . backend , context . stage ) ,
147+ functionName : replaceReference ( trigger . backend , context ) ,
148148 roleArn : gatewayAccessRole . attrArn ,
149149 fcVersion : '3.0' ,
150150 } ,
151151 } ,
152152 resultSample : 'ServerlessInsight resultSample' ,
153153 resultType : 'JSON' ,
154- tags : replaceReference ( iac . tags , context . stage ) ,
154+ tags : replaceReference ( iac . tags , context ) ,
155155 } ,
156156 true ,
157157 ) ;
0 commit comments