@@ -663,6 +663,168 @@ def test_bad_mapping(self):
663
663
)
664
664
665
665
666
+ class TestTransformValues (TestCase ):
667
+ def setUp (self ) -> None :
668
+ self .template_obj = convert_dict (
669
+ {
670
+ "Transform" : ["AWS::LanguageExtensions" ],
671
+ "Mappings" : {
672
+ "111111111111" : {
673
+ "A" : {"AppName" : "appa-dev" },
674
+ "B" : {"AppName" : "appb-dev" },
675
+ },
676
+ "222222222222" : {
677
+ "A" : {"AppName" : "appa-qa" },
678
+ "B" : {"AppName" : "appb-qa" },
679
+ },
680
+ },
681
+ "Resources" : {
682
+ "Fn::ForEach::Regions" : [
683
+ "Region" ,
684
+ ["A" ],
685
+ {
686
+ "${Region}Role" : {
687
+ "Type" : "AWS::IAM::Role" ,
688
+ "Properties" : {
689
+ "RoleName" : {
690
+ "Fn::Sub" : [
691
+ "${appname}" ,
692
+ {
693
+ "appname" : {
694
+ "Fn::FindInMap" : [
695
+ {"Ref" : "AWS::AccountId" },
696
+ {"Ref" : "Region" },
697
+ "AppName" ,
698
+ ]
699
+ }
700
+ },
701
+ ]
702
+ },
703
+ "AssumeRolePolicyDocument" : {
704
+ "Version" : "2012-10-17" ,
705
+ "Statement" : [
706
+ {
707
+ "Effect" : "Allow" ,
708
+ "Principal" : {
709
+ "Service" : ["ec2.amazonaws.com" ]
710
+ },
711
+ "Action" : ["sts:AssumeRole" ],
712
+ }
713
+ ],
714
+ },
715
+ "Path" : "/" ,
716
+ },
717
+ }
718
+ },
719
+ ],
720
+ "Fn::ForEach::NewRegions" : [
721
+ "Region" ,
722
+ ["B" ],
723
+ {
724
+ "${Region}Role" : {
725
+ "Type" : "AWS::IAM::Role" ,
726
+ "Properties" : {
727
+ "RoleName" : {
728
+ "Fn::Sub" : [
729
+ "${appname}" ,
730
+ {
731
+ "appname" : {
732
+ "Fn::FindInMap" : [
733
+ {"Ref" : "AWS::AccountId" },
734
+ {"Ref" : "Region" },
735
+ "AppName" ,
736
+ ]
737
+ }
738
+ },
739
+ ]
740
+ },
741
+ "AssumeRolePolicyDocument" : {
742
+ "Version" : "2012-10-17" ,
743
+ "Statement" : [
744
+ {
745
+ "Effect" : "Allow" ,
746
+ "Principal" : {
747
+ "Service" : ["ec2.amazonaws.com" ]
748
+ },
749
+ "Action" : ["sts:AssumeRole" ],
750
+ }
751
+ ],
752
+ },
753
+ "Path" : "/" ,
754
+ },
755
+ }
756
+ },
757
+ ],
758
+ },
759
+ }
760
+ )
761
+
762
+ self .result = {
763
+ "Mappings" : {
764
+ "111111111111" : {
765
+ "A" : {"AppName" : "appa-dev" },
766
+ "B" : {"AppName" : "appb-dev" },
767
+ },
768
+ "222222222222" : {
769
+ "A" : {"AppName" : "appa-qa" },
770
+ "B" : {"AppName" : "appb-qa" },
771
+ },
772
+ },
773
+ "Resources" : {
774
+ "ARole" : {
775
+ "Properties" : {
776
+ "AssumeRolePolicyDocument" : {
777
+ "Statement" : [
778
+ {
779
+ "Action" : ["sts:AssumeRole" ],
780
+ "Effect" : "Allow" ,
781
+ "Principal" : {"Service" : ["ec2.amazonaws.com" ]},
782
+ }
783
+ ],
784
+ "Version" : "2012-10-17" ,
785
+ },
786
+ "Path" : "/" ,
787
+ "RoleName" : {
788
+ "Fn::Sub" : ["${appname}" , {"appname" : "appa-dev" }]
789
+ },
790
+ },
791
+ "Type" : "AWS::IAM::Role" ,
792
+ },
793
+ "BRole" : {
794
+ "Properties" : {
795
+ "AssumeRolePolicyDocument" : {
796
+ "Statement" : [
797
+ {
798
+ "Action" : ["sts:AssumeRole" ],
799
+ "Effect" : "Allow" ,
800
+ "Principal" : {"Service" : ["ec2.amazonaws.com" ]},
801
+ }
802
+ ],
803
+ "Version" : "2012-10-17" ,
804
+ },
805
+ "Path" : "/" ,
806
+ "RoleName" : {
807
+ "Fn::Sub" : ["${appname}" , {"appname" : "appb-dev" }]
808
+ },
809
+ },
810
+ "Type" : "AWS::IAM::Role" ,
811
+ },
812
+ },
813
+ "Transform" : ["AWS::LanguageExtensions" ],
814
+ }
815
+
816
+ def test_transform (self ):
817
+ self .maxDiff = None
818
+ cfn = Template (filename = "" , template = self .template_obj , regions = ["us-east-1" ])
819
+ matches , template = language_extension (cfn )
820
+ self .assertListEqual (matches , [])
821
+ self .assertDictEqual (
822
+ template ,
823
+ self .result ,
824
+ template ,
825
+ )
826
+
827
+
666
828
def nested_set (dic , keys , value ):
667
829
for key in keys [:- 1 ]:
668
830
if isinstance (key , str ):
0 commit comments