11import * as cdk from 'aws-cdk-lib' ;
22import { Template } from 'aws-cdk-lib/assertions' ;
3- import { ParameterTier , ParameterDataType } from 'aws-cdk-lib/aws-ssm' ;
3+ import { ParameterTier , ParameterDataType , StringParameter } from 'aws-cdk-lib/aws-ssm' ;
44import { GlobalStringParameter } from '../src/index' ;
55
66describe ( 'GlobalParameter' , ( ) => {
@@ -13,7 +13,7 @@ describe('GlobalParameter', () => {
1313 parameterProps : {
1414 stringValue : 'testValue' ,
1515 } as any ,
16- regions : [ 'us-east-1' ] ,
16+ replicaRegions : [ 'us-east-1' ] ,
1717 } ) ;
1818 } ) . toThrow ( 'parameterName must be specified' ) ;
1919 } ) ;
@@ -27,12 +27,12 @@ describe('GlobalParameter', () => {
2727 parameterProps : {
2828 parameterName : 'testParameter' ,
2929 } as any ,
30- regions : [ 'us-east-1' ] ,
30+ replicaRegions : [ 'us-east-1' ] ,
3131 } ) ;
3232 } ) . toThrow ( 'stringValue must be specified' ) ;
3333 } ) ;
3434
35- it ( 'throws an error if no regions are specified ' , ( ) => {
35+ it ( 'throws an error if the current region is included in the replicaRegions list ' , ( ) => {
3636 const app = new cdk . App ( ) ;
3737 const stack = new cdk . Stack ( app , 'TestStack' ) ;
3838
@@ -42,7 +42,22 @@ describe('GlobalParameter', () => {
4242 parameterName : 'testParameter' ,
4343 stringValue : 'testValue' ,
4444 } ,
45- regions : [ ] ,
45+ replicaRegions : [ 'us-east-1' , process . env . CDK_DEFAULT_REGION ! ] ,
46+ } ) ;
47+ } ) . toThrow ( 'The current region cannot be included in the replicaRegions list' ) ;
48+ } ) ;
49+
50+ it ( 'throws an error if no replicaRegions are specified' , ( ) => {
51+ const app = new cdk . App ( ) ;
52+ const stack = new cdk . Stack ( app , 'TestStack' ) ;
53+
54+ expect ( ( ) => {
55+ new GlobalStringParameter ( stack , 'TestGlobalParameter' , {
56+ parameterProps : {
57+ parameterName : 'testParameter' ,
58+ stringValue : 'testValue' ,
59+ } ,
60+ replicaRegions : [ ] ,
4661 } ) ;
4762 } ) . toThrow ( 'At least one region must be specified' ) ;
4863 } ) ;
@@ -60,18 +75,57 @@ describe('GlobalParameter', () => {
6075 dataType : ParameterDataType . TEXT ,
6176 allowedPattern : '.*' ,
6277 } ,
63- regions : [ 'us-east-1' ] ,
78+ replicaRegions : [ 'us-east-1' ] ,
6479 } ) ;
6580
6681 const template = Template . fromStack ( stack ) ;
6782
6883 console . log ( JSON . stringify ( template . toJSON ( ) , null , 2 ) ) ;
6984
7085 template . hasResourceProperties ( 'Custom::AWS' , { } ) ;
86+
87+ template . hasResourceProperties ( 'AWS::SSM::Parameter' , {
88+ Type : 'String' ,
89+ Description : 'Test description' ,
90+ Tier : 'Standard' ,
91+ DataType : 'text' ,
92+ AllowedPattern : '.*' ,
93+ } ) ;
7194 } ) ;
7295} ) ;
7396
74- it ( 'creates, updates, and deletes SSM parameters in multiple regions' , ( ) => {
97+ it ( 'creates an SSM parameter with existing paramaters' , ( ) => {
98+ const app = new cdk . App ( ) ;
99+ const stack = new cdk . Stack ( app , 'TestStack' ) ;
100+
101+ const existingStringParamObj = new StringParameter ( new cdk . Stack ( app , 'OrigStack' ) , 'ExistingStringParameter' , {
102+ parameterName : 'existingParameter' ,
103+ stringValue : 'existingValue' ,
104+ } ) ;
105+
106+ new GlobalStringParameter ( stack , 'TestGlobalParameter' , {
107+ existingStringParamObj,
108+ parameterProps : {
109+ parameterName : 'testParameter' ,
110+ stringValue : 'testValue' ,
111+ description : 'Test description' ,
112+ tier : ParameterTier . STANDARD ,
113+ dataType : ParameterDataType . TEXT ,
114+ allowedPattern : '.*' ,
115+ } ,
116+ replicaRegions : [ 'us-east-1' ] ,
117+ } ) ;
118+
119+ const template = Template . fromStack ( stack ) ;
120+
121+ console . log ( JSON . stringify ( template . toJSON ( ) , null , 2 ) ) ;
122+
123+ template . hasResourceProperties ( 'Custom::AWS' , { } ) ;
124+
125+ template . resourceCountIs ( 'AWS::SSM::Parameter' , 0 ) ;
126+ } ) ;
127+
128+ it ( 'creates, updates, and deletes SSM parameters in multiple replicaRegions' , ( ) => {
75129 const app = new cdk . App ( ) ;
76130 const stack = new cdk . Stack ( app , 'TestStack' ) ;
77131
@@ -80,7 +134,7 @@ it('creates, updates, and deletes SSM parameters in multiple regions', () => {
80134 parameterName : 'testParameter' ,
81135 stringValue : 'testValue' ,
82136 } ,
83- regions : [ 'us-east-1' , 'us-west-2' ] ,
137+ replicaRegions : [ 'us-east-1' , 'us-west-2' ] ,
84138 } ) ;
85139
86140 const template = Template . fromStack ( stack ) ;
@@ -98,7 +152,7 @@ it('adds a policy to the grantPrincipal', () => {
98152 parameterName : 'testParameter' ,
99153 stringValue : 'testValue' ,
100154 } ,
101- regions : [ 'us-east-1' ] ,
155+ replicaRegions : [ 'us-east-1' ] ,
102156 } ) ;
103157
104158 const template = Template . fromStack ( stack ) ;
0 commit comments