Skip to content

fix(cfw): [121355580] Update CFW resource logic #3142

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
merged 5 commits into from
Feb 21, 2025
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
7 changes: 7 additions & 0 deletions .changelog/3142.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/tencentcloud_cfw_edge_policy: Update resource fields and code logic
```

```release-note:enhancement
resource/tencentcloud_cfw_nat_policy: Update resource fields and code logic
```
15 changes: 14 additions & 1 deletion tencentcloud/services/cfw/resource_tc_cfw_edge_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ func ResourceTencentCloudCfwEdgePolicy() *schema.Resource {
"scope": {
Type: schema.TypeString,
Optional: true,
Default: POLICY_SCOPE_ALL,
Computed: true,
ValidateFunc: tccommon.ValidateAllowedStringValue(POLICY_SCOPE),
Description: "Effective range. serial: serial; side: bypass; all: global, Default is all.",
},
"param_template_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Parameter template id.",
},
Expand Down Expand Up @@ -157,6 +158,10 @@ func resourceTencentCloudCfwEdgePolicyCreate(d *schema.ResourceData, meta interf
createRuleItem.Scope = helper.String(v.(string))
}

if v, ok := d.GetOk("param_template_id"); ok {
createRuleItem.ParamTemplateId = helper.String(v.(string))
}

request.Rules = append(request.Rules, &createRuleItem)

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
Expand Down Expand Up @@ -251,6 +256,10 @@ func resourceTencentCloudCfwEdgePolicyRead(d *schema.ResourceData, meta interfac
_ = d.Set("protocol", edgePolicy.Protocol)
}

if edgePolicy.RuleAction != nil {
_ = d.Set("rule_action", edgePolicy.RuleAction)
}

if edgePolicy.Port != nil {
_ = d.Set("port", edgePolicy.Port)
}
Expand Down Expand Up @@ -348,6 +357,10 @@ func resourceTencentCloudCfwEdgePolicyUpdate(d *schema.ResourceData, meta interf
modifyRuleItem.Scope = helper.String(v.(string))
}

if v, ok := d.GetOk("param_template_id"); ok {
modifyRuleItem.ParamTemplateId = helper.String(v.(string))
}

request.Rules = append(request.Rules, &modifyRuleItem)

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
Expand Down
6 changes: 3 additions & 3 deletions tencentcloud/services/cfw/resource_tc_cfw_edge_policy.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Provides a resource to create a cfw edge_policy
Provides a resource to create a CFW edge policy

Example Usage

Expand Down Expand Up @@ -38,8 +38,8 @@ resource "tencentcloud_cfw_edge_policy" "example" {

Import

cfw edge_policy can be imported using the id, e.g.
CFW edge policy can be imported using the id, e.g.

```
terraform import tencentcloud_cfw_edge_policy.example edge_policy_id
terraform import tencentcloud_cfw_edge_policy.example 1859582
```
36 changes: 36 additions & 0 deletions tencentcloud/services/cfw/resource_tc_cfw_nat_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,21 @@ func ResourceTencentCloudCfwNatPolicy() *schema.Resource {
},
"param_template_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Parameter template id. Note: This field may return null, indicating that no valid value can be obtained.",
},
"internal_uuid": {
Type: schema.TypeInt,
Computed: true,
Description: "Internal ID.",
},
"scope": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Scope of effective rules. ALL: Global effectiveness; ap-guangzhou: Effective territory; cfwnat-xxx: Effectiveness based on instance dimension.",
},
},
}
}
Expand Down Expand Up @@ -144,6 +156,14 @@ func resourceTencentCloudCfwNatPolicyCreate(d *schema.ResourceData, meta interfa
createNatRuleItem.Description = helper.String(v.(string))
}

if v, ok := d.GetOk("param_template_id"); ok {
createNatRuleItem.ParamTemplateId = helper.String(v.(string))
}

if v, ok := d.GetOk("scope"); ok {
createNatRuleItem.Scope = helper.String(v.(string))
}

request.Rules = append(request.Rules, &createNatRuleItem)

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
Expand Down Expand Up @@ -212,6 +232,10 @@ func resourceTencentCloudCfwNatPolicyRead(d *schema.ResourceData, meta interface
_ = d.Set("protocol", natPolicy.Protocol)
}

if natPolicy.RuleAction != nil {
_ = d.Set("rule_action", natPolicy.RuleAction)
}

if natPolicy.Port != nil {
_ = d.Set("port", natPolicy.Port)
}
Expand Down Expand Up @@ -240,6 +264,10 @@ func resourceTencentCloudCfwNatPolicyRead(d *schema.ResourceData, meta interface
_ = d.Set("param_template_id", natPolicy.ParamTemplateId)
}

if natPolicy.InternalUuid != nil {
_ = d.Set("internal_uuid", natPolicy.InternalUuid)
}

return nil
}

Expand Down Expand Up @@ -305,6 +333,14 @@ func resourceTencentCloudCfwNatPolicyUpdate(d *schema.ResourceData, meta interfa
modifyRuleItem.Description = helper.String(v.(string))
}

if v, ok := d.GetOk("param_template_id"); ok {
modifyRuleItem.ParamTemplateId = helper.String(v.(string))
}

if v, ok := d.GetOk("scope"); ok {
modifyRuleItem.Scope = helper.String(v.(string))
}

request.Rules = append(request.Rules, &modifyRuleItem)

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
Expand Down
7 changes: 4 additions & 3 deletions tencentcloud/services/cfw/resource_tc_cfw_nat_policy.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Provides a resource to create a cfw nat_policy
Provides a resource to create a CFW nat policy

Example Usage

Expand All @@ -14,13 +14,14 @@ resource "tencentcloud_cfw_nat_policy" "example" {
direction = 1
enable = "true"
description = "policy description."
scope = "ALL"
}
```

