Skip to content

Commit

Permalink
Add project_id to fw_rule_v2 resource and data-source
Browse files Browse the repository at this point in the history
  • Loading branch information
nikParasyr committed Jun 30, 2023
1 parent 12dad57 commit 4cefdab
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 19 deletions.
8 changes: 4 additions & 4 deletions docs/data-sources/fw_group_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ data "openstack_fw_group_v2" "group" {

* `group_id` - (Optional) The ID of the firewall group.

* `tenant_id` - (Optional) - This argument conflict and interchangeable with
`project_id`. The owner of the firewall group.
* `tenant_id` - (Optional) - This argument conflicts and is interchangeable
with `project_id`. The owner of the firewall group.

* `project_id` - (Optional) - This argument conflict and interchangeable with
`tenant_id`. The owner of the firewall group.
* `project_id` - (Optional) - This argument conflicts and is interchangeable
with `tenant_id`. The owner of the firewall group.

* `shared` - (Optional) The sharing status of the firewall group.

Expand Down
7 changes: 6 additions & 1 deletion docs/data-sources/fw_rule_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ data "openstack_fw_rule_v2" "rule" {

* `description` - (Optional) The description of the firewall rule.

* `tenant_id` - (Optional) The owner of the firewall policy.
* `tenant_id` - (Optional) - This argument conflicts and is interchangeable
with `project_id`. The owner of the firewall rule.

* `project_id` - (Optional) - This argument conflicts and is interchangeable
with `tenant_id`. The owner of the firewall rule.

* `protocol` - (Optional) The protocol type on which the firewall rule operates.

Expand Down Expand Up @@ -64,6 +68,7 @@ The following attributes are exported:
* `name` - See Argument Reference above.
* `description` - See Argument Reference above.
* `tenant_id` - See Argument Reference above.
* `project_id` - See Argument Reference above.
* `protocol` - See Argument Reference above.
* `action` - See Argument Reference above.
* `ip_version` - See Argument Reference above.
Expand Down
8 changes: 4 additions & 4 deletions docs/resources/fw_group_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ The following arguments are supported:
* `description` - (Optional) A description for the firewall group. Changing this
updates the `description` of an existing firewall group.

* `tenant_id` - (Optional) - This argument conflict and interchangeable with
* `tenant_id` - (Optional) - This argument conflicts and is interchangeable with
`project_id`. The owner of the firewall group. Required if admin wants to
create a firewall group for another tenant. Changing this creates a new
firewall group.

* `project_id` - (Optional) - This argument conflict and interchangeable with
`tenant_id`. The owner of the firewall group. Required if admin wants to
create a firewall group for another project. Changing this creates a new
* `project_id` - (Optional) - This argument conflicts and is interchangeable
with `tenant_id`. The owner of the firewall group. Required if admin wants
to create a firewall group for another project. Changing this creates a new
firewall group.

* `ingress_firewall_policy_id` - (Optional) The ingress firewall policy resource
Expand Down
13 changes: 10 additions & 3 deletions docs/resources/fw_rule_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ The following arguments are supported:
* `description` - (Optional) A description for the firewall rule. Changing this
updates the `description` of an existing firewall rule.

* `tenant_id` - (Optional) The owner of the firewall rule. Required if admin
wants to create a firewall rule for another tenant. Changing this creates a
new firewall rule.
* `tenant_id` - (Optional) - This argument conflicts and is interchangeable
with `project_id`. The owner of the firewall rule. Required if admin wants
to create a firewall rule for another tenant. Changing this creates a new
firewall rule.

* `project_id` - (Optional) - This argument conflicts and is interchangeable
with `tenant_id`. The owner of the firewall rule. Required if admin wants
to create a firewall rule for another project. Changing this creates a new
firewall rule.

* `protocol` - (Optional; Required if `source_port` or `destination_port` is not
empty) The protocol type on which the firewall rule operates.
Expand Down Expand Up @@ -90,6 +96,7 @@ The following attributes are exported:
* `name` - See Argument Reference above.
* `description` - See Argument Reference above.
* `tenant_id` - See Argument Reference above.
* `project_id` - See Argument Reference above.
* `protocol` - See Argument Reference above.
* `action` - See Argument Reference above.
* `ip_version` - See Argument Reference above.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/terraform-provider-openstack/terraform-provider-openstack
go 1.20

require (
github.com/gophercloud/gophercloud v1.4.0
github.com/gophercloud/gophercloud v1.5.1-0.20230630055749-157270b09bb3
github.com/gophercloud/utils v0.0.0-20230324070755-05e9e7f5ea4d
github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0
github.com/mitchellh/go-homedir v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/gophercloud/gophercloud v1.1.1/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM=
github.com/gophercloud/gophercloud v1.4.0 h1:RqEu43vaX0lb0LanZr5BylK5ICVxjpFFoc0sxivyuHU=
github.com/gophercloud/gophercloud v1.4.0/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM=
github.com/gophercloud/gophercloud v1.5.1-0.20230630055749-157270b09bb3 h1:NX1ukZLZGM034ZaXYcf5uEUxsuP4pImVpIxv0dhdvRQ=
github.com/gophercloud/gophercloud v1.5.1-0.20230630055749-157270b09bb3/go.mod h1:aAVqcocTSXh2vYFZ1JTvx4EQmfgzxRcNupUfxZbBNDM=
github.com/gophercloud/utils v0.0.0-20230324070755-05e9e7f5ea4d h1:AfRlf5NnsYsHIW5nNxhYp+99Bmj/fLeOYwD5Z4CMlzw=
github.com/gophercloud/utils v0.0.0-20230324070755-05e9e7f5ea4d/go.mod h1:z4Dey7xsTUXgcB1C8elMvGRKTjV1ez0eoYQlMrduG1g=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
Expand Down
19 changes: 16 additions & 3 deletions openstack/data_source_openstack_fw_rule_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ func dataSourceFWRuleV2() *schema.Resource {
},

"tenant_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Computed: true,
Optional: true,
ConflictsWith: []string{"project_id"},
},

"project_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{"tenant_id"},
},

"description": {
Expand Down Expand Up @@ -137,6 +145,10 @@ func dataSourceFWRuleV2Read(ctx context.Context, d *schema.ResourceData, meta in
listOpts.TenantID = v.(string)
}

if v, ok := d.GetOk("project_id"); ok {
listOpts.ProjectID = v.(string)
}

if v, ok := d.GetOk("protocol"); ok {
listOpts.Protocol = rules.Protocol(v.(string))
}
Expand Down Expand Up @@ -202,6 +214,7 @@ func dataSourceFWRuleV2Read(ctx context.Context, d *schema.ResourceData, meta in
d.Set("name", rule.Name)
d.Set("description", rule.Description)
d.Set("tenant_id", rule.TenantID)
d.Set("project_id", rule.ProjectID)
d.Set("action", rule.Action)
d.Set("ip_version", rule.IPVersion)
d.Set("source_ip_address", rule.SourceIPAddress)
Expand Down
19 changes: 16 additions & 3 deletions openstack/resource_openstack_fw_rule_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ func resourceFWRuleV2() *schema.Resource {
},

"tenant_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ConflictsWith: []string{"project_id"},
},

"project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ConflictsWith: []string{"tenant_id"},
},

"protocol": {
Expand Down Expand Up @@ -128,6 +138,7 @@ func resourceFWRuleV2Create(ctx context.Context, d *schema.ResourceData, meta in
SourcePort: d.Get("source_port").(string),
DestinationPort: d.Get("destination_port").(string),
TenantID: d.Get("tenant_id").(string),
ProjectID: d.Get("project_id").(string),
}

if v, ok := d.GetOk("shared"); ok {
Expand Down Expand Up @@ -178,6 +189,8 @@ func resourceFWRuleV2Read(_ context.Context, d *schema.ResourceData, meta interf
d.Set("destination_port", rule.DestinationPort)
d.Set("shared", rule.Shared)
d.Set("enabled", rule.Enabled)
d.Set("tenant_id", rule.TenantID)
d.Set("project_id", rule.ProjectID)

if rule.Protocol == "" {
d.Set("protocol", "any")
Expand Down

0 comments on commit 4cefdab

Please sign in to comment.