Skip to content

Commit cc65795

Browse files
committed
Reffed prop lists
1 parent cec645d commit cc65795

File tree

6 files changed

+62
-7
lines changed

6 files changed

+62
-7
lines changed

awscli/customizations/cloudformation/modules.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def process_module_section(
219219
fn_select(template)
220220

221221
fn_merge(template)
222-
222+
223223
fn_insertfile(template, base_path)
224224

225225
# Remove the Modules section from the template
@@ -548,10 +548,17 @@ def resolve_output_getatt(self, v, d, n):
548548
549549
This function sets d[n] and returns True if it resolved.
550550
"""
551+
551552
if not isinstance(v, list) or len(v) < 2:
552553
msg = f"GetAtt {v} invalid"
553554
raise exceptions.InvalidModuleError(msg=msg)
554555

556+
# print("")
557+
# print("resolve_output_getatt")
558+
# print(" v:", v)
559+
# print(" d:", d)
560+
# print(" n:", n)
561+
555562
# For example, Content.Arn or Content[0].Arn
556563

557564
mapped = self.parent_module.mapped
@@ -579,23 +586,43 @@ def resolve_output_getatt(self, v, d, n):
579586
if index > -1:
580587
name = f"{name}{index}"
581588

582-
r = None
589+
reffed_prop = None
583590
if name == self.name:
584591
if prop_name in self.module_outputs:
585-
r = self.module_outputs[prop_name]
592+
reffed_prop = self.module_outputs[prop_name]
586593
elif prop_name in self.props:
587-
r = self.props[prop_name]
594+
reffed_prop = self.props[prop_name]
588595

589-
if r is None:
596+
if reffed_prop is None:
597+
# print(" reffed_prop is None")
598+
# print("")
590599
return False
591600

601+
# print(" reffed_prop:", reffed_prop)
602+
603+
if isinstance(reffed_prop, list):
604+
for i, r in enumerate(reffed_prop):
605+
self.replace_reffed_prop(r, reffed_prop, i)
606+
d[n] = reffed_prop
607+
else:
608+
self.replace_reffed_prop(reffed_prop, d, n)
609+
610+
return True
611+
612+
def replace_reffed_prop(self, r, d, n):
613+
"""
614+
Replace a reffed prop in an output getatt.
615+
616+
Sets d[n].
617+
"""
618+
592619
if REF in r:
593620
ref = r[REF]
594621
d[n] = {REF: self.name + ref}
595622
elif GETATT in r:
596623
getatt = r[GETATT]
597624
if len(getatt) < 2:
598-
msg = f"GetAtt {getatt} in Output {v[1]} is invalid"
625+
msg = f"GetAtt {getatt} in {self.name} is invalid"
599626
raise exceptions.InvalidModuleError(msg=msg)
600627
s = getatt_map_list(getatt)
601628
if s is not None and s in self.mapped:
@@ -637,7 +664,6 @@ def resolve_output_getatt(self, v, d, n):
637664
else:
638665
# Handle scalars in Properties
639666
d[n] = r
640-
return True
641667

642668
def resolve_output_getatt_map(self, mapped, name, prop_name):
643669
"Resolve GetAtts that reference all Outputs from a mapped module"

tests/unit/customizations/cloudformation/modules/mapout-expect.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ Resources:
2727
- Fn::GetAtt:
2828
- OutputTestB1Bucket
2929
- Arn
30+
OutputTest2B0Bucket:
31+
Type: AWS::S3::Bucket
32+
Properties:
33+
BucketName: b-x
34+
OutputTest2B1Bucket:
35+
Type: AWS::S3::Bucket
36+
Properties:
37+
BucketName: b-y
3038
OutputTestB0Bucket:
3139
Type: AWS::S3::Bucket
3240
Properties:

tests/unit/customizations/cloudformation/modules/mapout-template.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Modules:
22
OutputTest:
33
Source: ./map-output-module.yaml
4+
OutputTest2:
5+
Source: ./map-output-module.yaml
46
ListTest:
57
Source: ./map-list-module.yaml
68
Properties:

tests/unit/customizations/cloudformation/modules/output-expect.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@ Resources:
99
Fn::GetAtt:
1010
- ContentBucket
1111
- Arn
12+
GetAttToSubList:
13+
- Fn::Sub: ${ContentBucket.Arn}
14+
- Fn::Sub: ${ContentBucket2.Arn}
1215
ContentBucket:
1316
Type: AWS::S3::Bucket
1417
Properties:
1518
BucketName: foo
19+
ContentBucket2:
20+
Type: AWS::S3::Bucket
1621
AnotherModuleFoo:
1722
Type: A::B::C
1823
Properties:
1924
AName:
2025
Fn::Sub: another-${ContentBucket.Arn}
26+
TestOverrideList:
27+
- Fn::Sub: ${ContentBucket.Arn}
28+
- Fn::Sub: ${ContentBucket2.Arn}
2129
Outputs:
2230
ExampleOutput:
2331
Value:

tests/unit/customizations/cloudformation/modules/output-module.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ Resources:
66
Type: AWS::S3::Bucket
77
Properties:
88
BucketName: !Ref Name
9+
Bucket2:
10+
Type: AWS::S3::Bucket
911
Outputs:
1012
BucketArn:
1113
Value: !GetAtt Bucket.Arn
1214
BucketArnSub:
1315
Value: !Sub ${Bucket.Arn}
1416
BucketRef:
1517
Value: !Ref Bucket
18+
ArnList:
19+
Value:
20+
- !Sub ${Bucket.Arn}
21+
- !Sub ${Bucket2.Arn}
1622

tests/unit/customizations/cloudformation/modules/output-template.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Modules:
77
Source: ./output-module2.yaml
88
Properties:
99
Name: !GetAtt ContentBucket.Arn
10+
Overrides:
11+
Foo:
12+
Properties:
13+
TestOverrideList: !GetAtt Content.ArnList
1014

1115
Resources:
1216
A:
@@ -15,6 +19,7 @@ Resources:
1519
Object:
1620
Arn: !Sub ${Content.BucketArn}
1721
ArnGetAtt: !GetAtt Content.BucketArn
22+
GetAttToSubList: !GetAtt Content.ArnList
1823
Outputs:
1924
ExampleOutput:
2025
Value: !GetAtt Content.BucketArn

0 commit comments

Comments
 (0)