Skip to content

Commit

Permalink
refactor(vpc): change eps ID to optional in network_acl (#6115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 authored Dec 30, 2024
1 parent a9d9658 commit 952caff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/resources/vpc_network_acl.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ The following arguments are supported:
* `name` - (Required, String) Specifies the network ACL name. The value can contain no more than 64 characters,
including letters, digits, underscores (_), hyphens (-), and periods (.).

* `enterprise_project_id` - (Required, String) Specifies the enterprise project ID of the network ACL.
* `enterprise_project_id` - (Optional, String) Specifies the enterprise project ID of the network ACL.

* `description` - (Optional, String) Specifies the network ACL description. The value can contain no more
than 255 characters and cannot contain angle brackets (< or >).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ resource "huaweicloud_vpc_subnet" "test" {
}
resource "huaweicloud_vpc_network_acl" "test" {
name = "%s"
description = "created by terraform"
enterprise_project_id = 0
name = "%s"
description = "created by terraform"
ingress_rules {
action = "allow"
Expand Down Expand Up @@ -222,10 +221,9 @@ resource "huaweicloud_vpc_subnet" "test" {
}
resource "huaweicloud_vpc_network_acl" "test" {
name = "%s-update"
description = "created by terraform update"
enterprise_project_id = 0
enabled = false
name = "%s-update"
description = "created by terraform update"
enabled = false
ingress_rules {
action = "allow"
Expand Down Expand Up @@ -297,10 +295,9 @@ resource "huaweicloud_vpc_subnet" "test" {
}
resource "huaweicloud_vpc_network_acl" "test" {
name = "%s-update"
description = "created by terraform update"
enterprise_project_id = 0
enabled = false
name = "%s-update"
description = "created by terraform update"
enabled = false
ingress_rules {
action = "allow"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func ResourceNetworkAcl() *schema.Resource {
},
"enterprise_project_id": {
Type: schema.TypeString,
Required: true,
Optional: true,
Computed: true,
},
"description": {
Type: schema.TypeString,
Expand Down Expand Up @@ -185,7 +186,7 @@ func resourceNetworkAclCreate(ctx context.Context, d *schema.ResourceData, meta
},
}

createNetworkAclOpt.JSONBody = utils.RemoveNil(buildCreateNetworkAclBodyParams(d))
createNetworkAclOpt.JSONBody = utils.RemoveNil(buildCreateNetworkAclBodyParams(d, cfg))
createNetworkAclResp, err := client.Request("POST", createNetworkAclPath, &createNetworkAclOpt)
if err != nil {
return diag.Errorf("error creating network ACL: %s", err)
Expand Down Expand Up @@ -324,11 +325,11 @@ func networkAclDisassociatSubnets(client *golangsdk.ServiceClient, subnets []int
return nil
}

func buildCreateNetworkAclBodyParams(d *schema.ResourceData) map[string]interface{} {
func buildCreateNetworkAclBodyParams(d *schema.ResourceData, cfg *config.Config) map[string]interface{} {
bodyParams := map[string]interface{}{
"firewall": map[string]interface{}{
"name": d.Get("name"),
"enterprise_project_id": d.Get("enterprise_project_id"),
"enterprise_project_id": utils.ValueIgnoreEmpty(cfg.GetEnterpriseProjectID(d)),
"description": utils.ValueIgnoreEmpty(d.Get("description")),
"admin_state_up": d.Get("enabled"),
},
Expand Down

0 comments on commit 952caff

Please sign in to comment.