@@ -751,6 +751,85 @@ func TestDefaults_Apply(t *testing.T) {
751
751
}),
752
752
}),
753
753
},
754
+ "applies default safely where possible when types mismatch" : {
755
+ defaults : & Defaults {
756
+ Type : cty .Map (cty .ObjectWithOptionalAttrs (map [string ]cty.Type {
757
+ "description" : cty .String ,
758
+ "rules" : cty .Map (cty .ObjectWithOptionalAttrs (map [string ]cty.Type {
759
+ "description" : cty .String ,
760
+ "destination_ports" : cty .List (cty .String ),
761
+ "destination_addresses" : cty .List (cty .String ),
762
+ "translated_address" : cty .String ,
763
+ "translated_port" : cty .String ,
764
+ }, []string {"destination_addresses" })),
765
+ }, []string {"description" })),
766
+ Children : map [string ]* Defaults {
767
+ "" : {
768
+ Type : cty .ObjectWithOptionalAttrs (map [string ]cty.Type {
769
+ "description" : cty .String ,
770
+ "rules" : cty .Map (cty .ObjectWithOptionalAttrs (map [string ]cty.Type {
771
+ "description" : cty .String ,
772
+ "destination_ports" : cty .List (cty .String ),
773
+ "destination_addresses" : cty .List (cty .String ),
774
+ "translated_address" : cty .String ,
775
+ "translated_port" : cty .String ,
776
+ }, []string {"destination_addresses" })),
777
+ }, []string {"description" }),
778
+ DefaultValues : map [string ]cty.Value {
779
+ "description" : cty .StringVal ("unknown" ),
780
+ },
781
+ Children : map [string ]* Defaults {
782
+ "rules" : {
783
+ Type : cty .Map (cty .ObjectWithOptionalAttrs (map [string ]cty.Type {
784
+ "description" : cty .String ,
785
+ "destination_ports" : cty .List (cty .String ),
786
+ "destination_addresses" : cty .List (cty .String ),
787
+ "translated_address" : cty .String ,
788
+ "translated_port" : cty .String ,
789
+ }, []string {"destination_addresses" })),
790
+ Children : map [string ]* Defaults {
791
+ "" : {
792
+ Type : cty .ObjectWithOptionalAttrs (map [string ]cty.Type {
793
+ "description" : cty .String ,
794
+ "destination_ports" : cty .List (cty .String ),
795
+ "destination_addresses" : cty .List (cty .String ),
796
+ "translated_address" : cty .String ,
797
+ "translated_port" : cty .String ,
798
+ }, []string {"destination_addresses" }),
799
+ DefaultValues : map [string ]cty.Value {
800
+ "destination_addresses" : cty .ListValEmpty (cty .String ),
801
+ },
802
+ },
803
+ },
804
+ },
805
+ },
806
+ },
807
+ },
808
+ },
809
+ value : cty .MapVal (map [string ]cty.Value {
810
+ "mysql" : cty .ObjectVal (map [string ]cty.Value {
811
+ "rules" : cty .ObjectVal (map [string ]cty.Value {
812
+ "description" : cty .StringVal ("Port forward" ),
813
+ "destination_ports" : cty .ListVal ([]cty.Value {cty .StringVal ("3306" )}),
814
+ "destination_addresses" : cty .ListVal ([]cty.Value {cty .StringVal ("192.168.0.1" )}),
815
+ "translated_address" : cty .StringVal ("192.168.0.1" ),
816
+ "translated_port" : cty .StringVal ("3306" ),
817
+ }),
818
+ }),
819
+ }),
820
+ want : cty .MapVal (map [string ]cty.Value {
821
+ "mysql" : cty .ObjectVal (map [string ]cty.Value {
822
+ "description" : cty .StringVal ("unknown" ),
823
+ "rules" : cty .ObjectVal (map [string ]cty.Value {
824
+ "description" : cty .StringVal ("Port forward" ),
825
+ "destination_ports" : cty .ListVal ([]cty.Value {cty .StringVal ("3306" )}),
826
+ "destination_addresses" : cty .ListVal ([]cty.Value {cty .StringVal ("192.168.0.1" )}),
827
+ "translated_address" : cty .StringVal ("192.168.0.1" ),
828
+ "translated_port" : cty .StringVal ("3306" ),
829
+ }),
830
+ }),
831
+ }),
832
+ },
754
833
}
755
834
756
835
for name , tc := range testCases {
0 commit comments