Skip to content

Commit a9b1341

Browse files
Migrate GA version of compute firewall policy (#13184) (#21854)
[upstream:94029cc11a1a92a9b6b0ed58fb843f8aff897b11] Signed-off-by: Modular Magician <[email protected]>
1 parent 92b3186 commit a9b1341

8 files changed

+416
-171
lines changed

.changelog/13184.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google/provider/provider_dcl_resources.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/hashicorp/terraform-provider-google/google/services/assuredworkloads"
2525
"github.com/hashicorp/terraform-provider-google/google/services/cloudbuild"
2626
"github.com/hashicorp/terraform-provider-google/google/services/clouddeploy"
27-
"github.com/hashicorp/terraform-provider-google/google/services/compute"
2827
"github.com/hashicorp/terraform-provider-google/google/services/containeraws"
2928
"github.com/hashicorp/terraform-provider-google/google/services/containerazure"
3029
"github.com/hashicorp/terraform-provider-google/google/services/dataplex"
@@ -40,7 +39,6 @@ var dclResources = map[string]*schema.Resource{
4039
"google_cloudbuild_worker_pool": cloudbuild.ResourceCloudbuildWorkerPool(),
4140
"google_clouddeploy_delivery_pipeline": clouddeploy.ResourceClouddeployDeliveryPipeline(),
4241
"google_clouddeploy_target": clouddeploy.ResourceClouddeployTarget(),
43-
"google_compute_firewall_policy": compute.ResourceComputeFirewallPolicy(),
4442
"google_container_aws_cluster": containeraws.ResourceContainerAwsCluster(),
4543
"google_container_aws_node_pool": containeraws.ResourceContainerAwsNodePool(),
4644
"google_container_azure_client": containerazure.ResourceContainerAzureClient(),

google/provider/provider_mmv1_resources.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
488488
}
489489

490490
// Resources
491-
// Generated resources: 553
491+
// Generated resources: 554
492492
// Generated IAM resources: 276
493-
// Total generated resources: 829
493+
// Total generated resources: 830
494494
var generatedResources = map[string]*schema.Resource{
495495
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
496496
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -692,6 +692,7 @@ var generatedResources = map[string]*schema.Resource{
692692
"google_compute_disk_resource_policy_attachment": compute.ResourceComputeDiskResourcePolicyAttachment(),
693693
"google_compute_external_vpn_gateway": compute.ResourceComputeExternalVpnGateway(),
694694
"google_compute_firewall": compute.ResourceComputeFirewall(),
695+
"google_compute_firewall_policy": compute.ResourceComputeFirewallPolicy(),
695696
"google_compute_firewall_policy_association": compute.ResourceComputeFirewallPolicyAssociation(),
696697
"google_compute_firewall_policy_rule": compute.ResourceComputeFirewallPolicyRule(),
697698
"google_compute_forwarding_rule": compute.ResourceComputeForwardingRule(),

google/services/compute/resource_compute_firewall_policy.go

Lines changed: 286 additions & 139 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource: 'google_compute_firewall_policy'
2+
generation_type: 'mmv1'
3+
source_file: 'products/compute/FirewallPolicy.yaml'
4+
api_service_name: 'compute.googleapis.com'
5+
api_version: 'v1'
6+
api_resource_type_kind: 'FirewallPolicy'
7+
fields:
8+
- field: 'creation_timestamp'
9+
- field: 'description'
10+
- field: 'fingerprint'
11+
- field: 'firewall_policy_id'
12+
api_field: 'id'
13+
- field: 'name'
14+
- field: 'parent'
15+
- field: 'rule_tuple_count'
16+
- field: 'self_link'
17+
- field: 'self_link_with_id'
18+
- field: 'short_name'
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// ----------------------------------------------------------------------------
5+
//
6+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
7+
//
8+
// ----------------------------------------------------------------------------
9+
//
10+
// This file is automatically generated by Magic Modules and manual
11+
// changes will be clobbered when the file is regenerated.
12+
//
13+
// Please read more about how to change this file in
14+
// .github/CONTRIBUTING.md.
15+
//
16+
// ----------------------------------------------------------------------------
17+
18+
package compute_test
19+
20+
import (
21+
"fmt"
22+
"strings"
23+
"testing"
24+
25+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
26+
"github.com/hashicorp/terraform-plugin-testing/terraform"
27+
28+
"github.com/hashicorp/terraform-provider-google/google/acctest"
29+
"github.com/hashicorp/terraform-provider-google/google/envvar"
30+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
31+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
32+
)
33+
34+
func TestAccComputeFirewallPolicy_firewallPolicyExample(t *testing.T) {
35+
t.Parallel()
36+
37+
context := map[string]interface{}{
38+
"org_id": envvar.GetTestOrgFromEnv(t),
39+
"random_suffix": acctest.RandString(t, 10),
40+
}
41+
42+
acctest.VcrTest(t, resource.TestCase{
43+
PreCheck: func() { acctest.AccTestPreCheck(t) },
44+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
45+
CheckDestroy: testAccCheckComputeFirewallPolicyDestroyProducer(t),
46+
Steps: []resource.TestStep{
47+
{
48+
Config: testAccComputeFirewallPolicy_firewallPolicyExample(context),
49+
},
50+
{
51+
ResourceName: "google_compute_firewall_policy.default",
52+
ImportState: true,
53+
ImportStateVerify: true,
54+
},
55+
},
56+
})
57+
}
58+
59+
func testAccComputeFirewallPolicy_firewallPolicyExample(context map[string]interface{}) string {
60+
return acctest.Nprintf(`
61+
resource "google_compute_firewall_policy" "default" {
62+
parent = "organizations/%{org_id}"
63+
short_name = "tf-test-my-policy%{random_suffix}"
64+
description = "Example Resource"
65+
}
66+
`, context)
67+
}
68+
69+
func testAccCheckComputeFirewallPolicyDestroyProducer(t *testing.T) func(s *terraform.State) error {
70+
return func(s *terraform.State) error {
71+
for name, rs := range s.RootModule().Resources {
72+
if rs.Type != "google_compute_firewall_policy" {
73+
continue
74+
}
75+
if strings.HasPrefix(name, "data.") {
76+
continue
77+
}
78+
79+
config := acctest.GoogleProviderConfig(t)
80+
81+
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{ComputeBasePath}}locations/global/firewallPolicies/{{name}}")
82+
if err != nil {
83+
return err
84+
}
85+
86+
billingProject := ""
87+
88+
if config.BillingProject != "" {
89+
billingProject = config.BillingProject
90+
}
91+
92+
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
93+
Config: config,
94+
Method: "GET",
95+
Project: billingProject,
96+
RawURL: url,
97+
UserAgent: config.UserAgent,
98+
})
99+
if err == nil {
100+
return fmt.Errorf("ComputeFirewallPolicy still exists at %s", url)
101+
}
102+
}
103+
104+
return nil
105+
}
106+
}

