Skip to content

Commit

Permalink
feat(waf): dedicated instance resource support field tags
Browse files Browse the repository at this point in the history
  • Loading branch information
deer-hang committed Dec 16, 2024
1 parent eb9541e commit 648d1a8
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 26 deletions.
20 changes: 17 additions & 3 deletions docs/resources/waf_dedicated_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ resource "huaweicloud_waf_dedicated_instance" "test" {
subnet_id = var.subnet_id
enterprise_project_id = var.enterprise_project_id
tags = {
foo = "bar"
key = "value"
}
security_group = [
var.security_group_id
]
Expand All @@ -55,6 +60,11 @@ resource "huaweicloud_waf_dedicated_instance" "test" {
enterprise_project_id = var.enterprise_project_id
res_tenant = true
tags = {
foo = "bar"
key = "value"
}
security_group = [
var.security_group_id
]
Expand Down Expand Up @@ -113,6 +123,10 @@ The following arguments are supported:
* `anti_affinity` - (Optional, Bool, ForceNew) Specifies whether to enable anti-affinity. This field is valid only
when `res_tenant` is set to **true**. Changing this will create a new instance.

* `tags` - (Optional, Map, ForceNew) Specifies the key/value pairs to associate with the WAF dedicated instance.

Changing this will create a new instance.

## Attribute Reference

The following attributes are exported:
Expand Down Expand Up @@ -162,8 +176,8 @@ $ terraform import huaweicloud_waf_dedicated_instance.test <id>/<enterprise_proj
```

Note that the imported state may not be identical to your resource definition, due to some attributes missing from the
API response. The missing attributes include: `res_tenant`, `anti_affinity`. It is generally recommended running
`terraform plan` after importing the resource. You can then decide if changes should be applied to the resource,
API response. The missing attributes include: `res_tenant`, `anti_affinity`, and `tags`. It is generally recommended
running `terraform plan` after importing the resource. You can then decide if changes should be applied to the resource,
or the resource definition should be updated to align with the resource. Also, you can ignore changes as below.

```hcl
Expand All @@ -172,7 +186,7 @@ resource "huaweicloud_waf_dedicated_instance" "test" {
lifecycle {
ignore_changes = [
res_tenant, anti_affinity,
res_tenant, anti_affinity, tags,
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962
github.com/chnsz/golangsdk v0.0.0-20241213035404-0fa410816029
github.com/chnsz/golangsdk v0.0.0-20241216072004-832ec6af9950
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chnsz/golangsdk v0.0.0-20241213035404-0fa410816029 h1:76LXmVL0hOBGnQqKm8wEr/7T6UpYTirefLUj4pQbglQ=
github.com/chnsz/golangsdk v0.0.0-20241213035404-0fa410816029/go.mod h1:Erm4hDWxXgAdbkG3+hhJFgRzEL1TvvcroWzw2Gax4uI=
github.com/chnsz/golangsdk v0.0.0-20241216072004-832ec6af9950 h1:R3Krq0w3Qril7BxLpZAPW6n4C8Cc6at1wFpyuIaecEw=
github.com/chnsz/golangsdk v0.0.0-20241216072004-832ec6af9950/go.mod h1:Erm4hDWxXgAdbkG3+hhJFgRzEL1TvvcroWzw2Gax4uI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func TestAccDedicatedInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "upgradable", "0"),
resource.TestCheckResourceAttr(resourceName, "res_tenant", "true"),
resource.TestCheckResourceAttr(resourceName, "anti_affinity", "true"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "tags.key", "value"),
resource.TestCheckResourceAttrSet(resourceName, "server_id"),
resource.TestCheckResourceAttrSet(resourceName, "service_ip"),
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
Expand All @@ -82,6 +84,8 @@ func TestAccDedicatedInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "upgradable", "0"),
resource.TestCheckResourceAttr(resourceName, "res_tenant", "true"),
resource.TestCheckResourceAttr(resourceName, "anti_affinity", "true"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "tags.key", "value"),
resource.TestCheckResourceAttrSet(resourceName, "server_id"),
resource.TestCheckResourceAttrSet(resourceName, "service_ip"),
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
Expand All @@ -95,7 +99,7 @@ func TestAccDedicatedInstance_basic(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testWAFResourceImportState(resourceName),
ImportStateVerifyIgnore: []string{"res_tenant", "anti_affinity"},
ImportStateVerifyIgnore: []string{"res_tenant", "anti_affinity", "tags"},
},
},
})
Expand All @@ -116,6 +120,11 @@ resource "huaweicloud_waf_dedicated_instance" "test" {
anti_affinity = true
enterprise_project_id = "%[3]s"
tags = {
foo = "bar"
key = "value"
}
security_group = [
huaweicloud_networking_secgroup.test.id
]
Expand All @@ -138,6 +147,11 @@ resource "huaweicloud_waf_dedicated_instance" "test" {
anti_affinity = true
enterprise_project_id = "%[3]s"
tags = {
foo = "bar"
key = "value"
}
security_group = [
huaweicloud_networking_secgroup.test.id
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func ResourceWafDedicatedInstance() *schema.Resource {
Optional: true,
ForceNew: true,
},
// This field has no response return value.
"tags": common.TagsForceNewSchema(),

"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -158,6 +161,7 @@ func buildCreateOpts(d *schema.ResourceData, region string) *instances.CreateIns
Count: 1,
PoolId: d.Get("group_id").(string),
ResTenant: utils.Bool(d.Get("res_tenant").(bool)),
Tags: utils.ExpandResourceTags(d.Get("tags").(map[string]interface{})),
}
if d.Get("res_tenant").(bool) {
// `anti_affinity` is valid only when `res_tenant` is true
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ github.com/apparentlymart/go-cidr/cidr
# github.com/apparentlymart/go-textseg/v13 v13.0.0
## explicit; go 1.16
github.com/apparentlymart/go-textseg/v13/textseg
# github.com/chnsz/golangsdk v0.0.0-20241213035404-0fa410816029
# github.com/chnsz/golangsdk v0.0.0-20241216072004-832ec6af9950
## explicit; go 1.14
github.com/chnsz/golangsdk
github.com/chnsz/golangsdk/auth
Expand Down Expand Up @@ -296,7 +296,6 @@ github.com/chnsz/golangsdk/openstack/networking/v3/eips
github.com/chnsz/golangsdk/openstack/networking/v3/security/groups
github.com/chnsz/golangsdk/openstack/networking/v3/security/rules
github.com/chnsz/golangsdk/openstack/obs
github.com/chnsz/golangsdk/openstack/opengauss/v3/backups
github.com/chnsz/golangsdk/openstack/opengauss/v3/instances
github.com/chnsz/golangsdk/openstack/rds/v3/backups
github.com/chnsz/golangsdk/openstack/rds/v3/configurations
Expand Down

0 comments on commit 648d1a8

Please sign in to comment.