Skip to content

Commit 63c2d49

Browse files
Add priority field to regional network firewall policy association (#16726) (#11770)
[upstream:05e0dac3ad176d8ad214b41baf27bdff71f5cad5] Signed-off-by: Modular Magician <[email protected]>
1 parent e04bc93 commit 63c2d49

5 files changed

+129
-0
lines changed

.changelog/16726.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `priority` field to `google_compute_region_network_firewall_policy_association` resource
3+
```

google-beta/services/compute/resource_compute_region_network_firewall_policy_association.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ func ResourceComputeRegionNetworkFirewallPolicyAssociation() *schema.Resource {
136136
ForceNew: true,
137137
Description: `The name for an association.`,
138138
},
139+
"priority": {
140+
Type: schema.TypeInt,
141+
Computed: true,
142+
Optional: true,
143+
ForceNew: true,
144+
Description: `An integer indicating the priority of an association.`,
145+
},
139146
"region": {
140147
Type: schema.TypeString,
141148
Computed: true,
@@ -179,6 +186,12 @@ func resourceComputeRegionNetworkFirewallPolicyAssociationCreate(d *schema.Resou
179186
} else if v, ok := d.GetOkExists("attachment_target"); !tpgresource.IsEmptyValue(reflect.ValueOf(attachmentTargetProp)) && (ok || !reflect.DeepEqual(v, attachmentTargetProp)) {
180187
obj["attachmentTarget"] = attachmentTargetProp
181188
}
189+
priorityProp, err := expandComputeRegionNetworkFirewallPolicyAssociationPriority(d.Get("priority"), d, config)
190+
if err != nil {
191+
return err
192+
} else if v, ok := d.GetOkExists("priority"); !tpgresource.IsEmptyValue(reflect.ValueOf(priorityProp)) && (ok || !reflect.DeepEqual(v, priorityProp)) {
193+
obj["priority"] = priorityProp
194+
}
182195

183196
url, err := tpgresource.ReplaceVarsForId(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/addAssociation")
184197
if err != nil {
@@ -287,6 +300,9 @@ func resourceComputeRegionNetworkFirewallPolicyAssociationRead(d *schema.Resourc
287300
if err := d.Set("short_name", flattenComputeRegionNetworkFirewallPolicyAssociationShortName(res["shortName"], d, config)); err != nil {
288301
return fmt.Errorf("Error reading RegionNetworkFirewallPolicyAssociation: %s", err)
289302
}
303+
if err := d.Set("priority", flattenComputeRegionNetworkFirewallPolicyAssociationPriority(res["priority"], d, config)); err != nil {
304+
return fmt.Errorf("Error reading RegionNetworkFirewallPolicyAssociation: %s", err)
305+
}
290306

291307
return nil
292308
}
@@ -381,10 +397,31 @@ func flattenComputeRegionNetworkFirewallPolicyAssociationShortName(v interface{}
381397
return v
382398
}
383399

400+
func flattenComputeRegionNetworkFirewallPolicyAssociationPriority(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
401+
// Handles the string fixed64 format
402+
if strVal, ok := v.(string); ok {
403+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
404+
return intVal
405+
}
406+
}
407+
408+
// number values are represented as float64
409+
if floatVal, ok := v.(float64); ok {
410+
intVal := int(floatVal)
411+
return intVal
412+
}
413+
414+
return v // let terraform core handle it otherwise
415+
}
416+
384417
func expandComputeRegionNetworkFirewallPolicyAssociationName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
385418
return v, nil
386419
}
387420

388421
func expandComputeRegionNetworkFirewallPolicyAssociationAttachmentTarget(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
389422
return v, nil
390423
}
424+
425+
func expandComputeRegionNetworkFirewallPolicyAssociationPriority(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
426+
return v, nil
427+
}

google-beta/services/compute/resource_compute_region_network_firewall_policy_association_generated_meta.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ fields:
1111
provider_only: true
1212
- api_field: associations.name
1313
field: name
14+
- api_field: associations.priority
15+
field: priority
1416
- field: region
1517
provider_only: true
1618
- api_field: associations.shortName

google-beta/services/compute/resource_compute_region_network_firewall_policy_association_generated_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,61 @@ resource "google_compute_region_network_firewall_policy_association" "default" {
101101
`, context)
102102
}
103103

