Skip to content

Commit

Permalink
chore(fgs): upgrade the parameters description and import validation (#…
Browse files Browse the repository at this point in the history
…6069)

* docs(fgs): add notes for some parameters of the function resource

* chore(fgs) remove package and xrole from ignore_changes

* test(fgs): adjust acceptance test
  • Loading branch information
wuzhuanhong authored Dec 25, 2024
1 parent 5002156 commit 608faa4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 145 deletions.
12 changes: 8 additions & 4 deletions docs/resources/fgs_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ The following arguments are supported:
* `app_agency` - (Optional, String) Specifies the execution agency enables you to obtain a token or an AK/SK for
accessing other cloud services.

-> After using this parameter, the function execution agency (`app_agency`) and the function configuration
agency (`agency`) can be independently set, which can reduce unnecessary performance loss. Otherwise, the same
agency is used for both function execution and function configuration.

* `description` - (Optional, String) Specifies the description of the function.

* `initializer_handler` - (Optional, String) Specifies the initializer of the function.
Expand Down Expand Up @@ -327,7 +331,8 @@ The following arguments are supported:
* `concurrency_num` - (Optional, Int) Specifies the number of concurrent requests of the function.
The valid value ranges from `1` to `1,000`, the default value is `1`.

-> This parameter is only supported by the `v2` version of the function.
-> 1. This parameter is only supported by the `v2` version of the function.
<br>2. This parameter is available only when the `runtime` parameter is set to **http** or **Custom Image**.

* `gpu_memory` - (Optional, Int) Specifies the GPU memory size allocated to the function, in MByte (MB).
The valid value ranges form `1,024` to `16,384`, the value must be a multiple of `1,024`.
Expand Down Expand Up @@ -487,8 +492,7 @@ $ terraform import huaweicloud_fgs_function.test <id>
```

Note that the imported state may not be identical to your resource definition, due to the attribute missing from the
API response. The missing attributes are:
`app`, `func_code`, `agency`, `tags"`, `package`.
API response. The missing attributes are: `app`, `func_code`, `tags`.
It is generally recommended running `terraform plan` after importing a function.
You can then decide if changes should be applied to the function, or the resource definition should be updated to align
with the function. Also you can ignore changes as below.
Expand All @@ -498,7 +502,7 @@ resource "huaweicloud_fgs_function" "test" {
...
lifecycle {
ignore_changes = [
app, func_code, agency, tags, package,
app, func_code, tags,
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ func TestAccFgsV2Function_basic(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"func_code",
"xrole",
"agency",
"tags",
},
},
Expand Down Expand Up @@ -127,8 +123,6 @@ func TestAccFgsV2Function_withEpsId(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"func_code",
},
},
Expand Down Expand Up @@ -163,8 +157,6 @@ func TestAccFgsV2Function_text(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"func_code",
},
},
Expand Down Expand Up @@ -213,6 +205,7 @@ func TestAccFgsV2Function_createByImage(t *testing.T) {
resource.TestCheckResourceAttr(rName1, "custom_image.0.command", "/bin/sh"),
resource.TestCheckResourceAttr(rName1, "custom_image.0.args", "-args,value"),
resource.TestCheckResourceAttr(rName1, "custom_image.0.working_dir", "/"),
resource.TestCheckResourceAttr(rName1, "concurrency_num", "1"),
rc2.CheckResourceExists(),
resource.TestCheckResourceAttr(rName2, "name", randName+"_2"),
resource.TestCheckResourceAttr(rName2, "agency", "functiongraph_swr_trust"),
Expand All @@ -234,6 +227,7 @@ func TestAccFgsV2Function_createByImage(t *testing.T) {
resource.TestCheckResourceAttr(rName1, "custom_image.0.command", ""),
resource.TestCheckResourceAttr(rName1, "custom_image.0.args", ""),
resource.TestCheckResourceAttr(rName1, "custom_image.0.working_dir", "/"),
resource.TestCheckResourceAttr(rName1, "concurrency_num", "1000"),
rc2.CheckResourceExists(),
resource.TestCheckResourceAttr(rName2, "handler", "-"),
resource.TestCheckResourceAttrPair(rName2, "vpc_id", "huaweicloud_vpc.test", "id"),
Expand All @@ -245,23 +239,11 @@ func TestAccFgsV2Function_createByImage(t *testing.T) {
ResourceName: rName1,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"xrole",
"agency",
},
},
{
ResourceName: rName2,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"xrole",
"agency",
},
},
},
})
Expand Down Expand Up @@ -392,7 +374,7 @@ resource "huaweicloud_fgs_function" "test" {
newkey = "value"
}
}
`, common.TestBaseNetwork(rName), rName)
`, common.TestVpc(rName), rName)
}

