Skip to content

Commit

Permalink
feat(iotda): the product resource supports new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ruwenqiang123 committed Nov 4, 2024
1 parent d136157 commit 5857efa
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
17 changes: 12 additions & 5 deletions docs/resources/iotda_product.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
subcategory: "IoT Device Access (IoTDA)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_iotda_product"
description: ""
description: |-
Manages a product resource within HuaweiCloud.
---

# huaweicloud_iotda_product

Manages an IoTDA product within HuaweiCloud.
Manages a product resource within HuaweiCloud.

-> When accessing an IoTDA **standard** or **enterprise** edition instance, you need to specify the IoTDA service
endpoint in `provider` block.
Expand Down Expand Up @@ -175,6 +176,9 @@ allowed: `?'#().,&%@!`.
* `type` - (Required, String) Specifies the type of the parameter.
The valid values are **int**, **decimal**, **string**, **DateTime**, **jsonObject** and **string list**.

* `required` - (Optional, Bool) Specifies the device property is mandatory or not.
The default value is **false**.

* `method` - (Required, String) Specifies the access mode of the device property.
Options: **RW**, **W**, **R**.

Expand Down Expand Up @@ -222,6 +226,9 @@ allowed: `?'#().,&%@!`.
* `type` - (Required, String) Specifies the type of the parameter.
The valid values are **int**, **decimal**, **string**, **DateTime**, **jsonObject** and **string list**.

* `required` - (Optional, Bool) Specifies the parameter is mandatory or not.
The default value is **false**.

* `description` - (Optional, String) Specifies the description of the parameter. The description contains a maximum of
`128` characters. Only letters, Chinese characters, digits, hyphens (-), underscores (_) and the following special
characters are allowed: `?'#().,&%@!`.
Expand All @@ -247,12 +254,12 @@ The unit contains a maximum of 16 characters.

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID in UUID format.
* `id` - The resource ID.

## Import

Products can be imported using the `id`, e.g.
The product resource can be imported using the `id`, e.g.

```bash
$ terraform import huaweicloud_iotda_product.test 10022532f4f94f26b01daa1e424853e1
$ terraform import huaweicloud_iotda_product.test <id>
```
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestAccProduct_basic(t *testing.T) {
resource.TestCheckResourceAttr(rName, "services.0.properties.#", "4"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.name", "p_1"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.required", "false"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.description", "desc"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.min", "3"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.max", "666"),
Expand All @@ -70,23 +71,26 @@ func TestAccProduct_basic(t *testing.T) {
resource.TestCheckResourceAttr(rName, "services.0.commands.0.name", "cmd_1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.name", "cmd_p_1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.required", "false"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.description", "desc"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.min", "3"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.max", "33"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.name", "cmd_r_1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.required", "false"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.min", "1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.max", "22"),
),
},
{
Config: testProduct_update(name + "_update"),
Config: testProduct_update(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "name", name+"_update"),
resource.TestCheckResourceAttr(rName, "services.0.properties.#", "3"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.name", "p_1"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.required", "true"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.description", "desc_update"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.min", "4"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.max", "5"),
Expand All @@ -102,11 +106,13 @@ func TestAccProduct_basic(t *testing.T) {
resource.TestCheckResourceAttr(rName, "services.0.commands.0.name", "cmd_1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.name", "cmd_p_2"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.required", "true"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.description", "desc"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.min", "5"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.max", "33"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.name", "cmd_r_1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.required", "true"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.min", "2"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.max", "33"),
),
Expand All @@ -124,6 +130,7 @@ func TestAccProduct_derived(t *testing.T) {
var obj model.ShowProductResponse

name := acceptance.RandomAccResourceName()

rName := "huaweicloud_iotda_product.test"

rc := acceptance.InitResourceCheck(
Expand Down Expand Up @@ -156,6 +163,7 @@ func TestAccProduct_derived(t *testing.T) {
resource.TestCheckResourceAttr(rName, "services.0.properties.#", "4"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.name", "p_1"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.required", "false"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.description", "desc"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.min", "3"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.max", "666"),
Expand All @@ -171,23 +179,26 @@ func TestAccProduct_derived(t *testing.T) {
resource.TestCheckResourceAttr(rName, "services.0.commands.0.name", "cmd_1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.name", "cmd_p_1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.required", "false"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.description", "desc"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.min", "3"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.max", "33"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.name", "cmd_r_1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.required", "false"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.min", "1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.max", "22"),
),
},
{
Config: testProduct_update(name + "_update"),
Config: testProduct_update(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "name", name+"_update"),
resource.TestCheckResourceAttr(rName, "services.0.properties.#", "3"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.name", "p_1"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.required", "true"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.description", "desc_update"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.min", "4"),
resource.TestCheckResourceAttr(rName, "services.0.properties.0.max", "5"),
Expand All @@ -203,11 +214,13 @@ func TestAccProduct_derived(t *testing.T) {
resource.TestCheckResourceAttr(rName, "services.0.commands.0.name", "cmd_1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.name", "cmd_p_2"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.required", "true"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.description", "desc"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.min", "5"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.paras.0.max", "33"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.name", "cmd_r_1"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.type", "int"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.required", "true"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.min", "2"),
resource.TestCheckResourceAttr(rName, "services.0.commands.0.responses.0.max", "33"),
),
Expand All @@ -225,12 +238,8 @@ func testProduct_basic(name string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_iotda_space" "test" {
name = "%[2]s"
}
resource "huaweicloud_iotda_product" "test" {
name = "%[3]s"
name = "%[2]s"
device_type = "test"
protocol = "MQTT"
space_id = huaweicloud_iotda_space.test.id
Expand All @@ -245,6 +254,7 @@ resource "huaweicloud_iotda_product" "test" {
properties {
name = "p_1"
type = "int"
required = false
min = "3"
max = "666"
description = "desc"
Expand Down Expand Up @@ -280,33 +290,31 @@ resource "huaweicloud_iotda_product" "test" {
paras {
name = "cmd_p_1"
type = "int"
required = false
description = "desc"
min = "3"
max = 33
}
responses {
name = "cmd_r_1"
type = "int"
min = "1"
max = "22"
name = "cmd_r_1"
type = "int"
required = false
min = "1"
max = "22"
}
}
}
}
`, buildIoTDAEndpoint(), name, name)
`, testSpace_basic(name), name)
}

func testProduct_update(name string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_iotda_space" "test" {
name = "%[2]s"
}
resource "huaweicloud_iotda_product" "test" {
name = "%[3]s"
name = "%[2]s_update"
device_type = "test"
protocol = "MQTT"
space_id = huaweicloud_iotda_space.test.id
Expand All @@ -321,6 +329,7 @@ resource "huaweicloud_iotda_product" "test" {
properties {
name = "p_1"
type = "int"
required = true
min = "4"
max = "5"
description = "desc_update"
Expand Down Expand Up @@ -348,19 +357,21 @@ resource "huaweicloud_iotda_product" "test" {
paras {
name = "cmd_p_2"
type = "int"
required = true
description = "desc"
min = "5"
max = 33
}
responses {
name = "cmd_r_1"
type = "int"
min = "2"
max = "33"
name = "cmd_r_1"
type = "int"
required = true
min = "2"
max = "33"
}
}
}
}
`, buildIoTDAEndpoint(), name, name)
`, testSpace_basic(name), name)
}
Loading

0 comments on commit 5857efa

Please sign in to comment.