@@ -359,19 +359,68 @@ def get_att(template: "TemplateConverter", values: Any):
359
359
values (Any): The values passed to the function.
360
360
361
361
Raises:
362
- TypeError: If values is not a list.
363
- ValueError: If length of values is not 3.
364
- TypeError: If the logicalNameOfResource and attributeName are not str.
365
- KeyError: If the logicalNameOfResource is not found in the template.
362
+ TypeError: If values is not a String.
366
363
367
364
Returns:
368
- str : Terraform equivalent expression.
365
+ LiteralType : Terraform equivalent expression.
369
366
"""
370
367
371
- if not isinstance (values , List ):
372
- raise TypeError (
373
- f"Fn::GetAtt - The values must be a List, not { type (values ).__name__ } ."
368
+ if isinstance (values , (str , StringType )):
369
+ return _get_att_string (template , values )
370
+
371
+ if isinstance (values , list ):
372
+ return _get_att_list (template , values )
373
+
374
+ raise TypeError (
375
+ f"Fn::GetAtt - The value must be a String or List, not { type (values ).__name__ } ."
376
+ )
377
+
378
+
379
+ def _get_att_string (template : "TemplateConverter" , values : Any ):
380
+ """Converts AWS GetAtt intrinsic function to it's Terraform equivalent.
381
+
382
+ Args:
383
+ template (Configuration): The template being tested.
384
+ values (Any): The values passed to the function.
385
+
386
+ Raises:
387
+ ValueError: If the value doesn't contain a resource id and an attribute.
388
+
389
+ Returns:
390
+ LiteralType: Terraform equivalent expression.
391
+ """
392
+
393
+ if "." not in values :
394
+ raise ValueError (
395
+ "Fn::GetAtt - The value must contain a resource id and an attribute."
374
396
)
397
+
398
+ parts = values .split ("." )
399
+
400
+ resouce_id = parts [0 ]
401
+
402
+ attributes = "." .join (parts [1 :])
403
+
404
+ result = _get_att_list (template , [resouce_id , attributes ])
405
+
406
+ return result
407
+
408
+
409
+ def _get_att_list (template : "TemplateConverter" , values : Any ):
410
+ """Converts AWS GetAtt intrinsic function to it's Terraform equivalent.
411
+
412
+ Args:
413
+ template (Configuration): The template being tested.
414
+ values (Any): The values passed to the function.
415
+
416
+ Raises:
417
+ ValueError: If the values length is not 2.
418
+ TypeError: If the values are not strings.
419
+
420
+ Returns:
421
+ LiteralType: Terraform equivalent expression.
422
+ """
423
+
375
424
if not len (values ) == 2 :
376
425
raise ValueError (
377
426
(
@@ -712,7 +761,7 @@ def replace_var(m):
712
761
713
762
attributes = "." .join (parts [1 :])
714
763
715
- result = get_att (template , [resouce_id , attributes ])
764
+ result = _get_att_list (template , [resouce_id , attributes ])
716
765
else :
717
766
result = ref (template , var )
718
767
@@ -775,7 +824,7 @@ def replace_var(m) -> str:
775
824
776
825
attributes = "." .join (parts [1 :])
777
826
778
- result = get_att (template , [resouce_id , attributes ])
827
+ result = _get_att_list (template , [resouce_id , attributes ])
779
828
else :
780
829
result = ref (template , var )
781
830
@@ -982,6 +1031,7 @@ def wrap_in_curlys(input: str):
982
1031
** ALLOWED_NESTED_CONDITIONS ,
983
1032
"Fn::Join" : join ,
984
1033
"Fn::Select" : select ,
1034
+ "Fn::Sub" : sub ,
985
1035
},
986
1036
"Fn::If" : {
987
1037
"Fn::Base64" : base64 ,
@@ -993,6 +1043,7 @@ def wrap_in_curlys(input: str):
993
1043
"Fn::Select" : select ,
994
1044
"Fn::Sub" : sub ,
995
1045
"Ref" : ref ,
1046
+ "Fn::Split" : split ,
996
1047
},
997
1048
"Fn::Not" : ALLOWED_NESTED_CONDITIONS ,
998
1049
"Fn::Or" : ALLOWED_NESTED_CONDITIONS ,
@@ -1001,6 +1052,7 @@ def wrap_in_curlys(input: str):
1001
1052
"Fn::Cidr" : {
1002
1053
"Fn::Select" : select ,
1003
1054
"Ref" : ref ,
1055
+ "Fn::GetAtt" : get_att ,
1004
1056
},
1005
1057
"Fn::FindInMap" : {
1006
1058
"Fn::FindInMap" : find_in_map ,
0 commit comments