Import

cfw nat_policy can be imported using the id, e.g.
CFW nat policy can be imported using the id, e.g.

```
terraform import tencentcloud_cfw_nat_policy.example nat_policy_id
terraform import tencentcloud_cfw_nat_policy.example 134123
```
10 changes: 5 additions & 5 deletions website/docs/r/cfw_edge_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ layout: "tencentcloud"
page_title: "TencentCloud: tencentcloud_cfw_edge_policy"
sidebar_current: "docs-tencentcloud-resource-cfw_edge_policy"
description: |-
Provides a resource to create a cfw edge_policy
Provides a resource to create a CFW edge policy
---

# tencentcloud_cfw_edge_policy

Provides a resource to create a cfw edge_policy
Provides a resource to create a CFW edge policy

## Example Usage

Expand Down Expand Up @@ -61,22 +61,22 @@ The following arguments are supported:
* `target_type` - (Required, String) Access purpose type: For inbound rules, the type can be net, instance, tag, template, group; for outbound rules, it can be net, location, vendor, template.
* `description` - (Optional, String) Description.
* `enable` - (Optional, String) Rule status, true means enabled, false means disabled. Default is true.
* `param_template_id` - (Optional, String) Parameter template id.
* `scope` - (Optional, String) Effective range. serial: serial; side: bypass; all: global, Default is all.

## Attributes Reference

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

* `id` - ID of the resource.
* `param_template_id` - Parameter template id.
* `uuid` - The unique id corresponding to the rule, no need to fill in when creating the rule.


## Import

cfw edge_policy can be imported using the id, e.g.
CFW edge policy can be imported using the id, e.g.

```
terraform import tencentcloud_cfw_edge_policy.example edge_policy_id
terraform import tencentcloud_cfw_edge_policy.example 1859582
```

13 changes: 8 additions & 5 deletions website/docs/r/cfw_nat_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ layout: "tencentcloud"
page_title: "TencentCloud: tencentcloud_cfw_nat_policy"
sidebar_current: "docs-tencentcloud-resource-cfw_nat_policy"
description: |-
Provides a resource to create a cfw nat_policy
Provides a resource to create a CFW nat policy
---

# tencentcloud_cfw_nat_policy

Provides a resource to create a cfw nat_policy
Provides a resource to create a CFW nat policy

## Example Usage

Expand All @@ -25,6 +25,7 @@ resource "tencentcloud_cfw_nat_policy" "example" {
direction = 1
enable = "true"
description = "policy description."
scope = "ALL"
}
```

Expand All @@ -42,21 +43,23 @@ The following arguments are supported:
* `target_type` - (Required, String) Access purpose type: For inbound rules, the type can be net, instance, tag, template, group; for outbound rules, it can be net, location, vendor, template.
* `description` - (Optional, String) Description.
* `enable` - (Optional, String) Rule status, true means enabled, false means disabled. Default is true.
* `param_template_id` - (Optional, String) Parameter template id. Note: This field may return null, indicating that no valid value can be obtained.
* `scope` - (Optional, String) Scope of effective rules. ALL: Global effectiveness; ap-guangzhou: Effective territory; cfwnat-xxx: Effectiveness based on instance dimension.

## Attributes Reference

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

* `id` - ID of the resource.
* `param_template_id` - Parameter template id. Note: This field may return null, indicating that no valid value can be obtained.
* `internal_uuid` - Internal ID.
* `uuid` - The unique id corresponding to the rule, no need to fill in when creating the rule.


## Import

cfw nat_policy can be imported using the id, e.g.
CFW nat policy can be imported using the id, e.g.

```
terraform import tencentcloud_cfw_nat_policy.example nat_policy_id
terraform import tencentcloud_cfw_nat_policy.example 134123
```

Loading