From 96cba26a689ab2b89fe206abfa1627de0c5d1a26 Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Mon, 30 Sep 2024 14:50:39 -0700 Subject: [PATCH 1/7] Convert from Ruby to Go --- .../compute/FirewallPolicyAssociation.yaml | 92 +++++++++++++++ ...ewall_policy_association_operation.go.tmpl | 10 ++ ...firewall_policy_association_import.go.tmpl | 37 ++++++ .../firewall_policy_association.tf.tmpl | 16 +++ ...ompute_firewall_policy_association_test.go | 58 ++++++++++ ..._firewall_policy_association.html.markdown | 107 ------------------ .../beta/firewall_policy_association.yaml | 4 - .../compute/firewall_policy_association.yaml | 4 - 8 files changed, 213 insertions(+), 115 deletions(-) create mode 100644 mmv1/products/compute/FirewallPolicyAssociation.yaml create mode 100644 mmv1/templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl create mode 100644 mmv1/templates/terraform/constants/firewall_policy_association_import.go.tmpl create mode 100644 mmv1/templates/terraform/examples/firewall_policy_association.tf.tmpl delete mode 100644 mmv1/third_party/terraform/website/docs/r/compute_firewall_policy_association.html.markdown delete mode 100644 tpgtools/overrides/compute/beta/firewall_policy_association.yaml delete mode 100644 tpgtools/overrides/compute/firewall_policy_association.yaml diff --git a/mmv1/products/compute/FirewallPolicyAssociation.yaml b/mmv1/products/compute/FirewallPolicyAssociation.yaml new file mode 100644 index 000000000000..06e011bbee7b --- /dev/null +++ b/mmv1/products/compute/FirewallPolicyAssociation.yaml @@ -0,0 +1,92 @@ +# Copyright 2024 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +name: 'FirewallPolicyAssociation' +kind: 'compute#firewallPolicyAssociation' +description: | + 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. + 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) +min_version: 'beta' +references: + guides: + api: 'https://cloud.google.com/compute/docs/reference/rest/v1/firewallPolicies/addAssociation' +docs: +id_format: '{{firewall_policy}}/associations/{{name}}' +base_url: '{{firewall_policy}}' +self_link: '{{firewall_policy}}/getAssociation?name={{name}}' +create_url: '{{firewall_policy}}/addAssociation' +delete_url: '{{firewall_policy}}/removeAssociation?name={{name}}' +delete_verb: 'POST' +immutable: true +import_format: + - 'locations/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}' + - '{{firewall_policy}}/{{name}}' +timeouts: + insert_minutes: 20 + update_minutes: 20 + delete_minutes: 20 +custom_code: + post_create: 'templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl' + post_delete: 'templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl' + custom_import: 'templates/terraform/constants/firewall_policy_association_import.go.tmpl' + test_check_destroy: 'templates/terraform/custom_check_destroy/skip_delete_during_test.go.tmpl' +custom_diff: + - 'tpgresource.DefaultProviderProject' +examples: + - name: 'firewall_policy_association' + primary_resource_id: 'default' + vars: + policy_name: 'my-policy' + association_name: 'my-association' + folder_name: 'my-folder' + test_env_vars: + org_id: 'ORG_ID' + exclude_test: true +parameters: + - name: 'firewallPolicy' + type: ResourceRef + description: | + The firewall policy ID of the association. + min_version: 'beta' + url_param_only: true + required: true + immutable: true + diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName' + custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.tmpl' + custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' + resource: 'FirewallPolicy' + imports: 'name' +properties: + - name: 'name' + type: String + description: | + The name for an association. + min_version: 'beta' + required: true + immutable: true + - name: 'attachmentTarget' + type: String + description: | + The target that the firewall policy is attached to. + min_version: 'beta' + required: true + immutable: true + diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName' + - name: 'shortName' + type: String + description: | + The short name of the firewall policy of the association. + min_version: 'beta' + immutable: true + output: true diff --git a/mmv1/templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl b/mmv1/templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl new file mode 100644 index 000000000000..88b5cf179465 --- /dev/null +++ b/mmv1/templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl @@ -0,0 +1,10 @@ +var opRes map[string]interface{} +err = ComputeOrgOperationWaitTimeWithResponse( + config, res, &opRes, d.Get("firewall_policy").(string), "FirewallPolicyAssociation operation", userAgent, + d.Timeout(schema.TimeoutCreate)) + +if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting for FirewallPolicyAssociation operation: %s", err) +} \ No newline at end of file diff --git a/mmv1/templates/terraform/constants/firewall_policy_association_import.go.tmpl b/mmv1/templates/terraform/constants/firewall_policy_association_import.go.tmpl new file mode 100644 index 000000000000..99e7f17bfda5 --- /dev/null +++ b/mmv1/templates/terraform/constants/firewall_policy_association_import.go.tmpl @@ -0,0 +1,37 @@ +{{/* + The license inside this block applies to this file + Copyright 2024 Google Inc. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ -}} + config := meta.(*transport_tpg.Config) + if err := tpgresource.ParseImportId([]string{ + "^locations/global/firewallPolicies/(?P[^/]+)/associations/(?P[^/]+)$", + "^(?P[^/]+)/(?P[^/]+)$", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := tpgresource.ReplaceVars(d, config, "locations/global/firewallPolicies/{{"{{"}}firewall_policy{{"}}"}}/associations/{{"{{"}}name{{"}}"}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + // Current import uses only the Firewall Policy Id + // Replace the field to format "locations/global/firewallPolicies/{{"{{"}}firewallPolicyId{{"}}"}}" + stringParts := strings.Split(d.Get("firewall_policy").(string), "/") + if len(stringParts) == 1 { + if err := d.Set("firewall_policy", fmt.Sprintf("locations/global/firewallPolicies/%s", d.Get("firewall_policy").(string))); err != nil { + return nil, fmt.Errorf("Error setting firewall_policy, %s", err) + } + } + + return []*schema.ResourceData{d}, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/firewall_policy_association.tf.tmpl b/mmv1/templates/terraform/examples/firewall_policy_association.tf.tmpl new file mode 100644 index 000000000000..38a00cbf74c0 --- /dev/null +++ b/mmv1/templates/terraform/examples/firewall_policy_association.tf.tmpl @@ -0,0 +1,16 @@ +resource "google_folder" "folder" { + display_name = "{{index $.Vars "folder_name"}}" + parent = "organizations/{{index $.TestEnvVars "org_id"}}" +} + +resource "google_compute_firewall_policy" "policy" { + parent = "organizations/{{index $.TestEnvVars "org_id"}}" + short_name = "{{index $.Vars "policy_name"}}" + description = "Example Resource" +} + +resource "google_compute_firewall_policy_association" "{{$.PrimaryResourceId}}" { + firewall_policy = google_compute_firewall_policy.policy.id + attachment_target = google_folder.folder.name + name = "{{index $.Vars "association_name"}}" +} \ No newline at end of file diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_firewall_policy_association_test.go b/mmv1/third_party/terraform/services/compute/resource_compute_firewall_policy_association_test.go index 12e8f78881a7..c1a801496a0a 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_firewall_policy_association_test.go +++ b/mmv1/third_party/terraform/services/compute/resource_compute_firewall_policy_association_test.go @@ -62,3 +62,61 @@ resource "google_compute_firewall_policy_association" "default" { } `, context) } + +func TestAccComputeFirewallPolicyAssociation_organization(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + "org_name": fmt.Sprintf("organizations/%s", envvar.GetTestOrgFromEnv(t)), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + ExternalProviders: map[string]resource.ExternalProvider{ + "time": {}, + }, + Steps: []resource.TestStep{ + { + Config: testAccComputeFirewallPolicyAssociation_organization(context), + }, + { + ResourceName: "google_compute_firewall_policy_association.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"firewall_policy"}, + }, + }, + }) +} + +func testAccComputeFirewallPolicyAssociation_organization(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "time_sleep" "wait_180s" { + destroy_duration = "180s" +} + +resource "google_folder" "folder" { + display_name = "tf-test-my-folder-%{random_suffix}" + parent = "%{org_name}" +} + +resource "google_compute_firewall_policy" "policy" { + parent = "%{org_name}" + short_name = "tf-test-my-policy-%{random_suffix}" + description = "Example Resource" +} + +resource "google_compute_firewall_policy_association" "default" { + firewall_policy = google_compute_firewall_policy.policy.id + attachment_target = google_folder.folder.name + name = "tf-test-my-association-%{random_suffix}" + depends_on = [ + time_sleep.wait_180s, + google_folder.folder, + google_compute_firewall_policy.policy + ] +} +`, context) +} diff --git a/mmv1/third_party/terraform/website/docs/r/compute_firewall_policy_association.html.markdown b/mmv1/third_party/terraform/website/docs/r/compute_firewall_policy_association.html.markdown deleted file mode 100644 index cfe4cc3fdcd9..000000000000 --- a/mmv1/third_party/terraform/website/docs/r/compute_firewall_policy_association.html.markdown +++ /dev/null @@ -1,107 +0,0 @@ ---- -# ---------------------------------------------------------------------------- -# -# *** AUTO GENERATED CODE *** Type: DCL *** -# -# ---------------------------------------------------------------------------- -# -# This file is managed by Magic Modules (https:#github.com/GoogleCloudPlatform/magic-modules) -# and is based on the DCL (https:#github.com/GoogleCloudPlatform/declarative-resource-client-library). -# Changes will need to be made to the DCL or Magic Modules instead of here. -# -# We are not currently able to accept contributions to this file. If changes -# are required, please file an issue at https:#github.com/hashicorp/terraform-provider-google/issues/new/choose -# -# ---------------------------------------------------------------------------- -subcategory: "Compute Engine" -description: |- - Applies a hierarchical firewall policy to a target resource ---- - -# google_compute_firewall_policy_association - -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. - -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) - -## Example Usage - -```hcl -resource "google_compute_firewall_policy" "default" { - parent = "organizations/12345" - short_name = "my-policy" - description = "Example Resource" -} - -resource "google_compute_firewall_policy_association" "default" { - firewall_policy = google_compute_firewall_policy.default.id - attachment_target = google_folder.folder.name - name = "my-association" -} -``` - - -## Argument Reference - -The following arguments are supported: - -* `attachment_target` - - (Required) - The target that the firewall policy is attached to. - -* `firewall_policy` - - (Required) - The firewall policy ID of the association. - -* `name` - - (Required) - The name for an association. - - - -- - - - - - -## Attributes Reference - -In addition to the arguments listed above, the following computed attributes are exported: - -* `id` - an identifier for the resource with format `locations/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}` - -* `short_name` - - The short name of the firewall policy of the association. - -## Timeouts - -This resource provides the following -[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: configuration options: - -- `create` - Default is 20 minutes. -- `delete` - Default is 20 minutes. - -## Import - -FirewallPolicyAssociation can be imported using any of these accepted formats: - -* `locations/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}` -* `{{firewall_policy}}/{{name}}` - -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: - -```tf -import { - id = "locations/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}" - to = google_compute_firewall_policy_association.default -} -``` - -When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), FirewallPolicyAssociation can be imported using one of the formats above. For example: - -``` -$ terraform import google_compute_firewall_policy_association.default locations/global/firewallPolicies/{{firewall_policy}}/associations/{{name}} -$ terraform import google_compute_firewall_policy_association.default {{firewall_policy}}/{{name}} -``` - - - diff --git a/tpgtools/overrides/compute/beta/firewall_policy_association.yaml b/tpgtools/overrides/compute/beta/firewall_policy_association.yaml deleted file mode 100644 index af851d79a0c9..000000000000 --- a/tpgtools/overrides/compute/beta/firewall_policy_association.yaml +++ /dev/null @@ -1,4 +0,0 @@ -- type: CUSTOMIZE_DIFF - details: - functions: - - tpgresource.DefaultProviderProject diff --git a/tpgtools/overrides/compute/firewall_policy_association.yaml b/tpgtools/overrides/compute/firewall_policy_association.yaml deleted file mode 100644 index af851d79a0c9..000000000000 --- a/tpgtools/overrides/compute/firewall_policy_association.yaml +++ /dev/null @@ -1,4 +0,0 @@ -- type: CUSTOMIZE_DIFF - details: - functions: - - tpgresource.DefaultProviderProject From 5691de10aaaa1b8d92ae4eef2e947734dbc49245 Mon Sep 17 00:00:00 2001 From: samir-cit Date: Wed, 30 Oct 2024 13:31:18 -0300 Subject: [PATCH 2/7] Suggestions --- .../compute/FirewallPolicyAssociation.yaml | 35 +++++++------------ ...ewall_policy_association_operation.go.tmpl | 10 ------ ...ompute_firewall_policy_association.go.tmpl | 7 ++++ .../firewall_policy_association.tf.tmpl | 1 + ...ewall_policy_association_operation.go.tmpl | 11 ++++++ ...ewall_policy_association_operation.go.tmpl | 11 ++++++ ...ompute_firewall_policy_association_test.go | 10 +----- 7 files changed, 44 insertions(+), 41 deletions(-) delete mode 100644 mmv1/templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl create mode 100644 mmv1/templates/terraform/custom_expand/compute_firewall_policy_association.go.tmpl create mode 100644 mmv1/templates/terraform/post_create/compute_firewall_policy_association_operation.go.tmpl create mode 100644 mmv1/templates/terraform/post_delete/compute_firewall_policy_association_operation.go.tmpl diff --git a/mmv1/products/compute/FirewallPolicyAssociation.yaml b/mmv1/products/compute/FirewallPolicyAssociation.yaml index 06e011bbee7b..a6e385c74b53 100644 --- a/mmv1/products/compute/FirewallPolicyAssociation.yaml +++ b/mmv1/products/compute/FirewallPolicyAssociation.yaml @@ -17,16 +17,15 @@ kind: 'compute#firewallPolicyAssociation' description: | 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. 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) -min_version: 'beta' references: guides: api: 'https://cloud.google.com/compute/docs/reference/rest/v1/firewallPolicies/addAssociation' docs: -id_format: '{{firewall_policy}}/associations/{{name}}' -base_url: '{{firewall_policy}}' -self_link: '{{firewall_policy}}/getAssociation?name={{name}}' -create_url: '{{firewall_policy}}/addAssociation' -delete_url: '{{firewall_policy}}/removeAssociation?name={{name}}' +id_format: 'locations/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}' +base_url: 'locations/global/firewallPolicies/{{firewall_policy}}' +self_link: 'locations/global/firewallPolicies/{{firewall_policy}}/getAssociation?name={{name}}' +create_url: 'locations/global/firewallPolicies/{{firewall_policy}}/addAssociation' +delete_url: 'locations/global/firewallPolicies/{{firewall_policy}}/removeAssociation?name={{name}}' delete_verb: 'POST' immutable: true import_format: @@ -37,10 +36,10 @@ timeouts: update_minutes: 20 delete_minutes: 20 custom_code: - post_create: 'templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl' - post_delete: 'templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl' - custom_import: 'templates/terraform/constants/firewall_policy_association_import.go.tmpl' - test_check_destroy: 'templates/terraform/custom_check_destroy/skip_delete_during_test.go.tmpl' + post_create: 'templates/terraform/post_create/compute_firewall_policy_association_operation.go.tmpl' + post_delete: 'templates/terraform/post_delete/compute_firewall_policy_association_operation.go.tmpl' + # custom_import: 'templates/terraform/constants/firewall_policy_association_import.go.tmpl' + # test_check_destroy: 'templates/terraform/custom_check_destroy/skip_delete_during_test.go.tmpl' custom_diff: - 'tpgresource.DefaultProviderProject' examples: @@ -57,14 +56,12 @@ parameters: - name: 'firewallPolicy' type: ResourceRef description: | - The firewall policy ID of the association. - min_version: 'beta' - url_param_only: true + The firewall policy of the resource. + ignore_read: true required: true immutable: true - diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName' - custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.tmpl' - custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' + diff_suppress_func: 'tpgresource.CompareResourceNames' + custom_expand: 'templates/terraform/custom_expand/compute_firewall_policy_association.go.tmpl' resource: 'FirewallPolicy' imports: 'name' properties: @@ -72,21 +69,15 @@ properties: type: String description: | The name for an association. - min_version: 'beta' required: true - immutable: true - name: 'attachmentTarget' type: String description: | The target that the firewall policy is attached to. - min_version: 'beta' required: true - immutable: true diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName' - name: 'shortName' type: String description: | The short name of the firewall policy of the association. - min_version: 'beta' - immutable: true output: true diff --git a/mmv1/templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl b/mmv1/templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl deleted file mode 100644 index 88b5cf179465..000000000000 --- a/mmv1/templates/terraform/constants/compute_firewall_policy_association_operation.go.tmpl +++ /dev/null @@ -1,10 +0,0 @@ -var opRes map[string]interface{} -err = ComputeOrgOperationWaitTimeWithResponse( - config, res, &opRes, d.Get("firewall_policy").(string), "FirewallPolicyAssociation operation", userAgent, - d.Timeout(schema.TimeoutCreate)) - -if err != nil { - // The resource didn't actually create - d.SetId("") - return fmt.Errorf("Error waiting for FirewallPolicyAssociation operation: %s", err) -} \ No newline at end of file diff --git a/mmv1/templates/terraform/custom_expand/compute_firewall_policy_association.go.tmpl b/mmv1/templates/terraform/custom_expand/compute_firewall_policy_association.go.tmpl new file mode 100644 index 000000000000..7b3a6e343f90 --- /dev/null +++ b/mmv1/templates/terraform/custom_expand/compute_firewall_policy_association.go.tmpl @@ -0,0 +1,7 @@ +func expand{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + firewallPolicyId := tpgresource.GetResourceNameFromSelfLink(v.(string)) + if err := d.Set("firewall_policy", firewallPolicyId); err != nil { + return nil, fmt.Errorf("Error setting firewall_policy: %s", err) + } + return firewallPolicyId, nil +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/firewall_policy_association.tf.tmpl b/mmv1/templates/terraform/examples/firewall_policy_association.tf.tmpl index 38a00cbf74c0..5ae7625e741c 100644 --- a/mmv1/templates/terraform/examples/firewall_policy_association.tf.tmpl +++ b/mmv1/templates/terraform/examples/firewall_policy_association.tf.tmpl @@ -1,6 +1,7 @@ resource "google_folder" "folder" { display_name = "{{index $.Vars "folder_name"}}" parent = "organizations/{{index $.TestEnvVars "org_id"}}" + deletion_protection = false } resource "google_compute_firewall_policy" "policy" { diff --git a/mmv1/templates/terraform/post_create/compute_firewall_policy_association_operation.go.tmpl b/mmv1/templates/terraform/post_create/compute_firewall_policy_association_operation.go.tmpl new file mode 100644 index 000000000000..0953b637e026 --- /dev/null +++ b/mmv1/templates/terraform/post_create/compute_firewall_policy_association_operation.go.tmpl @@ -0,0 +1,11 @@ +parent := d.Get("firewall_policy").(string) +var opRes map[string]interface{} +err = ComputeOrgOperationWaitTimeWithResponse( + config, res, &opRes, parent, "Creating FirewallPolicyAssociation", userAgent, + d.Timeout(schema.TimeoutCreate)) + +if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create FirewallPolicyAssociation: %s", err) +} \ No newline at end of file diff --git a/mmv1/templates/terraform/post_delete/compute_firewall_policy_association_operation.go.tmpl b/mmv1/templates/terraform/post_delete/compute_firewall_policy_association_operation.go.tmpl new file mode 100644 index 000000000000..45ef4fbfe655 --- /dev/null +++ b/mmv1/templates/terraform/post_delete/compute_firewall_policy_association_operation.go.tmpl @@ -0,0 +1,11 @@ +parent := d.Get("firewall_policy").(string) +var opRes map[string]interface{} +err = ComputeOrgOperationWaitTimeWithResponse( + config, res, &opRes, parent, "Deleting FirewallPolicyAssociation", userAgent, + d.Timeout(schema.TimeoutCreate)) + +if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to delete FirewallPolicyAssociation: %s", err) +} \ No newline at end of file diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_firewall_policy_association_test.go b/mmv1/third_party/terraform/services/compute/resource_compute_firewall_policy_association_test.go index c1a801496a0a..5845c149221f 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_firewall_policy_association_test.go +++ b/mmv1/third_party/terraform/services/compute/resource_compute_firewall_policy_association_test.go @@ -93,13 +93,10 @@ func TestAccComputeFirewallPolicyAssociation_organization(t *testing.T) { func testAccComputeFirewallPolicyAssociation_organization(context map[string]interface{}) string { return acctest.Nprintf(` -resource "time_sleep" "wait_180s" { - destroy_duration = "180s" -} - resource "google_folder" "folder" { display_name = "tf-test-my-folder-%{random_suffix}" parent = "%{org_name}" + deletion_protection = false } resource "google_compute_firewall_policy" "policy" { @@ -112,11 +109,6 @@ resource "google_compute_firewall_policy_association" "default" { firewall_policy = google_compute_firewall_policy.policy.id attachment_target = google_folder.folder.name name = "tf-test-my-association-%{random_suffix}" - depends_on = [ - time_sleep.wait_180s, - google_folder.folder, - google_compute_firewall_policy.policy - ] } `, context) } From 81deba86f36e21998b898658320a8e875bb1ed94 Mon Sep 17 00:00:00 2001 From: samir-cit Date: Wed, 30 Oct 2024 13:32:21 -0300 Subject: [PATCH 3/7] Unused code --- .../compute/FirewallPolicyAssociation.yaml | 2 - ...firewall_policy_association_import.go.tmpl | 37 ------------------- 2 files changed, 39 deletions(-) delete mode 100644 mmv1/templates/terraform/constants/firewall_policy_association_import.go.tmpl diff --git a/mmv1/products/compute/FirewallPolicyAssociation.yaml b/mmv1/products/compute/FirewallPolicyAssociation.yaml index a6e385c74b53..7c3e6ddc6bde 100644 --- a/mmv1/products/compute/FirewallPolicyAssociation.yaml +++ b/mmv1/products/compute/FirewallPolicyAssociation.yaml @@ -38,8 +38,6 @@ timeouts: custom_code: post_create: 'templates/terraform/post_create/compute_firewall_policy_association_operation.go.tmpl' post_delete: 'templates/terraform/post_delete/compute_firewall_policy_association_operation.go.tmpl' - # custom_import: 'templates/terraform/constants/firewall_policy_association_import.go.tmpl' - # test_check_destroy: 'templates/terraform/custom_check_destroy/skip_delete_during_test.go.tmpl' custom_diff: - 'tpgresource.DefaultProviderProject' examples: diff --git a/mmv1/templates/terraform/constants/firewall_policy_association_import.go.tmpl b/mmv1/templates/terraform/constants/firewall_policy_association_import.go.tmpl deleted file mode 100644 index 99e7f17bfda5..000000000000 --- a/mmv1/templates/terraform/constants/firewall_policy_association_import.go.tmpl +++ /dev/null @@ -1,37 +0,0 @@ -{{/* - The license inside this block applies to this file - Copyright 2024 Google Inc. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -}} - config := meta.(*transport_tpg.Config) - if err := tpgresource.ParseImportId([]string{ - "^locations/global/firewallPolicies/(?P[^/]+)/associations/(?P[^/]+)$", - "^(?P[^/]+)/(?P[^/]+)$", - }, d, config); err != nil { - return nil, err - } - - // Replace import id for the resource id - id, err := tpgresource.ReplaceVars(d, config, "locations/global/firewallPolicies/{{"{{"}}firewall_policy{{"}}"}}/associations/{{"{{"}}name{{"}}"}}") - if err != nil { - return nil, fmt.Errorf("Error constructing id: %s", err) - } - d.SetId(id) - - // Current import uses only the Firewall Policy Id - // Replace the field to format "locations/global/firewallPolicies/{{"{{"}}firewallPolicyId{{"}}"}}" - stringParts := strings.Split(d.Get("firewall_policy").(string), "/") - if len(stringParts) == 1 { - if err := d.Set("firewall_policy", fmt.Sprintf("locations/global/firewallPolicies/%s", d.Get("firewall_policy").(string))); err != nil { - return nil, fmt.Errorf("Error setting firewall_policy, %s", err) - } - } - - return []*schema.ResourceData{d}, nil \ No newline at end of file From 5795ffdc7b4ce61e3a9c39ee00621c53a9fbf43a Mon Sep 17 00:00:00 2001 From: samir-cit Date: Wed, 30 Oct 2024 14:15:50 -0300 Subject: [PATCH 4/7] Resource is still in beta --- mmv1/products/compute/FirewallPolicyAssociation.yaml | 1 + tpgtools/overrides/compute/firewall_policy_association.yaml | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 tpgtools/overrides/compute/firewall_policy_association.yaml diff --git a/mmv1/products/compute/FirewallPolicyAssociation.yaml b/mmv1/products/compute/FirewallPolicyAssociation.yaml index 7c3e6ddc6bde..0114bfc578ba 100644 --- a/mmv1/products/compute/FirewallPolicyAssociation.yaml +++ b/mmv1/products/compute/FirewallPolicyAssociation.yaml @@ -17,6 +17,7 @@ kind: 'compute#firewallPolicyAssociation' description: | 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. 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) +min_version: 'beta' references: guides: api: 'https://cloud.google.com/compute/docs/reference/rest/v1/firewallPolicies/addAssociation' diff --git a/tpgtools/overrides/compute/firewall_policy_association.yaml b/tpgtools/overrides/compute/firewall_policy_association.yaml new file mode 100644 index 000000000000..ba8d27aa31cc --- /dev/null +++ b/tpgtools/overrides/compute/firewall_policy_association.yaml @@ -0,0 +1,4 @@ +- type: CUSTOMIZE_DIFF + details: + functions: + - tpgresource.DefaultProviderProject \ No newline at end of file From b776b6133a9cb1b1b00becf70c5f00afac58b95b Mon Sep 17 00:00:00 2001 From: samir-cit Date: Thu, 28 Nov 2024 14:04:26 -0300 Subject: [PATCH 5/7] Added a pre read script to make the resource available to change from DCL to MMv1 --- mmv1/products/compute/FirewallPolicyAssociation.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/mmv1/products/compute/FirewallPolicyAssociation.yaml b/mmv1/products/compute/FirewallPolicyAssociation.yaml index 0114bfc578ba..b5206cfb6a52 100644 --- a/mmv1/products/compute/FirewallPolicyAssociation.yaml +++ b/mmv1/products/compute/FirewallPolicyAssociation.yaml @@ -37,6 +37,7 @@ timeouts: update_minutes: 20 delete_minutes: 20 custom_code: + pre_read: 'templates/terraform/pre_read/compute_firewall_policy_association.go.tmpl' post_create: 'templates/terraform/post_create/compute_firewall_policy_association_operation.go.tmpl' post_delete: 'templates/terraform/post_delete/compute_firewall_policy_association_operation.go.tmpl' custom_diff: From 289aeaa28074c1216c8f9ee2feabdf74de8fc0c6 Mon Sep 17 00:00:00 2001 From: samir-cit Date: Thu, 28 Nov 2024 14:04:36 -0300 Subject: [PATCH 6/7] Added a pre read script to make the resource available to change from DCL to MMv1 --- .../pre_read/compute_firewall_policy_association.go.tmpl | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 mmv1/templates/terraform/pre_read/compute_firewall_policy_association.go.tmpl diff --git a/mmv1/templates/terraform/pre_read/compute_firewall_policy_association.go.tmpl b/mmv1/templates/terraform/pre_read/compute_firewall_policy_association.go.tmpl new file mode 100644 index 000000000000..a3ae32690dc1 --- /dev/null +++ b/mmv1/templates/terraform/pre_read/compute_firewall_policy_association.go.tmpl @@ -0,0 +1,5 @@ +expandComputeFirewallPolicyAssociationFirewallPolicy(d.Get("firewall_policy"), d, config) +url, err = tpgresource.ReplaceVars(d, config, "{{"{{"}}ComputeBasePath{{"}}"}}locations/global/firewallPolicies/{{"{{"}}firewall_policy{{"}}"}}/getAssociation?name={{"{{"}}name{{"}}"}}") +if err != nil { + return err +} \ No newline at end of file From dadb93902d94c5e6345817f2b8a39e5a659522a7 Mon Sep 17 00:00:00 2001 From: samir-cit Date: Tue, 3 Dec 2024 13:47:31 -0300 Subject: [PATCH 7/7] Bump resource to GA --- mmv1/products/compute/FirewallPolicyAssociation.yaml | 2 +- tpgtools/overrides/compute/firewall_policy_association.yaml | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 tpgtools/overrides/compute/firewall_policy_association.yaml diff --git a/mmv1/products/compute/FirewallPolicyAssociation.yaml b/mmv1/products/compute/FirewallPolicyAssociation.yaml index b5206cfb6a52..eef602a814bf 100644 --- a/mmv1/products/compute/FirewallPolicyAssociation.yaml +++ b/mmv1/products/compute/FirewallPolicyAssociation.yaml @@ -13,11 +13,11 @@ --- name: 'FirewallPolicyAssociation' +api_resource_type_kind: FirewallPolicy kind: 'compute#firewallPolicyAssociation' description: | 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. 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) -min_version: 'beta' references: guides: api: 'https://cloud.google.com/compute/docs/reference/rest/v1/firewallPolicies/addAssociation' diff --git a/tpgtools/overrides/compute/firewall_policy_association.yaml b/tpgtools/overrides/compute/firewall_policy_association.yaml deleted file mode 100644 index ba8d27aa31cc..000000000000 --- a/tpgtools/overrides/compute/firewall_policy_association.yaml +++ /dev/null @@ -1,4 +0,0 @@ -- type: CUSTOMIZE_DIFF - details: - functions: - - tpgresource.DefaultProviderProject \ No newline at end of file