func testAccFgsV2Function_basic_step3(rName, obsConfig string) string {
Expand Down Expand Up @@ -427,7 +409,7 @@ resource "huaweicloud_fgs_function" "test" {
newkey = "value"
}
}
`, common.TestBaseNetwork(rName), obsConfig, rName)
`, common.TestVpc(rName), obsConfig, rName)
}

func testAccFgsV2Function_text(rName string) string {
Expand Down Expand Up @@ -482,13 +464,14 @@ func testAccFgsV2Function_createByImage_step_1(rName string) string {
%[1]s
resource "huaweicloud_fgs_function" "create_with_vpc_access" {
name = "%[2]s_1"
app = "default"
handler = "-"
memory_size = 128
runtime = "Custom Image"
timeout = 3
agency = "functiongraph_swr_trust"
name = "%[2]s_1"
app = "default"
handler = "-"
functiongraph_version = "v2"
memory_size = 128
runtime = "Custom Image"
timeout = 3
agency = "functiongraph_swr_trust"
custom_image {
url = "%[3]s"
Expand All @@ -514,7 +497,7 @@ resource "huaweicloud_fgs_function" "create_without_vpc_access" {
url = "%[3]s"
}
}
`, common.TestBaseNetwork(rName), rName, acceptance.HW_BUILD_IMAGE_URL)
`, common.TestVpc(rName), rName, acceptance.HW_BUILD_IMAGE_URL)
}

func testAccFgsV2Function_createByImage_step_2(rName string) string {
Expand All @@ -523,17 +506,20 @@ func testAccFgsV2Function_createByImage_step_2(rName string) string {
# Closs the VPC access
resource "huaweicloud_fgs_function" "create_with_vpc_access" {
name = "%[2]s_1"
app = "default"
handler = "-"
memory_size = 128
runtime = "Custom Image"
timeout = 3
agency = "functiongraph_swr_trust"
name = "%[2]s_1"
app = "default"
handler = "-"
functiongraph_version = "v2"
memory_size = 128
runtime = "Custom Image"
timeout = 3
agency = "functiongraph_swr_trust"
custom_image {
url = "%[3]s"
}
concurrency_num = 1000
}
# Open the VPC access
Expand All @@ -553,7 +539,7 @@ resource "huaweicloud_fgs_function" "create_without_vpc_access" {
vpc_id = huaweicloud_vpc.test.id
network_id = huaweicloud_vpc_subnet.test.id
}
`, common.TestBaseNetwork(rName), rName, acceptance.HW_BUILD_IMAGE_URL_UPDATED)
`, common.TestVpc(rName), rName, acceptance.HW_BUILD_IMAGE_URL_UPDATED)
}

func TestAccFgsV2Function_strategy(t *testing.T) {
Expand Down Expand Up @@ -615,8 +601,6 @@ func TestAccFgsV2Function_strategy(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"func_code",
},
},
Expand Down Expand Up @@ -702,8 +686,6 @@ func TestAccFgsV2Function_versions(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"func_code",
},
},
Expand Down Expand Up @@ -819,10 +801,6 @@ func TestAccFgsV2Function_domain(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"xrole",
"agency",
"app",
"package",
"func_code",
},
},
Expand All @@ -844,7 +822,7 @@ resource "huaweicloud_dns_zone" "test" {
router_id = huaweicloud_vpc.test.id
}
}
`, common.TestBaseNetwork(name))
`, common.TestVpc(name))
}

