Skip to content

Commit 46e28bb

Browse files
committed
feat(fgs/function): lts parameters can be set to empty
1 parent c667dc5 commit 46e28bb

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

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

+39-12
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,8 @@ func TestAccFunction_logConfig(t *testing.T) {
904904
// The empty strings of the LTS group and stream will be returned, but the nil values returned for
905905
// their names.
906906
resource.TestCheckResourceAttr(withoutLtsParams, "log_group_id", ""),
907+
// When a parameter is not configured in the ReadContext phase and has never been configured in the
908+
// script, its value in tfstate is null after creation.
907909
resource.TestCheckNoResourceAttr(withoutLtsParams, "log_group_name"),
908910
resource.TestCheckResourceAttr(withoutLtsParams, "log_stream_id", ""),
909911
resource.TestCheckNoResourceAttr(withoutLtsParams, "log_stream_name"),
@@ -946,15 +948,27 @@ func TestAccFunction_logConfig(t *testing.T) {
946948
Check: resource.ComposeTestCheckFunc(
947949
rcWithLtsParams.CheckResourceExists(),
948950
resource.TestCheckResourceAttr(withLtsParams, "functiongraph_version", "v1"),
949-
resource.TestCheckResourceAttrPair(withLtsParams, "log_group_id",
950-
"huaweicloud_lts_group.test.1", "id"),
951-
resource.TestCheckResourceAttrPair(withLtsParams, "log_group_name",
952-
"huaweicloud_lts_group.test.1", "group_name"),
953-
resource.TestCheckResourceAttrPair(withLtsParams, "log_stream_id",
954-
"huaweicloud_lts_stream.test.1", "id"),
955-
resource.TestCheckResourceAttrPair(withLtsParams, "log_stream_name",
956-
"huaweicloud_lts_stream.test.1", "stream_name"),
951+
// The empty strings of the LTS group and stream will be returned, but the nil values returned for
952+
// their names.
953+
resource.TestCheckResourceAttr(withLtsParams, "log_group_id", ""),
954+
// When a parameter is not configured in the ReadContext phase and has been configured in the
955+
// script, its value in tfstate is the corresponding null value instead of null after it is changed
956+
// to null or empty value.
957+
resource.TestCheckResourceAttr(withLtsParams, "log_group_name", ""),
958+
resource.TestCheckResourceAttr(withLtsParams, "log_stream_id", ""),
959+
resource.TestCheckResourceAttr(withLtsParams, "log_stream_name", ""),
957960
resource.TestCheckResourceAttr(withLtsParams, "lts_custom_tag.%", "0"),
961+
rcWithoutLtsParams.CheckResourceExists(),
962+
resource.TestCheckResourceAttr(withoutLtsParams, "functiongraph_version", "v1"),
963+
// The empty strings of the LTS group and stream will be returned, but the nil values returned for
964+
// their names.
965+
resource.TestCheckResourceAttr(withoutLtsParams, "log_group_id", ""),
966+
resource.TestCheckResourceAttr(withoutLtsParams, "log_group_name", ""),
967+
resource.TestCheckResourceAttr(withoutLtsParams, "log_stream_id", ""),
968+
resource.TestCheckResourceAttr(withoutLtsParams, "log_stream_name", ""),
969+
resource.TestCheckResourceAttr(withoutLtsParams, "lts_custom_tag.%", "2"),
970+
resource.TestCheckResourceAttr(withoutLtsParams, "lts_custom_tag.foo", "bar"),
971+
resource.TestCheckResourceAttr(withoutLtsParams, "lts_custom_tag.key", "value"),
958972
),
959973
},
960974
},
@@ -1088,11 +1102,24 @@ resource "huaweicloud_fgs_function" "create_with_lts_params" {
10881102
func_code = base64encode(var.script_content)
10891103
description = "Created by terraform script"
10901104
functiongraph_version = "v1"
1105+
}
1106+
1107+
resource "huaweicloud_fgs_function" "create_without_lts_params" {
1108+
name = "%[2]s_without_lts_params"
1109+
memory_size = 128
1110+
runtime = "Python2.7"
1111+
timeout = 3
1112+
app = "default"
1113+
handler = "index.handler"
1114+
code_type = "inline"
1115+
func_code = base64encode(var.script_content)
1116+
description = "Created by terraform script"
1117+
functiongraph_version = "v1"
10911118
1092-
log_group_id = huaweicloud_lts_group.test[1].id
1093-
log_stream_id = huaweicloud_lts_stream.test[1].id
1094-
log_group_name = huaweicloud_lts_group.test[1].group_name
1095-
log_stream_name = huaweicloud_lts_stream.test[1].stream_name
1119+
lts_custom_tag = {
1120+
foo = "bar"
1121+
key = "value"
1122+
}
10961123
}
10971124
`, testAccFunction_logConfig_base(name), name)
10981125
}

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ func ResourceFgsFunction() *schema.Resource {
392392
"log_group_id": {
393393
Type: schema.TypeString,
394394
Optional: true,
395-
Computed: true,
396395
RequiredWith: []string{
397396
"log_stream_id",
398397
"log_group_name",
@@ -403,21 +402,18 @@ func ResourceFgsFunction() *schema.Resource {
403402
"log_group_name": {
404403
Type: schema.TypeString,
405404
Optional: true,
406-
Computed: true,
407405
RequiredWith: []string{"log_group_id"},
408406
Description: `The LTS group name for collecting logs.`,
409407
},
410408
"log_stream_id": {
411409
Type: schema.TypeString,
412410
Optional: true,
413-
Computed: true,
414411
RequiredWith: []string{"log_group_id"},
415412
Description: `The LTS stream ID for collecting logs.`,
416413
},
417414
"log_stream_name": {
418415
Type: schema.TypeString,
419416
Optional: true,
420-
Computed: true,
421417
RequiredWith: []string{"log_group_id"},
422418
Description: `The LTS stream name for collecting logs.`,
423419
},
@@ -680,15 +676,15 @@ func buildFunctionLogConfig(d *schema.ResourceData) map[string]interface{} {
680676
// LTS stream (group will also be created) and associate it with the function.
681677
// So, the tfstate records will always have the log group ID and the log stream ID.
682678
groupName, ok := d.GetOk("log_group_name") // Only log group name and the log stream name are specified by users.
683-
if !ok {
679+
if !ok && d.IsNewResource() {
684680
return nil
685681
}
686682

687683
return map[string]interface{}{
688684
"group_id": d.Get("log_group_id"),
689685
"group_name": groupName,
690686
"stream_id": d.Get("log_stream_id"),
691-
"stream_name": utils.ValueIgnoreEmpty(d.Get("log_stream_name")),
687+
"stream_name": d.Get("log_stream_name"),
692688
}
693689
}
694690

0 commit comments

Comments
 (0)