Skip to content

Commit 38a6bd8

Browse files
committed
feat(fgs/function): new parameter lts_custom_tag supported
1 parent a988778 commit 38a6bd8

File tree

4 files changed

+247
-48
lines changed

4 files changed

+247
-48
lines changed

Diff for: docs/resources/fgs_function.md

+4
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ The following arguments are supported:
526526

527527
-> Only Java runtime supports the configurations of the heartbeat and restore hook.
528528

529+
* `lts_custom_tag` - (Optional, Map) Specifies the custom tags configuration that used to filter the LTS logs.
530+
531+
-> This parameter is only supported by the `v2` version of the function.
532+
529533
<a name="function_func_mounts"></a>
530534
The `func_mounts` block supports:
531535

Diff for: huaweicloud/services/acceptance/fgs/resource_huaweicloud_fgs_function_test.go

+150-21
Original file line numberDiff line numberDiff line change
@@ -874,33 +874,96 @@ func TestAccFunction_logConfig(t *testing.T) {
874874
var (
875875
obj interface{}
876876

877-
name = acceptance.RandomAccResourceName()
878-
resourceName = "huaweicloud_fgs_function.test"
877+
name = acceptance.RandomAccResourceName()
879878

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)
881883
)
882884

883885
resource.ParallelTest(t, resource.TestCase{
884-
PreCheck: func() { acceptance.TestAccPreCheck(t) },
886+
PreCheck: func() {
887+
acceptance.TestAccPreCheck(t)
888+
acceptance.TestAccPreCheckFgsAgency(t)
889+
},
885890
ProviderFactories: acceptance.TestAccProviderFactories,
886-
CheckDestroy: rc.CheckResourceDestroy(),
891+
CheckDestroy: resource.ComposeTestCheckFunc(
892+
rcCreateWithLtsParams.CheckResourceDestroy(),
893+
rcCreateWithoutLtsParams.CheckResourceDestroy(),
894+
),
887895
Steps: []resource.TestStep{
888896
{
889897
Config: testAccFunction_logConfig_step1(name),
890898
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"),
895920
),
896921
},
897922
{
898923
Config: testAccFunction_logConfig_step2(name),
899924
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"),
904967
),
905968
},
906969
},
@@ -931,8 +994,8 @@ func testAccFunction_logConfig_step1(name string) string {
931994
return fmt.Sprintf(`
932995
%[1]s
933996
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"
936999
memory_size = 128
9371000
runtime = "Python2.7"
9381001
timeout = 3
@@ -941,22 +1004,41 @@ resource "huaweicloud_fgs_function" "test" {
9411004
code_type = "inline"
9421005
func_code = base64encode(var.script_content)
9431006
description = "Created by terraform script"
944-
functiongraph_version = "v1"
1007+
functiongraph_version = "v2"
1008+
agency = "%[3]s"
9451009
9461010
log_group_id = huaweicloud_lts_group.test[0].id
9471011
log_stream_id = huaweicloud_lts_stream.test[0].id
9481012
log_group_name = huaweicloud_lts_group.test[0].group_name
9491013
log_stream_name = huaweicloud_lts_stream.test[0].stream_name
1014+
lts_custom_tag = {
1015+
foo = "bar"
1016+
key = "value"
1017+
}
9501018
}
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)
9521034
}
9531035

9541036
func testAccFunction_logConfig_step2(name string) string {
9551037
return fmt.Sprintf(`
9561038
%[1]s
9571039
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"
9601042
memory_size = 128
9611043
runtime = "Python2.7"
9621044
timeout = 3
@@ -965,14 +1047,61 @@ resource "huaweicloud_fgs_function" "test" {
9651047
code_type = "inline"
9661048
func_code = base64encode(var.script_content)
9671049
description = "Created by terraform script"
968-
functiongraph_version = "v1"
1050+
functiongraph_version = "v2"
1051+
agency = "%[3]s"
9691052
9701053
log_group_id = huaweicloud_lts_group.test[1].id
9711054
log_stream_id = huaweicloud_lts_stream.test[1].id
9721055
log_group_name = huaweicloud_lts_group.test[1].group_name
9731056
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"
9741103
}
975-
`, testAccFunction_logConfig_base(name), name)
1104+
`, testAccFunction_logConfig_base(name), name, acceptance.HW_FGS_AGENCY_NAME)
9761105
}
9771106