func testAccFunction_domain_step1(name string) string {
Expand Down Expand Up @@ -910,15 +888,16 @@ resource "huaweicloud_lts_stream" "test" {
}
resource "huaweicloud_fgs_function" "test" {
name = "%[1]s"
app = "default"
description = "fuction test"
handler = "index.handler"
memory_size = 128
timeout = 3
runtime = "Python2.7"
code_type = "inline"
func_code = "dCA9ICdIZWxsbyBtZXNzYWdlOiAnICsganN="
name = "%[1]s"
app = "default"
description = "fuction test"
handler = "index.handler"
functiongraph_version = "v1"
memory_size = 128
timeout = 3
runtime = "Python2.7"
code_type = "inline"
func_code = "dCA9ICdIZWxsbyBtZXNzYWdlOiAnICsganN="
log_group_id = huaweicloud_lts_group.test.id
log_stream_id = huaweicloud_lts_stream.test.id
Expand Down Expand Up @@ -951,15 +930,16 @@ resource "huaweicloud_lts_stream" "test1" {
}
resource "huaweicloud_fgs_function" "test" {
name = "%[1]s"
app = "default"
description = "fuction test"
handler = "index.handler"
memory_size = 128
timeout = 3
runtime = "Python2.7"
code_type = "inline"
func_code = "dCA9ICdIZWxsbyBtZXNzYWdlOiAnICsganN="
name = "%[1]s"
app = "default"
description = "fuction test"
handler = "index.handler"
functiongraph_version = "v1"
memory_size = 128
timeout = 3
runtime = "Python2.7"
code_type = "inline"
func_code = "dCA9ICdIZWxsbyBtZXNzYWdlOiAnICsganN="
log_group_id = huaweicloud_lts_group.test1.id
log_stream_id = huaweicloud_lts_stream.test1.id
Expand Down Expand Up @@ -1018,8 +998,6 @@ func TestAccFgsV2Function_reservedInstance_version(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"func_code",
"tags",
},
Expand Down Expand Up @@ -1070,8 +1048,6 @@ func TestAccFgsV2Function_reservedInstance_alias(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"func_code",
"tags",
},
Expand Down Expand Up @@ -1161,70 +1137,6 @@ resource "huaweicloud_fgs_function" "test" {
`, rName, aliasName)
}

func TestAccFgsV2Function_concurrencyNum(t *testing.T) {
var (
f function.Function

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

rc := acceptance.InitResourceCheck(
resourceName,
&f,
getResourceObj,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccFunction_strategy_default(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "concurrency_num", "1"),
),
},
{
Config: testAccFunction_concurrencyNum(name, 1000),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "concurrency_num", "1000"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"func_code",
},
},
},
})
}

func testAccFunction_concurrencyNum(name string, concurrencyNum int) string {
return fmt.Sprintf(`
resource "huaweicloud_fgs_function" "test" {
functiongraph_version = "v2"
name = "%[1]s"
app = "default"
handler = "index.handler"
memory_size = 128
timeout = 3
runtime = "Python2.7"
code_type = "inline"
func_code = "dCA9ICdIZWxsbyBtZXNzYWdlOiAnICsganN="
concurrency_num = %[2]d
}
`, name, concurrencyNum)
}

func TestAccFgsV2Function_gpuMemory(t *testing.T) {
var (
f function.Function
Expand Down Expand Up @@ -1277,8 +1189,6 @@ func TestAccFgsV2Function_gpuMemory(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"app",
"package",
"func_code",
},
},
Expand Down
Loading

0 comments on commit 608faa4

Please sign in to comment.