Skip to content

Commit c11a600

Browse files
Migrate google_compute_firewall_policy_association resource from DCL to MMv1 (#11358) (#20214)
[upstream:3850a583f7d4839598b5bd5e73bbb3163df398c8] Signed-off-by: Modular Magician <[email protected]>
1 parent 727d3fa commit c11a600

File tree

3 files changed

+89
-25
lines changed

3 files changed

+89
-25
lines changed

.changelog/11358.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: `google_compute_firewall_policy_association` now uses MMv1 engine instead of DCL.
3+
```

google/services/compute/resource_compute_firewall_policy_association_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,53 @@ resource "google_compute_firewall_policy_association" "default" {
6464
}
6565
`, context)
6666
}
67+
68+
func TestAccComputeFirewallPolicyAssociation_organization(t *testing.T) {
69+
t.Parallel()
70+
71+
context := map[string]interface{}{
72+
"random_suffix": acctest.RandString(t, 10),
73+
"org_name": fmt.Sprintf("organizations/%s", envvar.GetTestOrgFromEnv(t)),
74+
}
75+
76+
acctest.VcrTest(t, resource.TestCase{
77+
PreCheck: func() { acctest.AccTestPreCheck(t) },
78+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
79+
ExternalProviders: map[string]resource.ExternalProvider{
80+
"time": {},
81+
},
82+
Steps: []resource.TestStep{
83+
{
84+
Config: testAccComputeFirewallPolicyAssociation_organization(context),
85+
},
86+
{
87+
ResourceName: "google_compute_firewall_policy_association.default",
88+
ImportState: true,
89+
ImportStateVerify: true,
90+
ImportStateVerifyIgnore: []string{"firewall_policy"},
91+
},
92+
},
93+
})
94+
}
95+
96+
func testAccComputeFirewallPolicyAssociation_organization(context map[string]interface{}) string {
97+
return acctest.Nprintf(`
98+
resource "google_folder" "folder" {
99+
display_name = "tf-test-my-folder-%{random_suffix}"
100+
parent = "%{org_name}"
101+
deletion_protection = false
102+
}
103+
104+
resource "google_compute_firewall_policy" "policy" {
105+
parent = "%{org_name}"
106+
short_name = "tf-test-my-policy-%{random_suffix}"
107+
description = "Example Resource"
108+
}
109+
110+
resource "google_compute_firewall_policy_association" "default" {
111+
firewall_policy = google_compute_firewall_policy.policy.id
112+
attachment_target = google_folder.folder.name
113+
name = "tf-test-my-association-%{random_suffix}"
114+
}
115+
`, context)
116+
}

website/docs/r/compute_firewall_policy_association.html.markdown

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,73 @@
11
---
22
# ----------------------------------------------------------------------------
33
#
4-
# *** AUTO GENERATED CODE *** Type: DCL ***
4+
# *** AUTO GENERATED CODE *** Type: MMv1 ***
55
#
66
# ----------------------------------------------------------------------------
77
#
8-
# This file is managed by Magic Modules (https:#github.com/GoogleCloudPlatform/magic-modules)
9-
# and is based on the DCL (https:#github.com/GoogleCloudPlatform/declarative-resource-client-library).
10-
# Changes will need to be made to the DCL or Magic Modules instead of here.
8+
# This file is automatically generated by Magic Modules and manual
9+
# changes will be clobbered when the file is regenerated.
1110
#
12-
# We are not currently able to accept contributions to this file. If changes
13-
# are required, please file an issue at https:#github.com/hashicorp/terraform-provider-google/issues/new/choose
11+
# Please read more about how to change this file in
12+
# .github/CONTRIBUTING.md.
1413
#
1514
# ----------------------------------------------------------------------------
1615
subcategory: "Compute Engine"
1716
description: |-
18-
Applies a hierarchical firewall policy to a target resource
17+
Allows associating hierarchical firewall policies with the target where they are applied.
1918
---
2019

2120
# google_compute_firewall_policy_association
2221

2322
Allows associating hierarchical firewall policies with the target where they are applied. This allows creating policies and rules in a different location than they are applied.
23+
For more information on applying hierarchical firewall policies see the [official documentation](https://cloud.google.com/firewall/docs/firewall-policies#managing_hierarchical_firewall_policy_resources)
2424

25-
For more information on applying hierarchical firewall policies see the [official documentation](https://cloud.google.com/vpc/docs/firewall-policies#managing_hierarchical_firewall_policy_resources)
25+
~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
26+
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.
27+
28+
To get more information about FirewallPolicyAssociation, see:
29+
30+
* [API documentation](https://cloud.google.com/compute/docs/reference/rest/v1/firewallPolicies/addAssociation)
31+
32+
## Example Usage - Firewall Policy Association
2633

27-
## Example Usage
2834

2935
```hcl
30-
resource "google_compute_firewall_policy" "default" {
31-
parent = "organizations/12345"
36+
resource "google_folder" "folder" {
37+
display_name = "my-folder"
38+
parent = "organizations/123456789"
39+
deletion_protection = false
40+
}
41+
42+
resource "google_compute_firewall_policy" "policy" {
43+
parent = "organizations/123456789"
3244
short_name = "my-policy"
3345
description = "Example Resource"
3446
}
3547
3648
resource "google_compute_firewall_policy_association" "default" {
37-
firewall_policy = google_compute_firewall_policy.default.id
49+
firewall_policy = google_compute_firewall_policy.policy.id
3850
attachment_target = google_folder.folder.name
3951
name = "my-association"
4052
}
4153
```
4254

43-
4455
## Argument Reference
4556

4657
The following arguments are supported:
4758

59+
60+
* `name` -
61+
(Required)
62+
The name for an association.
63+
4864
* `attachment_target` -
4965
(Required)
5066
The target that the firewall policy is attached to.
51-
67+
5268
* `firewall_policy` -
5369
(Required)
54-
The firewall policy ID of the association.
55-
56-
* `name` -
57-
(Required)
58-
The name for an association.
59-
70+
The firewall policy of the resource.
6071

6172

6273
- - -
@@ -71,22 +82,25 @@ In addition to the arguments listed above, the following computed attributes are
7182

7283
* `short_name` -
7384
The short name of the firewall policy of the association.
74-
85+
86+
7587
## Timeouts
7688

7789
This resource provides the following
78-
[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: configuration options:
90+
[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options:
7991

8092
- `create` - Default is 20 minutes.
8193
- `delete` - Default is 20 minutes.
8294

8395
## Import
8496

97+
8598
FirewallPolicyAssociation can be imported using any of these accepted formats:
8699

87100
* `locations/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}`
88101
* `{{firewall_policy}}/{{name}}`
89102

103+
90104
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import FirewallPolicyAssociation using one of the formats above. For example:
91105

92106
```tf
@@ -102,6 +116,3 @@ When using the [`terraform import` command](https://developer.hashicorp.com/terr
102116
$ terraform import google_compute_firewall_policy_association.default locations/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}
103117
$ terraform import google_compute_firewall_policy_association.default {{firewall_policy}}/{{name}}
104118
```
105-
106-
107-

0 commit comments

Comments
 (0)