9781107
func TestAccFunction_strategy(t *testing.T) {

Diff for: huaweicloud/services/fgs/resource_huaweicloud_fgs_function.go

+52-7
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,14 @@ CIDR blocks used by the service.`,
589589
// value will not be returned. So, the computed behavior cannot be supported.
590590
Description: `The timeout of the function restore hook.`,
591591
},
592+
"lts_custom_tag": {
593+
Type: schema.TypeMap,
594+
Optional: true,
595+
Elem: &schema.Schema{Type: schema.TypeString},
596+
DiffSuppressFunc: utils.SuppressMapDiffs(),
597+
// The custom tags can be set to empty, so computed behavior cannot be supported.
598+
Description: `The custom tags configuration that used to filter the LTS logs.`,
599+
},
592600

593601
// Deprecated parameters.
594602
"package": {
@@ -615,6 +623,18 @@ CIDR blocks used by the service.`,
615623
Computed: true,
616624
Description: `The version of the function.`,
617625
},
626+
"lts_custom_tag_origin": {
627+
Type: schema.TypeMap,
628+
Computed: true,
629+
Elem: &schema.Schema{Type: schema.TypeString},
630+
Description: utils.SchemaDesc(
631+
`The script configuration value of this change is also the original value used for comparison with
632+
the new value next time the change is made. The corresponding parameter name is 'lts_custom_tag'.`,
633+
utils.SchemaDescInput{
634+
Internal: true,
635+
},
636+
),
637+
},
618638
},
619639
}
620640
}
@@ -802,6 +822,7 @@ func buildCreateFunctionBodyParams(cfg *config.Config, d *schema.ResourceData) m
802822
"enable_dynamic_memory": d.Get("enable_dynamic_memory"),
803823
"is_stateful_function": d.Get("is_stateful_function"),
804824
"network_controller": buildFunctionNetworkController(d.Get("network_controller").([]interface{})),
825+
"lts_custom_tag": utils.ValueIgnoreEmpty(d.Get("lts_custom_tag")),
805826
}
806827
}
807828

@@ -933,6 +954,7 @@ func buildUpdateFunctionMetadataBodyParams(cfg *config.Config, d *schema.Resourc
933954
"heartbeat_handler": d.Get("heartbeat_handler"),
934955
"restore_hook_handler": d.Get("restore_hook_handler"),
935956
"restore_hook_timeout": d.Get("restore_hook_timeout"),
957+
"lts_custom_tag": utils.ValueIgnoreEmpty(d.Get("lts_custom_tag")),
936958
}
937959
}
938960

