Skip to content

Commit ad1b5e9

Browse files
Samir-Citc2thornmaxi-cit
authored andcommitted
Migrate google_compute_firewall_policy resource from DCL to MMv1 (GoogleCloudPlatform#11357)
Co-authored-by: Cameron Thornton <[email protected]> Co-authored-by: Max W. Portocarrero <[email protected]>
1 parent 9c2e426 commit ad1b5e9

File tree

7 files changed

+150
-112
lines changed

7 files changed

+150
-112
lines changed
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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: 'FirewallPolicy'
16+
api_resource_type_kind: FirewallPolicy
17+
description: |
18+
Hierarchical firewall policy rules let you create and enforce a consistent firewall policy across your organization. Rules can explicitly allow or deny connections or delegate evaluation to lower level policies. Policies can be created within organizations or folders.
19+
20+
This resource should be generally be used with `google_compute_firewall_policy_association` and `google_compute_firewall_policy_rule`
21+
22+
For more information see the [official documentation](https://cloud.google.com/vpc/docs/firewall-policies)
23+
min_version: 'beta'
24+
references:
25+
guides:
26+
api: 'https://cloud.google.com/compute/docs/reference/rest/v1/firewallPolicies'
27+
docs:
28+
base_url: 'locations/global/firewallPolicies'
29+
self_link: 'locations/global/firewallPolicies/{{name}}'
30+
create_url: 'locations/global/firewallPolicies?parentId={{parent}}'
31+
update_verb: 'PATCH'
32+
timeouts:
33+
insert_minutes: 20
34+
update_minutes: 20
35+
delete_minutes: 20
36+
import_format:
37+
- 'locations/global/firewallPolicies/{{name}}'
38+
- '{{name}}'
39+
custom_code:
40+
post_create: 'templates/terraform/post_create/compute_firewall_policy.go.tmpl'
41+
post_delete: 'templates/terraform/constants/compute_firewall_policy_operation.go.tmpl'
42+
post_update: 'templates/terraform/constants/compute_firewall_policy_operation.go.tmpl'
43+
custom_diff:
44+
- 'tpgresource.DefaultProviderProject'
45+
examples:
46+
- name: 'firewall_policy'
47+
primary_resource_id: 'default'
48+
vars:
49+
policy_name: 'my-policy'
50+
test_env_vars:
51+
org_id: 'ORG_ID'
52+
parameters:
53+
properties:
54+
- name: 'creationTimestamp'
55+
type: String
56+
description: |
57+
Creation timestamp in RFC3339 text format.
58+
output: true
59+
- name: 'name'
60+
type: String
61+
description: |
62+
Name of the resource. It is a numeric ID allocated by GCP which uniquely identifies the Firewall Policy.
63+
output: true
64+
- name: 'firewallPolicyId'
65+
type: String
66+
api_name: 'id'
67+
description: |
68+
The unique identifier for the resource. This identifier is defined by the server.
69+
output: true
70+
- name: 'shortName'
71+
type: String
72+
description: |
73+
User-provided name of the Organization firewall policy. The name should be unique in the organization in which the firewall policy is created.
74+
This field is not applicable to network firewall policies. This name must be set on creation and cannot be changed. The name must be 1-63 characters long, and comply with RFC1035.
75+
Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.
76+
required: true
77+
immutable: true
78+
- name: 'description'
79+
type: String
80+
description: |
81+
An optional description of this resource. Provide this property when you create the resource.
82+
- name: 'parent'
83+
type: String
84+
description: |
85+
The parent of the firewall policy.
86+
required: true
87+
immutable: true
88+
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
89+
- name: 'fingerprint'
90+
type: Fingerprint
91+
description: |
92+
Fingerprint of the resource. This field is used internally during updates of this resource.
93+
output: true
94+
- name: 'selfLink'
95+
type: String
96+
description: |
97+
Server-defined URL for the resource.
98+
output: true
99+
- name: 'selfLinkWithId'
100+
type: String
101+
description: |
102+
Server-defined URL for this resource with the resource id.
103+
output: true
104+
- name: 'ruleTupleCount'
105+
type: Integer
106+
description: |
107+
Total count of all firewall policy rule tuples. A firewall policy can not exceed a set number of tuples.
108+
output: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var opRes map[string]interface{}
2+
err = ComputeOrgOperationWaitTimeWithResponse(
3+
config, res, &opRes, d.Get("parent").(string), "FirewallPolicy operation", userAgent,
4+
d.Timeout(schema.TimeoutCreate))
5+
6+
if err != nil {
7+
// The resource didn't actually create
8+
return fmt.Errorf("Error waiting for FirewallPolicy operation: %s", err)
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "google_compute_firewall_policy" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
4+
parent = "organizations/{{index $.TestEnvVars "org_id"}}"
5+
short_name = "{{index $.Vars "policy_name"}}"
6+
description = "Example Resource"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var opRes map[string]interface{}
2+
err = ComputeOrgOperationWaitTimeWithResponse(
3+
config, res, &opRes, d.Get("parent").(string), "FirewallPolicy operation", userAgent,
4+
d.Timeout(schema.TimeoutCreate))
5+
6+
if err != nil {
7+
// The resource didn't actually create
8+
d.SetId("")
9+
return fmt.Errorf("Error waiting to create FirewallPolicy: %s", err)
10+
}
11+
12+
firewallPolicyId, ok := opRes["targetId"]
13+
if !ok {
14+
return fmt.Errorf("Create response didn't contain targetId. Create may not have succeeded.")
15+
}
16+
if err := d.Set("name", firewallPolicyId.(string)); err != nil {
17+
return fmt.Errorf(`Error setting computed identity field "name": %s`, err)
18+
}
19+
20+
// Store the ID now
21+
id, err = tpgresource.ReplaceVars(d, config, "locations/global/firewallPolicies/{{"{{"}}name{{"}}"}}")
22+
if err != nil {
23+
return fmt.Errorf("Error constructing id: %s", err)
24+
}
25+
d.SetId(id)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ resource "google_folder" "folder" {
628628
resource "google_compute_firewall_policy" "fw_policy" {
629629
parent = google_folder.folder.id
630630
short_name = "tf-test-policy-%{random_suffix}"
631-
description = "Description Update"
631+
description = "Resource created for Terraform acceptance testing"
632632
}
633633

634634
resource "google_network_security_address_group" "address_group" {

mmv1/third_party/terraform/website/docs/r/compute_firewall_policy.html.markdown

-107
This file was deleted.

tpgtools/overrides/compute/beta/firewall_policy.yaml

-4
This file was deleted.

0 commit comments

Comments
 (0)