From fefeebfccb0a5b70c1ec688ed07e7475266cda85 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Wed, 10 Nov 2021 14:00:28 -0800 Subject: [PATCH] Revert "Reimplemented compute service attachment using the DCL (#5342)" (#5442) --- mmv1/products/compute/terraform.yaml | 1 - ...esource_compute_service_attachment_test.go | 4 +- .../terraform/utils/provider.go.erb | 1 - .../terraform/utils/provider_test.go.erb | 2 +- .../terraform/utils/self_link_helpers.go | 11 - .../compute/beta/service_attachment.yaml | 6 - .../samples/serviceattachment/basic.tf.tmpl | 83 ----- .../samples/serviceattachment/basic.yaml | 4 - .../serviceattachment/basic_update0.tf.tmpl | 83 ----- .../serviceattachment/basic_update1.tf.tmpl | 78 ----- .../samples/serviceattachment/meta.yaml | 33 -- .../overrides/compute/service_attachment.yaml | 6 - tpgtools/property.go | 14 +- tpgtools/sample.go | 2 +- tpgtools/serialization.go | 330 ------------------ 15 files changed, 5 insertions(+), 653 deletions(-) delete mode 100644 tpgtools/overrides/compute/beta/service_attachment.yaml delete mode 100644 tpgtools/overrides/compute/samples/serviceattachment/basic.tf.tmpl delete mode 100644 tpgtools/overrides/compute/samples/serviceattachment/basic.yaml delete mode 100644 tpgtools/overrides/compute/samples/serviceattachment/basic_update0.tf.tmpl delete mode 100644 tpgtools/overrides/compute/samples/serviceattachment/basic_update1.tf.tmpl delete mode 100644 tpgtools/overrides/compute/samples/serviceattachment/meta.yaml delete mode 100644 tpgtools/overrides/compute/service_attachment.yaml diff --git a/mmv1/products/compute/terraform.yaml b/mmv1/products/compute/terraform.yaml index 1c203b83b305..3a283da783e8 100644 --- a/mmv1/products/compute/terraform.yaml +++ b/mmv1/products/compute/terraform.yaml @@ -2431,7 +2431,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides SecurityPolicy: !ruby/object:Overrides::Terraform::ResourceOverride exclude: true ServiceAttachment: !ruby/object:Overrides::Terraform::ResourceOverride - exclude: true examples: - !ruby/object:Provider::Terraform::Examples name: "service_attachment_basic" diff --git a/mmv1/third_party/terraform/tests/resource_compute_service_attachment_test.go b/mmv1/third_party/terraform/tests/resource_compute_service_attachment_test.go index 79a1260b1508..abc5565f510c 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_service_attachment_test.go +++ b/mmv1/third_party/terraform/tests/resource_compute_service_attachment_test.go @@ -25,7 +25,7 @@ func TestAccComputeServiceAttachment_serviceAttachmentBasicExampleUpdate(t *test ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"target_service", "region", "nat_subnets.0"}, + ImportStateVerifyIgnore: []string{"target_service", "region"}, }, { Config: testAccComputeServiceAttachment_serviceAttachmentBasicExampleUpdate(context), @@ -34,7 +34,7 @@ func TestAccComputeServiceAttachment_serviceAttachmentBasicExampleUpdate(t *test ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"target_service", "region", "nat_subnets.0"}, + ImportStateVerifyIgnore: []string{"target_service", "region"}, }, }, }) diff --git a/mmv1/third_party/terraform/utils/provider.go.erb b/mmv1/third_party/terraform/utils/provider.go.erb index 5bf2a7bcf005..a012c93c9bcc 100644 --- a/mmv1/third_party/terraform/utils/provider.go.erb +++ b/mmv1/third_party/terraform/utils/provider.go.erb @@ -462,7 +462,6 @@ end # products.each do "google_compute_firewall_policy_association": resourceComputeFirewallPolicyAssociation(), "google_compute_firewall_policy": resourceComputeFirewallPolicy(), "google_compute_firewall_policy_rule": resourceComputeFirewallPolicyRule(), - "google_compute_service_attachment": resourceComputeServiceAttachment(), "google_dataproc_workflow_template": resourceDataprocWorkflowTemplate(), "google_eventarc_trigger": resourceEventarcTrigger(), <% unless version == 'ga' -%> diff --git a/mmv1/third_party/terraform/utils/provider_test.go.erb b/mmv1/third_party/terraform/utils/provider_test.go.erb index ac82f18a1d91..a1fccc7996aa 100644 --- a/mmv1/third_party/terraform/utils/provider_test.go.erb +++ b/mmv1/third_party/terraform/utils/provider_test.go.erb @@ -1003,7 +1003,7 @@ func initializeReleaseDiffTest(c resource.TestCase) resource.TestCase { replacementSteps = append(replacementSteps, newStep) } replacementSteps = append(replacementSteps, testStep) - } else if !testStep.ImportStateVerify { + } else { replacementSteps = append(replacementSteps, testStep) } } diff --git a/mmv1/third_party/terraform/utils/self_link_helpers.go b/mmv1/third_party/terraform/utils/self_link_helpers.go index 040fc2ae889f..16767600e565 100644 --- a/mmv1/third_party/terraform/utils/self_link_helpers.go +++ b/mmv1/third_party/terraform/utils/self_link_helpers.go @@ -53,17 +53,6 @@ func compareSelfLinkOrResourceName(_, old, new string, _ *schema.ResourceData) b return compareSelfLinkRelativePaths("", old, new, nil) } -// compareSelfLinkOrResourceNameList checks if two elements of lists of resources are the same resource -// -// Use this method when the field accepts either a name or a self_link referencing a resource. -// The value we store (i.e. `old` in this method), must be a self_link. -func compareSelfLinkOrResourceNameList(k, old, new string, _ *schema.ResourceData) bool { - if strings.HasSuffix(k, ".#") { - return new == old - } - return compareSelfLinkOrResourceName("", old, new, nil) -} - // Hash the relative path of a self link. func selfLinkRelativePathHash(selfLink interface{}) int { path, _ := getRelativePath(selfLink.(string)) diff --git a/tpgtools/overrides/compute/beta/service_attachment.yaml b/tpgtools/overrides/compute/beta/service_attachment.yaml deleted file mode 100644 index 0b7ede6bc2d3..000000000000 --- a/tpgtools/overrides/compute/beta/service_attachment.yaml +++ /dev/null @@ -1,6 +0,0 @@ -- type: EXCLUDE - field: region -- type: CUSTOM_NAME - details: - name: region - field: location diff --git a/tpgtools/overrides/compute/samples/serviceattachment/basic.tf.tmpl b/tpgtools/overrides/compute/samples/serviceattachment/basic.tf.tmpl deleted file mode 100644 index 5d8e3d286f12..000000000000 --- a/tpgtools/overrides/compute/samples/serviceattachment/basic.tf.tmpl +++ /dev/null @@ -1,83 +0,0 @@ -resource "google_compute_service_attachment" "primary" { - connection_preference = "ACCEPT_MANUAL" - name = "{{attachment}}" - nat_subnets = [google_compute_subnetwork.first_private_service_connect.self_link] - target_service = google_compute_forwarding_rule.first_internal.self_link - - consumer_accept_lists { - project_id_or_num = google_project.second.name - connection_limit = 2 - } - - consumer_reject_lists = [google_project.first.name] - description = "A sample service attachment" - enable_proxy_protocol = false - project = "{{project}}" - region = "{{region}}" -} - -resource "google_compute_forwarding_rule" "first_internal" { - name = "{{rule1}}" - all_ports = true - backend_service = google_compute_region_backend_service.internal.self_link - description = "A test forwarding rule with internal load balancing scheme" - load_balancing_scheme = "INTERNAL" - network = google_compute_network.basic.self_link - network_tier = "PREMIUM" - project = "{{project}}" - region = "{{region}}" - subnetwork = google_compute_subnetwork.private.self_link -} - -resource "google_compute_region_backend_service" "internal" { - name = "{{service}}" - load_balancing_scheme = "INTERNAL" - region = "{{region}}" - network = google_compute_network.basic.self_link - project = "{{project}}" -} - -resource "google_compute_subnetwork" "first_private_service_connect" { - ip_cidr_range = "10.2.0.0/16" - name = "{{compute_psc_subnetwork1}}" - network = google_compute_network.basic.self_link - project = "{{project}}" - purpose = "PRIVATE_SERVICE_CONNECT" - region = "{{region}}" -} - -resource "google_compute_subnetwork" "second_private_service_connect" { - ip_cidr_range = "10.3.0.0/16" - name = "{{compute_psc_subnetwork2}}" - network = google_compute_network.basic.self_link - project = "{{project}}" - purpose = "PRIVATE_SERVICE_CONNECT" - region = "{{region}}" -} - -resource "google_compute_subnetwork" "private" { - ip_cidr_range = "10.4.0.0/16" - name = "{{compute_private_subnetwork}}" - network = google_compute_network.basic.self_link - project = "{{project}}" - purpose = "PRIVATE" - region = "{{region}}" -} - -resource "google_compute_network" "basic" { - name = "{{compute_network}}" - auto_create_subnetworks = false - project = "{{project}}" -} - -resource "google_project" "first" { - project_id = "{{id1}}" - name = "{{id1}}" - org_id = "{{org_id}}" -} - -resource "google_project" "second" { - project_id = "{{id2}}" - name = "{{id2}}" - org_id = "{{org_id}}" -} diff --git a/tpgtools/overrides/compute/samples/serviceattachment/basic.yaml b/tpgtools/overrides/compute/samples/serviceattachment/basic.yaml deleted file mode 100644 index af3ed5a6d315..000000000000 --- a/tpgtools/overrides/compute/samples/serviceattachment/basic.yaml +++ /dev/null @@ -1,4 +0,0 @@ -# optional test level config -- needed for updates basic.tf.tmpl def -updates: -- resource: ./basic_update0.tf.tmpl -- resource: ./basic_update1.tf.tmpl diff --git a/tpgtools/overrides/compute/samples/serviceattachment/basic_update0.tf.tmpl b/tpgtools/overrides/compute/samples/serviceattachment/basic_update0.tf.tmpl deleted file mode 100644 index bdf42742132a..000000000000 --- a/tpgtools/overrides/compute/samples/serviceattachment/basic_update0.tf.tmpl +++ /dev/null @@ -1,83 +0,0 @@ -resource "google_compute_service_attachment" "primary" { - connection_preference = "ACCEPT_MANUAL" - name = "{{attachment}}" - nat_subnets = [google_compute_subnetwork.first_private_service_connect.self_link] - target_service = google_compute_forwarding_rule.first_internal.self_link - - consumer_accept_lists { - project_id_or_num = google_project.first.name - connection_limit = 3 - } - - consumer_reject_lists = [google_project.second.name] - description = "A sample service attachment" - enable_proxy_protocol = false - project = "{{project}}" - region = "{{region}}" -} - -resource "google_compute_forwarding_rule" "first_internal" { - name = "{{rule1}}" - all_ports = true - backend_service = google_compute_region_backend_service.internal.self_link - description = "A test forwarding rule with internal load balancing scheme" - load_balancing_scheme = "INTERNAL" - network = google_compute_network.basic.self_link - network_tier = "PREMIUM" - project = "{{project}}" - region = "{{region}}" - subnetwork = google_compute_subnetwork.private.self_link -} - -resource "google_compute_region_backend_service" "internal" { - name = "{{service}}" - load_balancing_scheme = "INTERNAL" - region = "{{region}}" - network = google_compute_network.basic.self_link - project = "{{project}}" -} - -resource "google_compute_subnetwork" "first_private_service_connect" { - ip_cidr_range = "10.2.0.0/16" - name = "{{compute_psc_subnetwork1}}" - network = google_compute_network.basic.self_link - project = "{{project}}" - purpose = "PRIVATE_SERVICE_CONNECT" - region = "{{region}}" -} - -resource "google_compute_subnetwork" "second_private_service_connect" { - ip_cidr_range = "10.3.0.0/16" - name = "{{compute_psc_subnetwork2}}" - network = google_compute_network.basic.self_link - project = "{{project}}" - purpose = "PRIVATE_SERVICE_CONNECT" - region = "{{region}}" -} - -resource "google_compute_subnetwork" "private" { - ip_cidr_range = "10.4.0.0/16" - name = "{{compute_private_subnetwork}}" - network = google_compute_network.basic.self_link - project = "{{project}}" - purpose = "PRIVATE" - region = "{{region}}" -} - -resource "google_compute_network" "basic" { - name = "{{compute_network}}" - auto_create_subnetworks = false - project = "{{project}}" -} - -resource "google_project" "first" { - project_id = "{{id1}}" - name = "{{id1}}" - org_id = "{{org_id}}" -} - -resource "google_project" "second" { - project_id = "{{id2}}" - name = "{{id2}}" - org_id = "{{org_id}}" -} diff --git a/tpgtools/overrides/compute/samples/serviceattachment/basic_update1.tf.tmpl b/tpgtools/overrides/compute/samples/serviceattachment/basic_update1.tf.tmpl deleted file mode 100644 index 17cf5cbb1b16..000000000000 --- a/tpgtools/overrides/compute/samples/serviceattachment/basic_update1.tf.tmpl +++ /dev/null @@ -1,78 +0,0 @@ -resource "google_compute_service_attachment" "primary" { - connection_preference = "ACCEPT_AUTOMATIC" - name = "{{attachment}}" - nat_subnets = [google_compute_subnetwork.first_private_service_connect.self_link] - target_service = google_compute_forwarding_rule.first_internal.self_link - - consumer_reject_lists = [] - description = "A sample service attachment" - enable_proxy_protocol = false - project = "{{project}}" - region = "{{region}}" -} - -resource "google_compute_forwarding_rule" "first_internal" { - name = "{{rule1}}" - all_ports = true - backend_service = google_compute_region_backend_service.internal.self_link - description = "A test forwarding rule with internal load balancing scheme" - load_balancing_scheme = "INTERNAL" - network = google_compute_network.basic.self_link - network_tier = "PREMIUM" - project = "{{project}}" - region = "{{region}}" - subnetwork = google_compute_subnetwork.private.self_link -} - -resource "google_compute_region_backend_service" "internal" { - name = "{{service}}" - load_balancing_scheme = "INTERNAL" - region = "{{region}}" - network = google_compute_network.basic.self_link - project = "{{project}}" -} - -resource "google_compute_subnetwork" "first_private_service_connect" { - ip_cidr_range = "10.2.0.0/16" - name = "{{compute_psc_subnetwork1}}" - network = google_compute_network.basic.self_link - project = "{{project}}" - purpose = "PRIVATE_SERVICE_CONNECT" - region = "{{region}}" -} - -resource "google_compute_subnetwork" "second_private_service_connect" { - ip_cidr_range = "10.3.0.0/16" - name = "{{compute_psc_subnetwork2}}" - network = google_compute_network.basic.self_link - project = "{{project}}" - purpose = "PRIVATE_SERVICE_CONNECT" - region = "{{region}}" -} - -resource "google_compute_subnetwork" "private" { - ip_cidr_range = "10.4.0.0/16" - name = "{{compute_private_subnetwork}}" - network = google_compute_network.basic.self_link - project = "{{project}}" - purpose = "PRIVATE" - region = "{{region}}" -} - -resource "google_compute_network" "basic" { - name = "{{compute_network}}" - auto_create_subnetworks = false - project = "{{project}}" -} - -resource "google_project" "first" { - project_id = "{{id1}}" - name = "{{id1}}" - org_id = "{{org_id}}" -} - -resource "google_project" "second" { - project_id = "{{id2}}" - name = "{{id2}}" - org_id = "{{org_id}}" -} diff --git a/tpgtools/overrides/compute/samples/serviceattachment/meta.yaml b/tpgtools/overrides/compute/samples/serviceattachment/meta.yaml deleted file mode 100644 index 956b80b0b19c..000000000000 --- a/tpgtools/overrides/compute/samples/serviceattachment/meta.yaml +++ /dev/null @@ -1,33 +0,0 @@ -substitutions: - - substitution: "org_id" - value: ":ORG_ID" - - substitution: "project" - value: ":PROJECT" - - substitution: "region" - value: ":REGION" - - substitution: "attachment" - value: "test-attachment" - - substitution: "service" - value: "test-service" - - substitution: "rule1" - value: "test-rule1" - - substitution: "compute_psc_subnetwork1" - value: "compute-psc-subnetwork1" - - substitution: "compute_psc_subnetwork2" - value: "compute-psc-subnetwork2" - - substitution: "compute_private_subnetwork" - value: "compute-private-subnetwork" - - substitution: "compute_network" - value: "compute-network" - - substitution: "id1" - value: "test-id1" - - substitution: "id2" - value: "test-id2" -ignore_read: - - nat_subnets.0 - - consumer_accept_lists.0.project_id_or_num - - consumer_reject_lists.0 -doc_hide: - - basic.tf.tmpl # basic_update0.tf.tmpl and basic_update1.tf.tmpl auto hide -test_hide: - - basic_service_attachment.yaml diff --git a/tpgtools/overrides/compute/service_attachment.yaml b/tpgtools/overrides/compute/service_attachment.yaml deleted file mode 100644 index 0b7ede6bc2d3..000000000000 --- a/tpgtools/overrides/compute/service_attachment.yaml +++ /dev/null @@ -1,6 +0,0 @@ -- type: EXCLUDE - field: region -- type: CUSTOM_NAME - details: - name: region - field: location diff --git a/tpgtools/property.go b/tpgtools/property.go index 08b3a5981ee8..02f0484d1372 100644 --- a/tpgtools/property.go +++ b/tpgtools/property.go @@ -392,25 +392,13 @@ func getSchemaExtensionMap(v interface{}) map[interface{}]interface{} { } func (p Property) DefaultDiffSuppress() *string { - if p.Computed { - return nil - } switch p.Type.String() { case SchemaTypeString: + // Field is reference to another resource if _, ok := p.typ.Extension["x-dcl-references"]; ok { - // Field is reference to another resource. dsf := "compareSelfLinkOrResourceName" return &dsf } - case SchemaTypeList: - if p.typ.Items == nil || len(p.typ.Items.Extension) == 0 { - return nil - } - if _, ok := p.typ.Items.Extension["x-dcl-references"]; ok { - // Field is reference to another resource. - dsf := "compareSelfLinkOrResourceNameList" - return &dsf - } } return nil } diff --git a/tpgtools/sample.go b/tpgtools/sample.go index 46b3d7d0c4f5..16427130ab8d 100644 --- a/tpgtools/sample.go +++ b/tpgtools/sample.go @@ -213,7 +213,7 @@ func (s Sample) ReplaceReferences(d *Dependency) error { var tfReference string for _, dep := range s.DependencyList { if dep.FileName == referenceFileName { - tfReference = dep.TerraformResourceType + "." + dep.HCLLocalName + "." + jsonToSnakeCase(idField) + tfReference = dep.TerraformResourceType + "." + dep.HCLLocalName + "." + idField break } } diff --git a/tpgtools/serialization.go b/tpgtools/serialization.go index b93a714c0916..1d18850c54fd 100644 --- a/tpgtools/serialization.go +++ b/tpgtools/serialization.go @@ -68,8 +68,6 @@ func DCLToTerraformReference(resourceType, version string) (string, error) { return "google_compute_forwarding_rule", nil case "ComputeGlobalForwardingRule": return "google_compute_global_forwarding_rule", nil - case "ComputeServiceAttachment": - return "google_compute_service_attachment", nil case "DataprocWorkflowTemplate": return "google_dataproc_workflow_template", nil case "EventarcTrigger": @@ -104,8 +102,6 @@ func DCLToTerraformReference(resourceType, version string) (string, error) { return "google_compute_forwarding_rule", nil case "ComputeGlobalForwardingRule": return "google_compute_global_forwarding_rule", nil - case "ComputeServiceAttachment": - return "google_compute_service_attachment", nil case "DataprocWorkflowTemplate": return "google_dataproc_workflow_template", nil case "EventarcTrigger": @@ -139,8 +135,6 @@ func DCLToTerraformSampleName(service, resource string) (string, string, error) return "Compute", "FirewallPolicyRule", nil case "computeforwardingrule": return "Compute", "ForwardingRule", nil - case "computeserviceattachment": - return "Compute", "ServiceAttachment", nil case "dataprocworkflowtemplate": return "Dataproc", "WorkflowTemplate", nil case "eventarctrigger": @@ -217,12 +211,6 @@ func ConvertSampleJSONToHCL(resourceType string, version string, hasGAEquivalent return "", err } return ComputeGlobalForwardingRuleBetaAsHCL(*r, hasGAEquivalent) - case "ComputeServiceAttachment": - r := &computeBeta.ServiceAttachment{} - if err := json.Unmarshal(b, r); err != nil { - return "", err - } - return ComputeServiceAttachmentBetaAsHCL(*r, hasGAEquivalent) case "DataprocWorkflowTemplate": r := &dataprocBeta.WorkflowTemplate{} if err := json.Unmarshal(b, r); err != nil { @@ -317,12 +305,6 @@ func ConvertSampleJSONToHCL(resourceType string, version string, hasGAEquivalent return "", err } return ComputeGlobalForwardingRuleAsHCL(*r, hasGAEquivalent) - case "ComputeServiceAttachment": - r := &compute.ServiceAttachment{} - if err := json.Unmarshal(b, r); err != nil { - return "", err - } - return ComputeServiceAttachmentAsHCL(*r, hasGAEquivalent) case "DataprocWorkflowTemplate": r := &dataproc.WorkflowTemplate{} if err := json.Unmarshal(b, r); err != nil { @@ -869,95 +851,6 @@ func convertComputeGlobalForwardingRuleBetaMetadataFilterFilterLabelToHCL(r *com return outputConfig + "}" } -// ComputeServiceAttachmentBetaAsHCL returns a string representation of the specified resource in HCL. -// The generated HCL will include every settable field as a literal - that is, no -// variables, no references. This may not be the best possible representation, but -// the crucial point is that `terraform import; terraform apply` will not produce -// any changes. We do not validate that the resource specified will pass terraform -// validation unless is an object returned from the API after an Apply. -func ComputeServiceAttachmentBetaAsHCL(r computeBeta.ServiceAttachment, hasGAEquivalent bool) (string, error) { - outputConfig := "resource \"google_compute_service_attachment\" \"output\" {\n" - if r.ConnectionPreference != nil { - outputConfig += fmt.Sprintf("\tconnection_preference = %#v\n", *r.ConnectionPreference) - } - if r.Name != nil { - outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name) - } - if r.NatSubnets != nil { - outputConfig += "\tnat_subnets = [" - for _, v := range r.NatSubnets { - outputConfig += fmt.Sprintf("%#v, ", v) - } - outputConfig += "]\n" - } - if r.TargetService != nil { - outputConfig += fmt.Sprintf("\ttarget_service = %#v\n", *r.TargetService) - } - if r.ConsumerAcceptLists != nil { - for _, v := range r.ConsumerAcceptLists { - outputConfig += fmt.Sprintf("\tconsumer_accept_lists %s\n", convertComputeServiceAttachmentBetaConsumerAcceptListsToHCL(&v)) - } - } - if r.ConsumerRejectLists != nil { - outputConfig += "\tconsumer_reject_lists = [" - for _, v := range r.ConsumerRejectLists { - outputConfig += fmt.Sprintf("%#v, ", v) - } - outputConfig += "]\n" - } - if r.Description != nil { - outputConfig += fmt.Sprintf("\tdescription = %#v\n", *r.Description) - } - if r.EnableProxyProtocol != nil { - outputConfig += fmt.Sprintf("\tenable_proxy_protocol = %#v\n", *r.EnableProxyProtocol) - } - if r.Project != nil { - outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project) - } - if r.Location != nil { - outputConfig += fmt.Sprintf("\tregion = %#v\n", *r.Location) - } - formatted, err := formatHCL(outputConfig + "}") - if err != nil { - return "", err - } - if !hasGAEquivalent { - // The formatter will not accept the google-beta symbol because it is injected during testing. - return withProviderLine(formatted), nil - } - return formatted, nil -} - -func convertComputeServiceAttachmentBetaConsumerAcceptListsToHCL(r *computeBeta.ServiceAttachmentConsumerAcceptLists) string { - if r == nil { - return "" - } - outputConfig := "{\n" - if r.ProjectIdOrNum != nil { - outputConfig += fmt.Sprintf("\tproject_id_or_num = %#v\n", *r.ProjectIdOrNum) - } - if r.ConnectionLimit != nil { - outputConfig += fmt.Sprintf("\tconnection_limit = %#v\n", *r.ConnectionLimit) - } - return outputConfig + "}" -} - -func convertComputeServiceAttachmentBetaConnectedEndpointsToHCL(r *computeBeta.ServiceAttachmentConnectedEndpoints) string { - if r == nil { - return "" - } - outputConfig := "{\n" - return outputConfig + "}" -} - -func convertComputeServiceAttachmentBetaPscServiceAttachmentIdToHCL(r *computeBeta.ServiceAttachmentPscServiceAttachmentId) string { - if r == nil { - return "" - } - outputConfig := "{\n" - return outputConfig + "}" -} - // DataprocWorkflowTemplateBetaAsHCL returns a string representation of the specified resource in HCL. // The generated HCL will include every settable field as a literal - that is, no // variables, no references. This may not be the best possible representation, but @@ -3187,95 +3080,6 @@ func convertComputeGlobalForwardingRuleMetadataFilterFilterLabelToHCL(r *compute return outputConfig + "}" } -// ComputeServiceAttachmentAsHCL returns a string representation of the specified resource in HCL. -// The generated HCL will include every settable field as a literal - that is, no -// variables, no references. This may not be the best possible representation, but -// the crucial point is that `terraform import; terraform apply` will not produce -// any changes. We do not validate that the resource specified will pass terraform -// validation unless is an object returned from the API after an Apply. -func ComputeServiceAttachmentAsHCL(r compute.ServiceAttachment, hasGAEquivalent bool) (string, error) { - outputConfig := "resource \"google_compute_service_attachment\" \"output\" {\n" - if r.ConnectionPreference != nil { - outputConfig += fmt.Sprintf("\tconnection_preference = %#v\n", *r.ConnectionPreference) - } - if r.Name != nil { - outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name) - } - if r.NatSubnets != nil { - outputConfig += "\tnat_subnets = [" - for _, v := range r.NatSubnets { - outputConfig += fmt.Sprintf("%#v, ", v) - } - outputConfig += "]\n" - } - if r.TargetService != nil { - outputConfig += fmt.Sprintf("\ttarget_service = %#v\n", *r.TargetService) - } - if r.ConsumerAcceptLists != nil { - for _, v := range r.ConsumerAcceptLists { - outputConfig += fmt.Sprintf("\tconsumer_accept_lists %s\n", convertComputeServiceAttachmentConsumerAcceptListsToHCL(&v)) - } - } - if r.ConsumerRejectLists != nil { - outputConfig += "\tconsumer_reject_lists = [" - for _, v := range r.ConsumerRejectLists { - outputConfig += fmt.Sprintf("%#v, ", v) - } - outputConfig += "]\n" - } - if r.Description != nil { - outputConfig += fmt.Sprintf("\tdescription = %#v\n", *r.Description) - } - if r.EnableProxyProtocol != nil { - outputConfig += fmt.Sprintf("\tenable_proxy_protocol = %#v\n", *r.EnableProxyProtocol) - } - if r.Project != nil { - outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project) - } - if r.Location != nil { - outputConfig += fmt.Sprintf("\tregion = %#v\n", *r.Location) - } - formatted, err := formatHCL(outputConfig + "}") - if err != nil { - return "", err - } - if !hasGAEquivalent { - // The formatter will not accept the google-beta symbol because it is injected during testing. - return withProviderLine(formatted), nil - } - return formatted, nil -} - -func convertComputeServiceAttachmentConsumerAcceptListsToHCL(r *compute.ServiceAttachmentConsumerAcceptLists) string { - if r == nil { - return "" - } - outputConfig := "{\n" - if r.ProjectIdOrNum != nil { - outputConfig += fmt.Sprintf("\tproject_id_or_num = %#v\n", *r.ProjectIdOrNum) - } - if r.ConnectionLimit != nil { - outputConfig += fmt.Sprintf("\tconnection_limit = %#v\n", *r.ConnectionLimit) - } - return outputConfig + "}" -} - -func convertComputeServiceAttachmentConnectedEndpointsToHCL(r *compute.ServiceAttachmentConnectedEndpoints) string { - if r == nil { - return "" - } - outputConfig := "{\n" - return outputConfig + "}" -} - -func convertComputeServiceAttachmentPscServiceAttachmentIdToHCL(r *compute.ServiceAttachmentPscServiceAttachmentId) string { - if r == nil { - return "" - } - outputConfig := "{\n" - return outputConfig + "}" -} - // DataprocWorkflowTemplateAsHCL returns a string representation of the specified resource in HCL. // The generated HCL will include every settable field as a literal - that is, no // variables, no references. This may not be the best possible representation, but @@ -4946,73 +4750,6 @@ func convertComputeGlobalForwardingRuleBetaMetadataFilterFilterLabelList(i inter return out } -func convertComputeServiceAttachmentBetaConsumerAcceptLists(i interface{}) map[string]interface{} { - if i == nil { - return nil - } - in := i.(map[string]interface{}) - return map[string]interface{}{ - "projectIdOrNum": in["project_id_or_num"], - "connectionLimit": in["connection_limit"], - } -} - -func convertComputeServiceAttachmentBetaConsumerAcceptListsList(i interface{}) (out []map[string]interface{}) { - if i == nil { - return nil - } - - for _, v := range i.([]interface{}) { - out = append(out, convertComputeServiceAttachmentBetaConsumerAcceptLists(v)) - } - return out -} - -func convertComputeServiceAttachmentBetaConnectedEndpoints(i interface{}) map[string]interface{} { - if i == nil { - return nil - } - in := i.(map[string]interface{}) - return map[string]interface{}{ - "endpoint": in["endpoint"], - "pscConnectionId": in["psc_connection_id"], - "status": in["status"], - } -} - -func convertComputeServiceAttachmentBetaConnectedEndpointsList(i interface{}) (out []map[string]interface{}) { - if i == nil { - return nil - } - - for _, v := range i.([]interface{}) { - out = append(out, convertComputeServiceAttachmentBetaConnectedEndpoints(v)) - } - return out -} - -func convertComputeServiceAttachmentBetaPscServiceAttachmentId(i interface{}) map[string]interface{} { - if i == nil { - return nil - } - in := i.(map[string]interface{}) - return map[string]interface{}{ - "high": in["high"], - "low": in["low"], - } -} - -func convertComputeServiceAttachmentBetaPscServiceAttachmentIdList(i interface{}) (out []map[string]interface{}) { - if i == nil { - return nil - } - - for _, v := range i.([]interface{}) { - out = append(out, convertComputeServiceAttachmentBetaPscServiceAttachmentId(v)) - } - return out -} - func convertDataprocWorkflowTemplateBetaJobs(i interface{}) map[string]interface{} { if i == nil { return nil @@ -7044,73 +6781,6 @@ func convertComputeGlobalForwardingRuleMetadataFilterFilterLabelList(i interface return out } -func convertComputeServiceAttachmentConsumerAcceptLists(i interface{}) map[string]interface{} { - if i == nil { - return nil - } - in := i.(map[string]interface{}) - return map[string]interface{}{ - "projectIdOrNum": in["project_id_or_num"], - "connectionLimit": in["connection_limit"], - } -} - -func convertComputeServiceAttachmentConsumerAcceptListsList(i interface{}) (out []map[string]interface{}) { - if i == nil { - return nil - } - - for _, v := range i.([]interface{}) { - out = append(out, convertComputeServiceAttachmentConsumerAcceptLists(v)) - } - return out -} - -func convertComputeServiceAttachmentConnectedEndpoints(i interface{}) map[string]interface{} { - if i == nil { - return nil - } - in := i.(map[string]interface{}) - return map[string]interface{}{ - "endpoint": in["endpoint"], - "pscConnectionId": in["psc_connection_id"], - "status": in["status"], - } -} - -func convertComputeServiceAttachmentConnectedEndpointsList(i interface{}) (out []map[string]interface{}) { - if i == nil { - return nil - } - - for _, v := range i.([]interface{}) { - out = append(out, convertComputeServiceAttachmentConnectedEndpoints(v)) - } - return out -} - -func convertComputeServiceAttachmentPscServiceAttachmentId(i interface{}) map[string]interface{} { - if i == nil { - return nil - } - in := i.(map[string]interface{}) - return map[string]interface{}{ - "high": in["high"], - "low": in["low"], - } -} - -func convertComputeServiceAttachmentPscServiceAttachmentIdList(i interface{}) (out []map[string]interface{}) { - if i == nil { - return nil - } - - for _, v := range i.([]interface{}) { - out = append(out, convertComputeServiceAttachmentPscServiceAttachmentId(v)) - } - return out -} - func convertDataprocWorkflowTemplateJobs(i interface{}) map[string]interface{} { if i == nil { return nil