@@ -1231,8 +1253,11 @@ func updateFunctionReservedInstances(client *golangsdk.ServiceClient, d *schema.
12311253

12321254
func resourceFunctionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
12331255
var (
1234-
cfg = meta.(*config.Config)
1235-
region = cfg.GetRegion(d)
1256+
cfg = meta.(*config.Config)
1257+
region = cfg.GetRegion(d)
1258+
functionMetadataObjectParamKeys = []string{
1259+
"lts_custom_tag",
1260+
}
12361261
)
12371262

12381263
client, err := cfg.NewServiceClient("fgs", region)
@@ -1253,12 +1278,20 @@ func resourceFunctionCreate(ctx context.Context, d *schema.ResourceData, meta in
12531278
// lintignore:R019
12541279
if d.HasChanges("vpc_id", "func_mounts", "app_agency", "initializer_handler", "initializer_timeout", "concurrency_num",
12551280
"peering_cidr", "enable_auth_in_header", "enable_class_isolation", "ephemeral_storage", "heartbeat_handler",
1256-
"restore_hook_handler", "restore_hook_timeout") {
1281+
"restore_hook_handler", "restore_hook_timeout", "lts_custom_tag") {
12571282
err = updateFunctionMetadata(client, cfg, d, funcUrnWithoutVersion)
12581283
if err != nil {
12591284
return diag.FromErr(err)
12601285
}
12611286
}
1287+
// If the request is successful, obtain the values of all JSON|object parameters first and save them to the
1288+
// corresponding '_origin' attributes for subsequent determination and construction of the request body during
1289+
// next updates.
1290+
// And whether corresponding parameters are changed, the origin values must be refreshed.
1291+
err = utils.RefreshObjectParamOriginValues(d, functionMetadataObjectParamKeys)
1292+
if err != nil {
1293+
return diag.Errorf("unable to refresh the origin values: %s", err)
1294+
}
12621295

12631296
if d.HasChange("depend_list") {
12641297
err := updateFunctionCode(client, d, funcUrnWithoutVersion)
@@ -1656,6 +1689,7 @@ func resourceFunctionRead(_ context.Context, d *schema.ResourceData, meta interf
16561689
function, make(map[string]interface{})).(map[string]interface{}))),
16571690
d.Set("gpu_type", utils.PathSearch("gpu_type", function, nil)),
16581691
d.Set("gpu_memory", utils.PathSearch("gpu_memory", function, nil)),
1692+
d.Set("lts_custom_tag", utils.PathSearch("lts_custom_tag", function, nil)),
16591693
d.Set("pre_stop_handler", utils.PathSearch("pre_stop_handler", function, nil)),
16601694
d.Set("pre_stop_timeout", utils.PathSearch("pre_stop_timeout", function, nil)),
16611695
d.Set("log_group_id", utils.PathSearch("log_group_id", function, nil)),
@@ -1712,9 +1746,12 @@ func resourceFunctionRead(_ context.Context, d *schema.ResourceData, meta interf
17121746

17131747
func resourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
17141748
var (
1715-
cfg = meta.(*config.Config)
1716-
region = cfg.GetRegion(d)
1717-
funcUrnWithoutVersion = parseFunctionUrnWithoutVersion(d.Id())
1749+
cfg = meta.(*config.Config)
1750+
region = cfg.GetRegion(d)
1751+
funcUrnWithoutVersion = parseFunctionUrnWithoutVersion(d.Id())
1752+
functionMetadataObjectParamKeys = []string{
1753+
"lts_custom_tag",
1754+
}
17181755
)
17191756

17201757
client, err := cfg.NewServiceClient("fgs", region)
@@ -1736,12 +1773,20 @@ func resourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, meta in
17361773
"log_group_id", "log_stream_id", "log_group_name", "log_stream_name", "concurrency_num", "gpu_memory", "gpu_type",
17371774
"enable_dynamic_memory", "is_stateful_function", "network_controller", "enterprise_project_id", "peering_cidr",
17381775
"enable_auth_in_header", "enable_class_isolation", "ephemeral_storage", "heartbeat_handler", "restore_hook_handler",
1739-
"restore_hook_timeout") {
1776+
"restore_hook_timeout", "lts_custom_tag") {
17401777
err := updateFunctionMetadata(client, cfg, d, funcUrnWithoutVersion)
17411778
if err != nil {
17421779
return diag.FromErr(err)
17431780
}
17441781
}
1782+
// If the request is successful, obtain the values ​​of all JSON|object parameters first and save them to the
1783+
// corresponding '_origin' attributes for subsequent determination and construction of the request body during
1784+
// next updates.
1785+
// And whether corresponding parameters are changed, the origin values must be refreshed.
1786+
err = utils.RefreshObjectParamOriginValues(d, functionMetadataObjectParamKeys)
1787+
if err != nil {
1788+
return diag.Errorf("unable to refresh the origin values: %s", err)
1789+
}
17451790

17461791
if d.HasChange("max_instance_num") {
17471792
// If the maximum number of instances is omitted (after type conversion, the value is zero), means this feature

0 commit comments

Comments
 (0)