Skip to content

feat(fgs/function): new parameter lts_custom_tag supported #6625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/resources/fgs_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ The following arguments are supported:

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

* `lts_custom_tag` - (Optional, Map) Specifies the custom tags configuration that used to filter the LTS logs.

-> This parameter is only supported by the `v2` version of the function.

<a name="function_func_mounts"></a>
The `func_mounts` block supports:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,33 +874,96 @@ func TestAccFunction_logConfig(t *testing.T) {
var (
obj interface{}

name = acceptance.RandomAccResourceName()
resourceName = "huaweicloud_fgs_function.test"
name = acceptance.RandomAccResourceName()

rc = acceptance.InitResourceCheck(resourceName, &obj, getFunction)
createWithLtsParams = "huaweicloud_fgs_function.create_with_lts_params"
rcCreateWithLtsParams = acceptance.InitResourceCheck(createWithLtsParams, &obj, getFunction)
createWithoutLtsParams = "huaweicloud_fgs_function.create_without_lts_params"
rcCreateWithoutLtsParams = acceptance.InitResourceCheck(createWithoutLtsParams, &obj, getFunction)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckFgsAgency(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
CheckDestroy: resource.ComposeTestCheckFunc(
rcCreateWithLtsParams.CheckResourceDestroy(),
rcCreateWithoutLtsParams.CheckResourceDestroy(),
),
Steps: []resource.TestStep{
{
Config: testAccFunction_logConfig_step1(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "functiongraph_version", "v1"),
resource.TestCheckResourceAttrSet(resourceName, "log_group_id"),
resource.TestCheckResourceAttrSet(resourceName, "log_stream_id"),
rcCreateWithLtsParams.CheckResourceExists(),
resource.TestCheckResourceAttr(createWithLtsParams, "functiongraph_version", "v2"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_group_id",
"huaweicloud_lts_group.test.0", "id"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_group_name",
"huaweicloud_lts_group.test.0", "group_name"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_stream_id",
"huaweicloud_lts_stream.test.0", "id"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_stream_name",
"huaweicloud_lts_stream.test.0", "stream_name"),
resource.TestCheckResourceAttr(createWithLtsParams, "lts_custom_tag.%", "2"),
resource.TestCheckResourceAttr(createWithLtsParams, "lts_custom_tag.foo", "bar"),
resource.TestCheckResourceAttr(createWithLtsParams, "lts_custom_tag.key", "value"),
rcCreateWithoutLtsParams.CheckResourceExists(),
resource.TestCheckResourceAttr(createWithoutLtsParams, "functiongraph_version", "v2"),
// In some regions (such as 'cn-north-4'), the FunctionGraph service automatically binds the groups
// and streams created by FunctionGraph to functions that do not have LTS set.
resource.TestCheckResourceAttrSet(createWithoutLtsParams, "log_group_id"),
resource.TestCheckNoResourceAttr(createWithoutLtsParams, "log_group_name"),
resource.TestCheckResourceAttrSet(createWithoutLtsParams, "log_stream_id"),
resource.TestCheckNoResourceAttr(createWithoutLtsParams, "log_stream_name"),
),
},
{
Config: testAccFunction_logConfig_step2(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "functiongraph_version", "v1"),
resource.TestCheckResourceAttrSet(resourceName, "log_group_id"),
resource.TestCheckResourceAttrSet(resourceName, "log_stream_id"),
rcCreateWithLtsParams.CheckResourceExists(),
resource.TestCheckResourceAttr(createWithLtsParams, "functiongraph_version", "v2"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_group_id",
"huaweicloud_lts_group.test.1", "id"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_group_name",
"huaweicloud_lts_group.test.1", "group_name"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_stream_id",
"huaweicloud_lts_stream.test.1", "id"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_stream_name",
"huaweicloud_lts_stream.test.1", "stream_name"),
resource.TestCheckResourceAttr(createWithLtsParams, "lts_custom_tag.%", "2"),
resource.TestCheckResourceAttr(createWithLtsParams, "lts_custom_tag.foo", "baar"),
resource.TestCheckResourceAttr(createWithLtsParams, "lts_custom_tag.new_key", "value"),
rcCreateWithoutLtsParams.CheckResourceExists(),
resource.TestCheckResourceAttr(createWithoutLtsParams, "functiongraph_version", "v2"),
resource.TestCheckResourceAttrPair(createWithoutLtsParams, "log_group_id",
"huaweicloud_lts_group.test.0", "id"),
resource.TestCheckResourceAttrPair(createWithoutLtsParams, "log_group_name",
"huaweicloud_lts_group.test.0", "group_name"),
resource.TestCheckResourceAttrPair(createWithoutLtsParams, "log_stream_id",
"huaweicloud_lts_stream.test.0", "id"),
resource.TestCheckResourceAttrPair(createWithoutLtsParams, "log_stream_name",
"huaweicloud_lts_stream.test.0", "stream_name"),
resource.TestCheckResourceAttr(createWithoutLtsParams, "lts_custom_tag.%", "2"),
resource.TestCheckResourceAttr(createWithoutLtsParams, "lts_custom_tag.foo", "bar"),
resource.TestCheckResourceAttr(createWithoutLtsParams, "lts_custom_tag.key", "value"),
),
},
{
Config: testAccFunction_logConfig_step3(name),
Check: resource.ComposeTestCheckFunc(
rcCreateWithLtsParams.CheckResourceExists(),
resource.TestCheckResourceAttr(createWithLtsParams, "functiongraph_version", "v2"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_group_id",
"huaweicloud_lts_group.test.1", "id"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_group_name",
"huaweicloud_lts_group.test.1", "group_name"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_stream_id",
"huaweicloud_lts_stream.test.1", "id"),
resource.TestCheckResourceAttrPair(createWithLtsParams, "log_stream_name",
"huaweicloud_lts_stream.test.1", "stream_name"),
resource.TestCheckResourceAttr(createWithLtsParams, "lts_custom_tag.%", "0"),
),
},
},
Expand Down Expand Up @@ -931,8 +994,8 @@ func testAccFunction_logConfig_step1(name string) string {
return fmt.Sprintf(`
%[1]s

resource "huaweicloud_fgs_function" "test" {
name = "%[2]s"
resource "huaweicloud_fgs_function" "create_with_lts_params" {
name = "%[2]s_with_lts_params"
memory_size = 128
runtime = "Python2.7"
timeout = 3
Expand All @@ -941,22 +1004,41 @@ resource "huaweicloud_fgs_function" "test" {
code_type = "inline"
func_code = base64encode(var.script_content)
description = "Created by terraform script"
functiongraph_version = "v1"
functiongraph_version = "v2"
agency = "%[3]s"

log_group_id = huaweicloud_lts_group.test[0].id
log_stream_id = huaweicloud_lts_stream.test[0].id
log_group_name = huaweicloud_lts_group.test[0].group_name
log_stream_name = huaweicloud_lts_stream.test[0].stream_name
lts_custom_tag = {
foo = "bar"
key = "value"
}
}
`, testAccFunction_logConfig_base(name), name)

resource "huaweicloud_fgs_function" "create_without_lts_params" {
name = "%[2]s_without_lts_params"
memory_size = 128
runtime = "Python2.7"
timeout = 3
app = "default"
handler = "index.handler"
code_type = "inline"
func_code = base64encode(var.script_content)
description = "Created by terraform script"
functiongraph_version = "v2"
agency = "%[3]s"
}
`, testAccFunction_logConfig_base(name), name, acceptance.HW_FGS_AGENCY_NAME)
}

func testAccFunction_logConfig_step2(name string) string {
return fmt.Sprintf(`
%[1]s

resource "huaweicloud_fgs_function" "test" {
name = "%[2]s"
resource "huaweicloud_fgs_function" "create_with_lts_params" {
name = "%[2]s_with_lts_params"
memory_size = 128
runtime = "Python2.7"
timeout = 3
Expand All @@ -965,14 +1047,61 @@ resource "huaweicloud_fgs_function" "test" {
code_type = "inline"
func_code = base64encode(var.script_content)
description = "Created by terraform script"
functiongraph_version = "v1"
functiongraph_version = "v2"
agency = "%[3]s"

log_group_id = huaweicloud_lts_group.test[1].id
log_stream_id = huaweicloud_lts_stream.test[1].id
log_group_name = huaweicloud_lts_group.test[1].group_name
log_stream_name = huaweicloud_lts_stream.test[1].stream_name
lts_custom_tag = {
foo = "baar"
new_key = "value"
}
}

resource "huaweicloud_fgs_function" "create_without_lts_params" {
name = "%[2]s_without_lts_params"
memory_size = 128
runtime = "Python2.7"
timeout = 3
app = "default"
handler = "index.handler"
code_type = "inline"
func_code = base64encode(var.script_content)
description = "Created by terraform script"
functiongraph_version = "v2"
agency = "%[3]s"

log_group_id = huaweicloud_lts_group.test[0].id
log_stream_id = huaweicloud_lts_stream.test[0].id
log_group_name = huaweicloud_lts_group.test[0].group_name
log_stream_name = huaweicloud_lts_stream.test[0].stream_name
lts_custom_tag = {
foo = "bar"
key = "value"
}
}
`, testAccFunction_logConfig_base(name), name, acceptance.HW_FGS_AGENCY_NAME)
}

func testAccFunction_logConfig_step3(name string) string {
return fmt.Sprintf(`
%[1]s

resource "huaweicloud_fgs_function" "create_with_lts_params" {
name = "%[2]s_with_lts_params"
memory_size = 128
runtime = "Python2.7"
timeout = 3
app = "default"
handler = "index.handler"
code_type = "inline"
func_code = base64encode(var.script_content)
description = "Created by terraform script"
functiongraph_version = "v2"
}
`, testAccFunction_logConfig_base(name), name)
`, testAccFunction_logConfig_base(name), name, acceptance.HW_FGS_AGENCY_NAME)
}

func TestAccFunction_strategy(t *testing.T) {
Expand Down
59 changes: 52 additions & 7 deletions huaweicloud/services/fgs/resource_huaweicloud_fgs_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,14 @@ CIDR blocks used by the service.`,
// value will not be returned. So, the computed behavior cannot be supported.
Description: `The timeout of the function restore hook.`,
},
"lts_custom_tag": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
DiffSuppressFunc: utils.SuppressMapDiffs(),
// The custom tags can be set to empty, so computed behavior cannot be supported.
Description: `The custom tags configuration that used to filter the LTS logs.`,
},

// Deprecated parameters.
"package": {
Expand All @@ -615,6 +623,18 @@ CIDR blocks used by the service.`,
Computed: true,
Description: `The version of the function.`,
},
"lts_custom_tag_origin": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: utils.SchemaDesc(
`The script configuration value of this change is also the original value used for comparison with
the new value next time the change is made. The corresponding parameter name is 'lts_custom_tag'.`,
utils.SchemaDescInput{
Internal: true,
},
),
},
},
}
}
Expand Down Expand Up @@ -802,6 +822,7 @@ func buildCreateFunctionBodyParams(cfg *config.Config, d *schema.ResourceData) m
"enable_dynamic_memory": d.Get("enable_dynamic_memory"),
"is_stateful_function": d.Get("is_stateful_function"),
"network_controller": buildFunctionNetworkController(d.Get("network_controller").([]interface{})),
"lts_custom_tag": utils.ValueIgnoreEmpty(d.Get("lts_custom_tag")),
}
}

Expand Down Expand Up @@ -933,6 +954,7 @@ func buildUpdateFunctionMetadataBodyParams(cfg *config.Config, d *schema.Resourc
"heartbeat_handler": d.Get("heartbeat_handler"),
"restore_hook_handler": d.Get("restore_hook_handler"),
"restore_hook_timeout": d.Get("restore_hook_timeout"),
"lts_custom_tag": utils.ValueIgnoreEmpty(d.Get("lts_custom_tag")),
}
}

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

func resourceFunctionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var (
cfg = meta.(*config.Config)
region = cfg.GetRegion(d)
cfg = meta.(*config.Config)
region = cfg.GetRegion(d)
functionMetadataObjectParamKeys = []string{
"lts_custom_tag",
}
)

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

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

func resourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var (
cfg = meta.(*config.Config)
region = cfg.GetRegion(d)
funcUrnWithoutVersion = parseFunctionUrnWithoutVersion(d.Id())
cfg = meta.(*config.Config)
region = cfg.GetRegion(d)
funcUrnWithoutVersion = parseFunctionUrnWithoutVersion(d.Id())
functionMetadataObjectParamKeys = []string{
"lts_custom_tag",
}
)

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

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