Skip to content

Commit 23442ce

Browse files
committed
Test sending arrays to props and fix output bug
1 parent ef49cbd commit 23442ce

File tree

8 files changed

+50
-8
lines changed

8 files changed

+50
-8
lines changed

awscli/customizations/cloudformation/module_conditions.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
We have to be able to fully resolve it locally.
2121
"""
2222

23+
from collections import OrderedDict
2324
from awscli.customizations.cloudformation import exceptions
2425

2526
AND = "Fn::And"
@@ -56,19 +57,21 @@ def resolve_if(v, find_ref, prior):
5657
# pylint: disable=too-many-branches,too-many-statements
5758
def istrue(v, find_ref, prior):
5859
"Recursive function to evaluate a Condition"
60+
if not isdict(v):
61+
return False
5962
retval = False
6063
if EQUALS in v:
6164
eq = v[EQUALS]
6265
if len(eq) == 2:
6366
val0 = eq[0]
6467
val1 = eq[1]
65-
if IF in val0:
68+
if isdict(val0) and IF in val0:
6669
val0 = resolve_if(val0[IF], find_ref, prior)
67-
if IF in val1:
70+
if isdict(val1) and IF in val1:
6871
val1 = resolve_if(val1[IF], find_ref, prior)
69-
if REF in val0:
72+
if isdict(val0) and REF in val0:
7073
val0 = find_ref(val0[REF])
71-
if REF in val1:
74+
if isdict(val1) and REF in val1:
7275
val1 = find_ref(val1[REF])
7376
retval = val0 == val1
7477
else:
@@ -114,3 +117,8 @@ def istrue(v, find_ref, prior):
114117
# We are depending on the author putting them in order
115118

116119
return retval
120+
121+
122+
def isdict(v):
123+
"Returns True if the type is a dict or OrderedDict"
124+
return isinstance(v, (dict, OrderedDict))

awscli/customizations/cloudformation/modules.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ def resolve_output_sub(self, v, d, n):
544544
resolved = "${" + self.name + ".".join(getatt) + "}"
545545
elif SUB in output:
546546
resolved = "${" + self.name + output[SUB] + "}"
547+
elif REF in output:
548+
resolved = "${" + self.name + output[REF] + "}"
547549
sub += resolved
548550

549551
d[n] = {SUB: sub}
@@ -715,8 +717,6 @@ def resolve(self, k, v, d, n):
715717
k = BucketName, v = {!Ref, Name}, d = Bucket{}, n = Properties
716718
"""
717719

718-
# print(f"k: {k}, v: {v}, d: {d}, n: {n}")
719-
720720
if k == REF:
721721
self.resolve_ref(v, d, n)
722722
elif k == SUB:
@@ -766,7 +766,6 @@ def resolve_sub(self, v, d, n):
766766
767767
Use the same logic as with resolve_ref.
768768
"""
769-
# print(f"resolve_sub v: {v}, d: {d}, n: {n}")
770769
words = parse_sub(v, True)
771770
sub = ""
772771
need_sub = False
@@ -830,7 +829,6 @@ def find_ref(self, name):
830829
:param name The name to search for
831830
:return The referenced element or None
832831
"""
833-
# print(f"find_ref {name}, props: {self.props}, params: {self.params}")
834832
if name in self.props:
835833
if name not in self.params:
836834
# The parent tried to set a property that doesn't exist

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ Resources:
1515
Type: AWS::S3::Bucket
1616
Properties:
1717
BucketName: foo
18+
A:
19+
Type: A::B::C
20+
Properties:
21+
Object:
22+
Arn: !Sub ${ContentBucket.Arn}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ Modules:
33
Source: ./output-module.yaml
44
Properties:
55
Name: foo
6+
Resources:
7+
A:
8+
Type: A::B::C
9+
Properties:
10+
Object:
11+
Arn: !Sub ${Content.BucketArn}
612
Outputs:
713
ExampleOutput:
814
Value: !GetAtt Content.BucketArn
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Resources:
2+
FooBaz:
3+
Type: A::B::C
4+
Properties:
5+
AnArray:
6+
- a
7+
- b
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Parameters:
2+
Bar:
3+
Type: Array
4+
5+
Resources:
6+
Baz:
7+
Type: A::B::C
8+
Properties:
9+
AnArray: !Ref Bar
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Resources:
2+
Foo:
3+
Type: LocalModule
4+
Source: proparray-module.yaml
5+
Properties:
6+
Bar:
7+
- a
8+
- b

tests/unit/customizations/cloudformation/test_modules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def test_main(self):
101101
"example",
102102
"getatt",
103103
"constant",
104+
"proparray",
104105
]
105106
for test in tests:
106107
base = "unit/customizations/cloudformation/modules"

0 commit comments

Comments
 (0)