google/transport/provider_dcl_client_creation.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
cloudbuild "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild"
3030
clouddeploy "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/clouddeploy"
3131
cloudresourcemanager "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudresourcemanager"
32-
compute "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/compute"
3332
containeraws "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/containeraws"
3433
containerazure "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/containerazure"
3534
dataplex "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/dataplex"
@@ -154,29 +153,6 @@ func NewDCLCloudResourceManagerClient(config *Config, userAgent, billingProject
154153
return cloudresourcemanager.NewClient(dclConfig)
155154
}
156155

157-
func NewDCLComputeClient(config *Config, userAgent, billingProject string, timeout time.Duration) *compute.Client {
158-
configOptions := []dcl.ConfigOption{
159-
dcl.WithHTTPClient(config.Client),
160-
dcl.WithUserAgent(userAgent),
161-
dcl.WithLogger(dclLogger{}),
162-
dcl.WithBasePath(config.ComputeBasePath),
163-
}
164-
165-
if timeout != 0 {
166-
configOptions = append(configOptions, dcl.WithTimeout(timeout))
167-
}
168-
169-
if config.UserProjectOverride {
170-
configOptions = append(configOptions, dcl.WithUserProjectOverride())
171-
if billingProject != "" {
172-
configOptions = append(configOptions, dcl.WithBillingProject(billingProject))
173-
}
174-
}
175-
176-
dclConfig := dcl.NewConfig(configOptions...)
177-
return compute.NewClient(dclConfig)
178-
}
179-
180156
func NewDCLContainerAwsClient(config *Config, userAgent, billingProject string, timeout time.Duration) *containeraws.Client {
181157
configOptions := []dcl.ConfigOption{
182158
dcl.WithHTTPClient(config.Client),

website/docs/r/compute_firewall_policy.html.markdown

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ This resource should be generally be used with `google_compute_firewall_policy_a
2727

2828
For more information see the [official documentation](https://cloud.google.com/vpc/docs/firewall-policies)
2929

30-
~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
31-
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.
3230

3331
To get more information about FirewallPolicy, see:
3432

@@ -39,8 +37,6 @@ To get more information about FirewallPolicy, see:
3937

4038
```hcl
4139
resource "google_compute_firewall_policy" "default" {
42-
provider = google-beta
43-
4440
parent = "organizations/123456789"
4541
short_name = "my-policy"
4642
description = "Example Resource"

0 commit comments

Comments
 (0)