Skip to content

Commit 71d0854

Browse files
Samir-Citc2thorn
authored andcommitted
Migrate Network Firewall Policy Association (global and region) resource from DCL to MMv1 (GoogleCloudPlatform#11366)
Co-authored-by: Cameron Thornton <[email protected]>
1 parent 721d837 commit 71d0854

14 files changed

+241
-198
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: 'NetworkFirewallPolicyAssociation'
16+
kind: 'compute#firewallPolicyAssociation'
17+
description: |
18+
The Compute NetworkFirewallPolicyAssociation resource
19+
references:
20+
guides:
21+
api: 'https://cloud.google.com/compute/docs/reference/rest/v1/networkFirewallPolicies/addAssociation'
22+
docs:
23+
id_format: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}'
24+
base_url: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}'
25+
self_link: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/getAssociation?name={{name}}'
26+
create_url: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/addAssociation'
27+
delete_url: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/removeAssociation?name={{name}}'
28+
delete_verb: 'POST'
29+
immutable: true
30+
legacy_long_form_project: true
31+
import_format:
32+
- 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}'
33+
- '{{project}}/{{firewall_policy}}/{{name}}'
34+
timeouts:
35+
insert_minutes: 20
36+
update_minutes: 20
37+
delete_minutes: 20
38+
async:
39+
actions: ['create', 'delete', 'update']
40+
type: 'OpAsync'
41+
operation:
42+
base_url: '{{op_id}}'
43+
kind: 'compute#operation'
44+
path: 'name'
45+
wait_ms: 1000
46+
result:
47+
path: 'targetLink'
48+
resource_inside_response: false
49+
error:
50+
path: 'error/errors'
51+
message: 'message'
52+
examples:
53+
- name: 'network_firewall_policy_association'
54+
primary_resource_id: 'default'
55+
vars:
56+
policy_name: 'my-policy'
57+
association_name: 'my-association'
58+
network_name: 'my-network'
59+
test_env_vars:
60+
project_name: 'PROJECT_NAME'
61+
parameters:
62+
- name: 'firewallPolicy'
63+
type: ResourceRef
64+
description: |
65+
The firewall policy of the resource.
66+
url_param_only: true
67+
required: true
68+
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
69+
resource: 'NetworkFirewallPolicy'
70+
imports: 'name'
71+
properties:
72+
- name: 'name'
73+
type: String
74+
description: |
75+
The name for an association.
76+
required: true
77+
- name: 'attachmentTarget'
78+
type: String
79+
description: |
80+
The target that the firewall policy is attached to.
81+
required: true
82+
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
83+
- name: 'shortName'
84+
type: String
85+
description: |
86+
The short name of the firewall policy of the association.
87+
output: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: 'RegionNetworkFirewallPolicyAssociation'
16+
kind: 'compute#firewallPolicyAssociation'
17+
description: |
18+
The Compute NetworkFirewallPolicyAssociation resource
19+
references:
20+
guides:
21+
api: 'https://cloud.google.com/compute/docs/reference/rest/v1/regionNetworkFirewallPolicies/addAssociation'
22+
docs:
23+
id_format: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/associations/{{name}}'
24+
base_url: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}'
25+
self_link: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/getAssociation?name={{name}}'
26+
create_url: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/addAssociation'
27+
delete_url: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/removeAssociation?name={{name}}'
28+
delete_verb: 'POST'
29+
immutable: true
30+
legacy_long_form_project: true
31+
import_format:
32+
- 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/associations/{{name}}'
33+
- '{{project}}/{{firewall_policy}}/{{name}}'
34+
timeouts:
35+
insert_minutes: 20
36+
update_minutes: 20
37+
delete_minutes: 20
38+
async:
39+
actions: ['create', 'delete', 'update']
40+
type: 'OpAsync'
41+
operation:
42+
base_url: '{{op_id}}'
43+
kind: 'compute#operation'
44+
path: 'name'
45+
wait_ms: 1000
46+
result:
47+
path: 'targetLink'
48+
resource_inside_response: false
49+
error:
50+
path: 'error/errors'
51+
message: 'message'
52+
examples:
53+
- name: 'region_network_firewall_policy_association'
54+
primary_resource_id: 'default'
55+
vars:
56+
policy_name: 'my-policy'
57+
association_name: 'my-association'
58+
network_name: 'my-network'
59+
test_env_vars:
60+
region: 'REGION'
61+
project_name: 'PROJECT_NAME'
62+
parameters:
63+
- name: 'firewallPolicy'
64+
type: ResourceRef
65+
description: |
66+
The firewall policy of the resource.
67+
url_param_only: true
68+
required: true
69+
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
70+
resource: 'RegionNetworkFirewallPolicy'
71+
imports: 'name'
72+
- name: 'region'
73+
type: String
74+
description: 'The location of this resource.'
75+
url_param_only: true
76+
default_from_api: true
77+
properties:
78+
- name: 'name'
79+
type: String
80+
description: |
81+
The name for an association.
82+
required: true
83+
- name: 'attachmentTarget'
84+
type: String
85+
description: |
86+
The target that the firewall policy is attached to.
87+
required: true
88+
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
89+
- name: 'shortName'
90+
type: String
91+
description: |
92+
The short name of the firewall policy of the association.
93+
output: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
resource "google_compute_network_firewall_policy" "policy" {
2+
name = "{{index $.Vars "policy_name"}}"
3+
project = "{{index $.TestEnvVars "project_name"}}"
4+
description = "Sample global network firewall policy"
5+
}
6+
7+
resource "google_compute_network" "network" {
8+
name = "{{index $.Vars "network_name"}}"
9+
auto_create_subnetworks = false
10+
}
11+
12+
resource "google_compute_network_firewall_policy_association" "{{$.PrimaryResourceId}}" {
13+
name = "{{index $.Vars "association_name"}}"
14+
project = "{{index $.TestEnvVars "project_name"}}"
15+
attachment_target = google_compute_network.network.id
16+
firewall_policy = google_compute_network_firewall_policy.policy.id
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "google_compute_region_network_firewall_policy" "policy" {
2+
name = "{{index $.Vars "policy_name"}}"
3+
project = "{{index $.TestEnvVars "project_name"}}"
4+
description = "Sample global network firewall policy"
5+
region = "{{index $.TestEnvVars "region"}}"
6+
}
7+
8+
resource "google_compute_network" "network" {
9+
name = "{{index $.Vars "network_name"}}"
10+
auto_create_subnetworks = false
11+
}
12+
13+
resource "google_compute_region_network_firewall_policy_association" "{{$.PrimaryResourceId}}" {
14+
name = "{{index $.Vars "association_name"}}"
15+
project = "{{index $.TestEnvVars "project_name"}}"
16+
attachment_target = google_compute_network.network.id
17+
firewall_policy = google_compute_region_network_firewall_policy.policy.id
18+
region = "{{index $.TestEnvVars "region"}}"
19+
}

mmv1/third_party/terraform/services/compute/resource_compute_network_firewall_policy_rule_test.go.tmpl

+25
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func TestAccComputeNetworkFirewallPolicyRule_multipleRules(t *testing.T) {
8686

8787
context := map[string]interface{}{
8888
"random_suffix": acctest.RandString(t, 10),
89+
"project_name": envvar.GetTestProjectFromEnv(),
8990
"org_name": fmt.Sprintf("organizations/%s", envvar.GetTestOrgFromEnv(t)),
9091
}
9192

@@ -731,11 +732,23 @@ resource "google_compute_network_firewall_policy_rule" "fw_policy_rule2" {
731732

732733
func testAccComputeNetworkFirewallPolicyRule_multipleAdd(context map[string]interface{}) string {
733734
return acctest.Nprintf(`
735+
resource "google_compute_network" "network1" {
736+
name = "tf-test-%{random_suffix}"
737+
auto_create_subnetworks = false
738+
}
739+
734740
resource "google_compute_network_firewall_policy" "fw_policy" {
735741
name = "tf-test-policy-%{random_suffix}"
736742
description = "Resource created for Terraform acceptance testing"
737743
}
738744

745+
resource "google_compute_network_firewall_policy_association" "fw_policy_a" {
746+
name = "tf-test-policy-a-%{random_suffix}"
747+
project = "projects/%{project_name}"
748+
attachment_target = google_compute_network.network1.id
749+
firewall_policy = google_compute_network_firewall_policy.fw_policy.id
750+
}
751+
739752
resource "google_network_security_address_group" "address_group" {
740753
name = "tf-test-policy%{random_suffix}"
741754
parent = "%{org_name}"
@@ -815,11 +828,23 @@ resource "google_compute_network_firewall_policy_rule" "fw_policy_rule3" {
815828

816829
func testAccComputeNetworkFirewallPolicyRule_multipleRemove(context map[string]interface{}) string {
817830
return acctest.Nprintf(`
831+
resource "google_compute_network" "network1" {
832+
name = "tf-test-%{random_suffix}"
833+
auto_create_subnetworks = false
834+
}
835+
818836
resource "google_compute_network_firewall_policy" "fw_policy" {
819837
name = "tf-test-policy-%{random_suffix}"
820838
description = "Resource created for Terraform acceptance testing"
821839
}
822840

841+
resource "google_compute_network_firewall_policy_association" "fw_policy_a" {
842+
name = "tf-test-policy-a-%{random_suffix}"
843+
project = "%{project_name}"
844+
attachment_target = google_compute_network.network1.id
845+
firewall_policy = google_compute_network_firewall_policy.fw_policy.id
846+
}
847+
823848
resource "google_network_security_address_group" "address_group" {
824849
name = "tf-test-policy%{random_suffix}"
825850
parent = "%{org_name}"

tpgtools/overrides/compute/beta/network_firewall_policy_association.yaml

-38
This file was deleted.

tpgtools/overrides/compute/network_firewall_policy_association.yaml

-38
This file was deleted.

tpgtools/overrides/compute/samples/networkfirewallpolicyassociation/global.tf.tmpl

-16
This file was deleted.

tpgtools/overrides/compute/samples/networkfirewallpolicyassociation/global.yaml

-11
This file was deleted.

0 commit comments

Comments
 (0)