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 4cefdab commit 60d9538
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
7 changes: 6 additions & 1 deletion docs/data-sources/fw_policy_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ data "openstack_fw_policy_v2" "policy" {

* `policy_id` - (Optional) The ID of the firewall policy.

* `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 policy.

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

* `shared` - (Optional) Whether this policy is shared across all projects.

Expand All @@ -45,6 +49,7 @@ The following attributes are exported:
* `name` - See Argument Reference above.
* `policy_id` - See Argument Reference above.
* `tenant_id` - See Argument Reference above.
* `project_id` - See Argument Reference above.
* `shared` - The sharing status of the firewall policy.
* `audited` - The audit status of the firewall policy.
* `rules` - The array of one or more firewall rules that comprise the policy.
13 changes: 10 additions & 3 deletions docs/resources/fw_policy_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ The following arguments are supported:
* `description` - (Optional) A description for the firewall policy. Changing
this updates the `description` of an existing firewall policy.

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

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

* `rules` - (Optional) An array of one or more firewall rules that comprise
the policy. Changing this results in adding/removing rules from the
Expand All @@ -86,6 +92,7 @@ The following attributes are exported:
* `region` - See Argument Reference above.
* `name` - See Argument Reference above.
* `tenant_id` - See Argument Reference above.
* `project_id` - See Argument Reference above.
* `description` - See Argument Reference above.
* `rules` - See Argument Reference above.
* `audited` - See Argument Reference above.
Expand Down
20 changes: 16 additions & 4 deletions openstack/data_source_openstack_fw_policy_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ func dataSourceFWPolicyV2() *schema.Resource {
},

"tenant_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: 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 @@ -90,6 +97,10 @@ func dataSourceFWPolicyV2Read(ctx context.Context, d *schema.ResourceData, meta
listOpts.TenantID = v.(string)
}

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

if v, ok := d.GetOk("shared"); ok {
shared := v.(bool)
listOpts.Shared = &shared
Expand Down Expand Up @@ -126,6 +137,7 @@ func dataSourceFWPolicyV2Read(ctx context.Context, d *schema.ResourceData, meta

d.Set("name", policy.Name)
d.Set("tenant_id", policy.TenantID)
d.Set("project_id", policy.ProjectID)
d.Set("description", policy.Description)
d.Set("shared", policy.Shared)
d.Set("audited", policy.Audited)
Expand Down
19 changes: 15 additions & 4 deletions openstack/resource_openstack_fw_policy_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ func resourceFWPolicyV2() *schema.Resource {
},

"tenant_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: 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"},
},

"audited": {
Expand Down Expand Up @@ -82,6 +91,7 @@ func resourceFWPolicyV2Create(ctx context.Context, d *schema.ResourceData, meta
Name: d.Get("name").(string),
Description: d.Get("description").(string),
TenantID: d.Get("tenant_id").(string),
ProjectID: d.Get("project_id").(string),
FirewallRules: expandToStringSlice(d.Get("rules").([]interface{})),
}

Expand Down Expand Up @@ -126,6 +136,7 @@ func resourceFWPolicyV2Read(_ context.Context, d *schema.ResourceData, meta inte
d.Set("name", policy.Name)
d.Set("description", policy.Description)
d.Set("tenant_id", policy.TenantID)
d.Set("project_id", policy.ProjectID)
d.Set("rules", policy.Rules)
d.Set("audited", policy.Audited)
d.Set("shared", policy.Shared)
Expand Down

0 comments on commit 60d9538

Please sign in to comment.