@@ -4,26 +4,26 @@ import { ActionContext, EventTypes, ServerlessIac } from '../types';
4
4
import * as fc from '@alicloud/ros-cdk-fc3' ;
5
5
import * as ram from '@alicloud/ros-cdk-ram' ;
6
6
import * as agw from '@alicloud/ros-cdk-apigateway' ;
7
- import { evalRefValue , replaceReference , resolveCode } from '../common' ;
7
+ import { replaceReference , resolveCode } from '../common' ;
8
8
9
9
export class IacStack extends ros . Stack {
10
- private service : string ;
10
+ private readonly service : string ;
11
11
12
12
constructor ( scope : ros . Construct , iac : ServerlessIac , context : ActionContext ) {
13
- super ( scope , evalRefValue ( iac . service , iac , context . stage ) , {
13
+ super ( scope , replaceReference ( iac . service , context ) , {
14
14
stackName : context . stackName ,
15
15
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 ) ;
17
17
return acc ;
18
18
} , { } ) ,
19
19
} ) ;
20
- this . service = evalRefValue ( iac . service , iac , context . stage ) ;
20
+ this . service = replaceReference ( iac . service , context ) ;
21
21
22
22
// Define Parameters
23
23
if ( iac . vars ) {
24
24
Object . entries ( iac . vars ) . map (
25
- ( [ key , value ] ) =>
26
- new ros . RosParameter ( this , key , {
25
+ ( [ id , value ] ) =>
26
+ new ros . RosParameter ( this , id , {
27
27
type : RosParameterType . STRING ,
28
28
defaultValue : value ,
29
29
} ) ,
@@ -32,26 +32,26 @@ export class IacStack extends ros.Stack {
32
32
33
33
// Define Mappings
34
34
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 ) } ) ;
36
36
}
37
37
38
38
new ros . RosInfo (
39
39
this ,
40
40
ros . RosInfo . description ,
41
- replaceReference ( `${ this . service } stack` , context . stage ) ,
41
+ replaceReference ( `${ this . service } stack` , context ) ,
42
42
) ;
43
43
44
44
iac . functions . forEach ( ( fnc ) => {
45
45
new fc . RosFunction (
46
46
this ,
47
47
fnc . key ,
48
48
{
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 ) ,
55
55
code : {
56
56
zipFile : resolveCode ( fnc . code ) ,
57
57
} ,
@@ -64,10 +64,10 @@ export class IacStack extends ros.Stack {
64
64
if ( apiGateway ?. length ) {
65
65
const gatewayAccessRole = new ram . RosRole (
66
66
this ,
67
- replaceReference ( `${ this . service } _role` , context . stage ) ,
67
+ replaceReference ( `${ this . service } _role` , context ) ,
68
68
{
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 ) ,
71
71
assumeRolePolicyDocument : {
72
72
version : '1' ,
73
73
statement : [
@@ -82,7 +82,7 @@ export class IacStack extends ros.Stack {
82
82
} ,
83
83
policies : [
84
84
{
85
- policyName : replaceReference ( `${ this . service } -policy` , context . stage ) ,
85
+ policyName : replaceReference ( `${ this . service } -policy` , context ) ,
86
86
policyDocument : {
87
87
version : '1' ,
88
88
statement : [
@@ -102,10 +102,10 @@ export class IacStack extends ros.Stack {
102
102
103
103
const apiGatewayGroup = new agw . RosGroup (
104
104
this ,
105
- replaceReference ( `${ this . service } _apigroup` , context . stage ) ,
105
+ replaceReference ( `${ this . service } _apigroup` , context ) ,
106
106
{
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 ) ,
109
109
} ,
110
110
true ,
111
111
) ;
@@ -129,29 +129,29 @@ export class IacStack extends ros.Stack {
129
129
130
130
const api = new agw . RosApi (
131
131
this ,
132
- replaceReference ( `${ event . key } _api_${ key } ` , context . stage ) ,
132
+ replaceReference ( `${ event . key } _api_${ key } ` , context ) ,
133
133
{
134
- apiName : replaceReference ( `${ event . name } _api_${ key } ` , context . stage ) ,
134
+ apiName : replaceReference ( `${ event . name } _api_${ key } ` , context ) ,
135
135
groupId : apiGatewayGroup . attrGroupId ,
136
136
visibility : 'PRIVATE' ,
137
137
requestConfig : {
138
138
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 ) ,
141
141
requestMode : 'PASSTHROUGH' ,
142
142
} ,
143
143
serviceConfig : {
144
144
serviceProtocol : 'FunctionCompute' ,
145
145
functionComputeConfig : {
146
146
fcRegionId : context . region ,
147
- functionName : replaceReference ( trigger . backend , context . stage ) ,
147
+ functionName : replaceReference ( trigger . backend , context ) ,
148
148
roleArn : gatewayAccessRole . attrArn ,
149
149
fcVersion : '3.0' ,
150
150
} ,
151
151
} ,
152
152
resultSample : 'ServerlessInsight resultSample' ,
153
153
resultType : 'JSON' ,
154
- tags : replaceReference ( iac . tags , context . stage ) ,
154
+ tags : replaceReference ( iac . tags , context ) ,
155
155
} ,
156
156
true ,
157
157
) ;
0 commit comments