@@ -874,33 +874,96 @@ func TestAccFunction_logConfig(t *testing.T) {
874
874
var (
875
875
obj interface {}
876
876
877
- name = acceptance .RandomAccResourceName ()
878
- resourceName = "huaweicloud_fgs_function.test"
877
+ name = acceptance .RandomAccResourceName ()
879
878
880
- rc = acceptance .InitResourceCheck (resourceName , & obj , getFunction )
879
+ createWithLtsParams = "huaweicloud_fgs_function.create_with_lts_params"
880
+ rcCreateWithLtsParams = acceptance .InitResourceCheck (createWithLtsParams , & obj , getFunction )
881
+ createWithoutLtsParams = "huaweicloud_fgs_function.create_without_lts_params"
882
+ rcCreateWithoutLtsParams = acceptance .InitResourceCheck (createWithoutLtsParams , & obj , getFunction )
881
883
)
882
884
883
885
resource .ParallelTest (t , resource.TestCase {
884
- PreCheck : func () { acceptance .TestAccPreCheck (t ) },
886
+ PreCheck : func () {
887
+ acceptance .TestAccPreCheck (t )
888
+ acceptance .TestAccPreCheckFgsAgency (t )
889
+ },
885
890
ProviderFactories : acceptance .TestAccProviderFactories ,
886
- CheckDestroy : rc .CheckResourceDestroy (),
891
+ CheckDestroy : resource .ComposeTestCheckFunc (
892
+ rcCreateWithLtsParams .CheckResourceDestroy (),
893
+ rcCreateWithoutLtsParams .CheckResourceDestroy (),
894
+ ),
887
895
Steps : []resource.TestStep {
888
896
{
889
897
Config : testAccFunction_logConfig_step1 (name ),
890
898
Check : resource .ComposeTestCheckFunc (
891
- rc .CheckResourceExists (),
892
- resource .TestCheckResourceAttr (resourceName , "functiongraph_version" , "v1" ),
893
- resource .TestCheckResourceAttrSet (resourceName , "log_group_id" ),
894
- resource .TestCheckResourceAttrSet (resourceName , "log_stream_id" ),
899
+ rcCreateWithLtsParams .CheckResourceExists (),
900
+ resource .TestCheckResourceAttr (createWithLtsParams , "functiongraph_version" , "v2" ),
901
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_group_id" ,
902
+ "huaweicloud_lts_group.test.0" , "id" ),
903
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_group_name" ,
904
+ "huaweicloud_lts_group.test.0" , "group_name" ),
905
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_stream_id" ,
906
+ "huaweicloud_lts_stream.test.0" , "id" ),
907
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_stream_name" ,
908
+ "huaweicloud_lts_stream.test.0" , "stream_name" ),
909
+ resource .TestCheckResourceAttr (createWithLtsParams , "lts_custom_tag.%" , "2" ),
910
+ resource .TestCheckResourceAttr (createWithLtsParams , "lts_custom_tag.foo" , "bar" ),
911
+ resource .TestCheckResourceAttr (createWithLtsParams , "lts_custom_tag.key" , "value" ),
912
+ rcCreateWithoutLtsParams .CheckResourceExists (),
913
+ resource .TestCheckResourceAttr (createWithoutLtsParams , "functiongraph_version" , "v2" ),
914
+ // In some regions (such as 'cn-north-4'), the FunctionGraph service automatically binds the groups
915
+ // and streams created by FunctionGraph to functions that do not have LTS set.
916
+ resource .TestCheckResourceAttrSet (createWithoutLtsParams , "log_group_id" ),
917
+ resource .TestCheckNoResourceAttr (createWithoutLtsParams , "log_group_name" ),
918
+ resource .TestCheckResourceAttrSet (createWithoutLtsParams , "log_stream_id" ),
919
+ resource .TestCheckNoResourceAttr (createWithoutLtsParams , "log_stream_name" ),
895
920
),
896
921
},
897
922
{
898
923
Config : testAccFunction_logConfig_step2 (name ),
899
924
Check : resource .ComposeTestCheckFunc (
900
- rc .CheckResourceExists (),
901
- resource .TestCheckResourceAttr (resourceName , "functiongraph_version" , "v1" ),
902
- resource .TestCheckResourceAttrSet (resourceName , "log_group_id" ),
903
- resource .TestCheckResourceAttrSet (resourceName , "log_stream_id" ),
925
+ rcCreateWithLtsParams .CheckResourceExists (),
926
+ resource .TestCheckResourceAttr (createWithLtsParams , "functiongraph_version" , "v2" ),
927
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_group_id" ,
928
+ "huaweicloud_lts_group.test.1" , "id" ),
929
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_group_name" ,
930
+ "huaweicloud_lts_group.test.1" , "group_name" ),
931
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_stream_id" ,
932
+ "huaweicloud_lts_stream.test.1" , "id" ),
933
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_stream_name" ,
934
+ "huaweicloud_lts_stream.test.1" , "stream_name" ),
935
+ resource .TestCheckResourceAttr (createWithLtsParams , "lts_custom_tag.%" , "2" ),
936
+ resource .TestCheckResourceAttr (createWithLtsParams , "lts_custom_tag.foo" , "baar" ),
937
+ resource .TestCheckResourceAttr (createWithLtsParams , "lts_custom_tag.new_key" , "value" ),
938
+ rcCreateWithoutLtsParams .CheckResourceExists (),
939
+ resource .TestCheckResourceAttr (createWithoutLtsParams , "functiongraph_version" , "v2" ),
940
+ resource .TestCheckResourceAttrPair (createWithoutLtsParams , "log_group_id" ,
941
+ "huaweicloud_lts_group.test.0" , "id" ),
942
+ resource .TestCheckResourceAttrPair (createWithoutLtsParams , "log_group_name" ,
943
+ "huaweicloud_lts_group.test.0" , "group_name" ),
944
+ resource .TestCheckResourceAttrPair (createWithoutLtsParams , "log_stream_id" ,
945
+ "huaweicloud_lts_stream.test.0" , "id" ),
946
+ resource .TestCheckResourceAttrPair (createWithoutLtsParams , "log_stream_name" ,
947
+ "huaweicloud_lts_stream.test.0" , "stream_name" ),
948
+ resource .TestCheckResourceAttr (createWithoutLtsParams , "lts_custom_tag.%" , "2" ),
949
+ resource .TestCheckResourceAttr (createWithoutLtsParams , "lts_custom_tag.foo" , "bar" ),
950
+ resource .TestCheckResourceAttr (createWithoutLtsParams , "lts_custom_tag.key" , "value" ),
951
+ ),
952
+ },
953
+ {
954
+ Config : testAccFunction_logConfig_step3 (name ),
955
+ Check : resource .ComposeTestCheckFunc (
956
+ rcCreateWithLtsParams .CheckResourceExists (),
957
+ resource .TestCheckResourceAttr (createWithLtsParams , "functiongraph_version" , "v2" ),
958
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_group_id" ,
959
+ "huaweicloud_lts_group.test.1" , "id" ),
960
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_group_name" ,
961
+ "huaweicloud_lts_group.test.1" , "group_name" ),
962
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_stream_id" ,
963
+ "huaweicloud_lts_stream.test.1" , "id" ),
964
+ resource .TestCheckResourceAttrPair (createWithLtsParams , "log_stream_name" ,
965
+ "huaweicloud_lts_stream.test.1" , "stream_name" ),
966
+ resource .TestCheckResourceAttr (createWithLtsParams , "lts_custom_tag.%" , "0" ),
904
967
),
905
968
},
906
969
},
@@ -931,8 +994,8 @@ func testAccFunction_logConfig_step1(name string) string {
931
994
return fmt .Sprintf (`
932
995
%[1]s
933
996
934
- resource "huaweicloud_fgs_function" "test " {
935
- name = "%[2]s "
997
+ resource "huaweicloud_fgs_function" "create_with_lts_params " {
998
+ name = "%[2]s_with_lts_params "
936
999
memory_size = 128
937
1000
runtime = "Python2.7"
938
1001
timeout = 3
@@ -941,22 +1004,41 @@ resource "huaweicloud_fgs_function" "test" {
941
1004
code_type = "inline"
942
1005
func_code = base64encode(var.script_content)
943
1006
description = "Created by terraform script"
944
- functiongraph_version = "v1"
1007
+ functiongraph_version = "v2"
1008
+ agency = "%[3]s"
945
1009
946
1010
log_group_id = huaweicloud_lts_group.test[0].id
947
1011
log_stream_id = huaweicloud_lts_stream.test[0].id
948
1012
log_group_name = huaweicloud_lts_group.test[0].group_name
949
1013
log_stream_name = huaweicloud_lts_stream.test[0].stream_name
1014
+ lts_custom_tag = {
1015
+ foo = "bar"
1016
+ key = "value"
1017
+ }
950
1018
}
951
- ` , testAccFunction_logConfig_base (name ), name )
1019
+
1020
+ resource "huaweicloud_fgs_function" "create_without_lts_params" {
1021
+ name = "%[2]s_without_lts_params"
1022
+ memory_size = 128
1023
+ runtime = "Python2.7"
1024
+ timeout = 3
1025
+ app = "default"
1026
+ handler = "index.handler"
1027
+ code_type = "inline"
1028
+ func_code = base64encode(var.script_content)
1029
+ description = "Created by terraform script"
1030
+ functiongraph_version = "v2"
1031
+ agency = "%[3]s"
1032
+ }
1033
+ ` , testAccFunction_logConfig_base (name ), name , acceptance .HW_FGS_AGENCY_NAME )
952
1034
}
953
1035
954
1036
func testAccFunction_logConfig_step2 (name string ) string {
955
1037
return fmt .Sprintf (`
956
1038
%[1]s
957
1039
958
- resource "huaweicloud_fgs_function" "test " {
959
- name = "%[2]s "
1040
+ resource "huaweicloud_fgs_function" "create_with_lts_params " {
1041
+ name = "%[2]s_with_lts_params "
960
1042
memory_size = 128
961
1043
runtime = "Python2.7"
962
1044
timeout = 3
@@ -965,14 +1047,61 @@ resource "huaweicloud_fgs_function" "test" {
965
1047
code_type = "inline"
966
1048
func_code = base64encode(var.script_content)
967
1049
description = "Created by terraform script"
968
- functiongraph_version = "v1"
1050
+ functiongraph_version = "v2"
1051
+ agency = "%[3]s"
969
1052
970
1053
log_group_id = huaweicloud_lts_group.test[1].id
971
1054
log_stream_id = huaweicloud_lts_stream.test[1].id
972
1055
log_group_name = huaweicloud_lts_group.test[1].group_name
973
1056
log_stream_name = huaweicloud_lts_stream.test[1].stream_name
1057
+ lts_custom_tag = {
1058
+ foo = "baar"
1059
+ new_key = "value"
1060
+ }
1061
+ }
1062
+
1063
+ resource "huaweicloud_fgs_function" "create_without_lts_params" {
1064
+ name = "%[2]s_without_lts_params"
1065
+ memory_size = 128
1066
+ runtime = "Python2.7"
1067
+ timeout = 3
1068
+ app = "default"
1069
+ handler = "index.handler"
1070
+ code_type = "inline"
1071
+ func_code = base64encode(var.script_content)
1072
+ description = "Created by terraform script"
1073
+ functiongraph_version = "v2"
1074
+ agency = "%[3]s"
1075
+
1076
+ log_group_id = huaweicloud_lts_group.test[0].id
1077
+ log_stream_id = huaweicloud_lts_stream.test[0].id
1078
+ log_group_name = huaweicloud_lts_group.test[0].group_name
1079
+ log_stream_name = huaweicloud_lts_stream.test[0].stream_name
1080
+ lts_custom_tag = {
1081
+ foo = "bar"
1082
+ key = "value"
1083
+ }
1084
+ }
1085
+ ` , testAccFunction_logConfig_base (name ), name , acceptance .HW_FGS_AGENCY_NAME )
1086
+ }
1087
+
1088
+ func testAccFunction_logConfig_step3 (name string ) string {
1089
+ return fmt .Sprintf (`
1090
+ %[1]s
1091
+
1092
+ resource "huaweicloud_fgs_function" "create_with_lts_params" {
1093
+ name = "%[2]s_with_lts_params"
1094
+ memory_size = 128
1095
+ runtime = "Python2.7"
1096
+ timeout = 3
1097
+ app = "default"
1098
+ handler = "index.handler"
1099
+ code_type = "inline"
1100
+ func_code = base64encode(var.script_content)
1101
+ description = "Created by terraform script"
1102
+ functiongraph_version = "v2"
974
1103
}
975
- ` , testAccFunction_logConfig_base (name ), name )
1104
+ ` , testAccFunction_logConfig_base (name ), name , acceptance . HW_FGS_AGENCY_NAME )
976
1105
}
977
1106
978
1107
func TestAccFunction_strategy (t * testing.T ) {
0 commit comments