104+
func TestAccComputeRegionNetworkFirewallPolicyAssociation_regionNetworkFirewallPolicyAssociationPriorityExample(t *testing.T) {
105+
t.Parallel()
106+
107+
context := map[string]interface{}{
108+
"project_name": envvar.GetTestProjectFromEnv(),
109+
"region": envvar.GetTestRegionFromEnv(),
110+
"random_suffix": acctest.RandString(t, 10),
111+
}
112+
113+
acctest.VcrTest(t, resource.TestCase{
114+
PreCheck: func() { acctest.AccTestPreCheck(t) },
115+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
116+
CheckDestroy: testAccCheckComputeRegionNetworkFirewallPolicyAssociationDestroyProducer(t),
117+
Steps: []resource.TestStep{
118+
{
119+
Config: testAccComputeRegionNetworkFirewallPolicyAssociation_regionNetworkFirewallPolicyAssociationPriorityExample(context),
120+
},
121+
{
122+
ResourceName: "google_compute_region_network_firewall_policy_association.association",
123+
ImportState: true,
124+
ImportStateVerify: true,
125+
ImportStateVerifyIgnore: []string{"firewall_policy", "region"},
126+
},
127+
},
128+
})
129+
}
130+
131+
func testAccComputeRegionNetworkFirewallPolicyAssociation_regionNetworkFirewallPolicyAssociationPriorityExample(context map[string]interface{}) string {
132+
return acctest.Nprintf(`
133+
resource "google_compute_region_network_firewall_policy" "policy" {
134+
provider = google-beta
135+
name = "tf-test-my-policy%{random_suffix}"
136+
project = "%{project_name}"
137+
description = "Sample global network firewall policy"
138+
region = "%{region}"
139+
}
140+
141+
resource "google_compute_network" "network" {
142+
provider = google-beta
143+
name = "tf-test-my-network%{random_suffix}"
144+
auto_create_subnetworks = false
145+
}
146+
147+
resource "google_compute_region_network_firewall_policy_association" "association" {
148+
provider = google-beta
149+
name = "tf-test-my-association%{random_suffix}"
150+
project = "%{project_name}"
151+
attachment_target = google_compute_network.network.id
152+
firewall_policy = google_compute_region_network_firewall_policy.policy.id
153+
region = "%{region}"
154+
priority = 1
155+
}
156+
`, context)
157+
}
158+
104159
func testAccCheckComputeRegionNetworkFirewallPolicyAssociationDestroyProducer(t *testing.T) func(s *terraform.State) error {
105160
return func(s *terraform.State) error {
106161
for name, rs := range s.RootModule().Resources {

website/docs/r/compute_region_network_firewall_policy_association.html.markdown

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,34 @@ resource "google_compute_region_network_firewall_policy_association" "default" {
5252
region = "us-west1"
5353
}
5454
```
55+
## Example Usage - Region Network Firewall Policy Association Priority
56+
57+
58+
```hcl
59+
resource "google_compute_region_network_firewall_policy" "policy" {
60+
provider = google-beta
61+
name = "my-policy"
62+
project = "my-project-name"
63+
description = "Sample global network firewall policy"
64+
region = "us-west1"
65+
}
66+
67+
resource "google_compute_network" "network" {
68+
provider = google-beta
69+
name = "my-network"
70+
auto_create_subnetworks = false
71+
}
72+
73+
resource "google_compute_region_network_firewall_policy_association" "association" {
74+
provider = google-beta
75+
name = "my-association"
76+
project = "my-project-name"
77+
attachment_target = google_compute_network.network.id
78+
firewall_policy = google_compute_region_network_firewall_policy.policy.id
79+
region = "us-west1"
80+
priority = 1
81+
}
82+
```
5583

5684
## Argument Reference
5785

@@ -71,6 +99,10 @@ The following arguments are supported:
7199
The firewall policy of the resource.
72100

73101

102+
* `priority` -
103+
(Optional, [Beta](../guides/provider_versions.html.markdown))
104+
An integer indicating the priority of an association.
105+
74106
* `region` -
75107
(Optional)
76108
The location of this resource.

0 commit comments

Comments
 (0)