diff --git a/.changelog/9616.txt b/.changelog/9616.txt new file mode 100644 index 0000000000..366fd3bcfa --- /dev/null +++ b/.changelog/9616.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_integration_connectors_endpoint_attachment` +``` diff --git a/google-beta/provider/provider_mmv1_resources.go b/google-beta/provider/provider_mmv1_resources.go index 1afc83097e..fafad96a55 100644 --- a/google-beta/provider/provider_mmv1_resources.go +++ b/google-beta/provider/provider_mmv1_resources.go @@ -417,9 +417,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{ } // Resources -// Generated resources: 406 +// Generated resources: 407 // Generated IAM resources: 252 -// Total generated resources: 658 +// Total generated resources: 659 var generatedResources = map[string]*schema.Resource{ "google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(), "google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(), @@ -887,6 +887,7 @@ var generatedResources = map[string]*schema.Resource{ "google_identity_platform_tenant_inbound_saml_config": identityplatform.ResourceIdentityPlatformTenantInboundSamlConfig(), "google_identity_platform_tenant_oauth_idp_config": identityplatform.ResourceIdentityPlatformTenantOauthIdpConfig(), "google_integration_connectors_connection": integrationconnectors.ResourceIntegrationConnectorsConnection(), + "google_integration_connectors_endpoint_attachment": integrationconnectors.ResourceIntegrationConnectorsEndpointAttachment(), "google_kms_crypto_key": kms.ResourceKMSCryptoKey(), "google_kms_crypto_key_version": kms.ResourceKMSCryptoKeyVersion(), "google_kms_key_ring": kms.ResourceKMSKeyRing(), diff --git a/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment.go b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment.go new file mode 100644 index 0000000000..1c6342ec47 --- /dev/null +++ b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment.go @@ -0,0 +1,518 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: MMv1 *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package integrationconnectors + +import ( + "fmt" + "log" + "reflect" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" +) + +func ResourceIntegrationConnectorsEndpointAttachment() *schema.Resource { + return &schema.Resource{ + Create: resourceIntegrationConnectorsEndpointAttachmentCreate, + Read: resourceIntegrationConnectorsEndpointAttachmentRead, + Update: resourceIntegrationConnectorsEndpointAttachmentUpdate, + Delete: resourceIntegrationConnectorsEndpointAttachmentDelete, + + Importer: &schema.ResourceImporter{ + State: resourceIntegrationConnectorsEndpointAttachmentImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(5 * time.Minute), + Delete: schema.DefaultTimeout(5 * time.Minute), + }, + + CustomizeDiff: customdiff.All( + tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderProject, + ), + + Schema: map[string]*schema.Schema{ + "location": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `Location in which Endpoint Attachment needs to be created.`, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `Name of Endpoint Attachment needs to be created.`, + }, + "service_attachment": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The path of the service attachment.`, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Description: `Description of the resource.`, + }, + "labels": { + Type: schema.TypeMap, + Optional: true, + Description: `Resource labels to represent user provided metadata. + + +**Note**: This field is non-authoritative, and will only manage the labels present in your configuration. +Please refer to the field 'effective_labels' for all of the labels present on the resource.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: `Time the Namespace was created in UTC.`, + }, + "effective_labels": { + Type: schema.TypeMap, + Computed: true, + Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "endpoint_ip": { + Type: schema.TypeString, + Computed: true, + Description: `The Private Service Connect connection endpoint ip.`, + }, + "terraform_labels": { + Type: schema.TypeMap, + Computed: true, + Description: `The combination of labels configured directly on the resource + and default labels configured on the provider.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: `Time the Namespace was updated in UTC.`, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + UseJSONNumber: true, + } +} + +func resourceIntegrationConnectorsEndpointAttachmentCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + descriptionProp, err := expandIntegrationConnectorsEndpointAttachmentDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + serviceAttachmentProp, err := expandIntegrationConnectorsEndpointAttachmentServiceAttachment(d.Get("service_attachment"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("service_attachment"); !tpgresource.IsEmptyValue(reflect.ValueOf(serviceAttachmentProp)) && (ok || !reflect.DeepEqual(v, serviceAttachmentProp)) { + obj["serviceAttachment"] = serviceAttachmentProp + } + labelsProp, err := expandIntegrationConnectorsEndpointAttachmentEffectiveLabels(d.Get("effective_labels"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { + obj["labels"] = labelsProp + } + + url, err := tpgresource.ReplaceVars(d, config, "{{IntegrationConnectorsBasePath}}projects/{{project}}/locations/{{location}}/endpointAttachments?endpointAttachmentId={{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new EndpointAttachment: %#v", obj) + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for EndpointAttachment: %s", err) + } + billingProject = project + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutCreate), + }) + if err != nil { + return fmt.Errorf("Error creating EndpointAttachment: %s", err) + } + + // Store the ID now + id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + // Use the resource in the operation response to populate + // identity fields and d.Id() before read + var opRes map[string]interface{} + err = IntegrationConnectorsOperationWaitTimeWithResponse( + config, res, &opRes, project, "Creating EndpointAttachment", userAgent, + d.Timeout(schema.TimeoutCreate)) + if err != nil { + // The resource didn't actually create + d.SetId("") + + return fmt.Errorf("Error waiting to create EndpointAttachment: %s", err) + } + + // This may have caused the ID to update - update it if so. + id, err = tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating EndpointAttachment %q: %#v", d.Id(), res) + + return resourceIntegrationConnectorsEndpointAttachmentRead(d, meta) +} + +func resourceIntegrationConnectorsEndpointAttachmentRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + url, err := tpgresource.ReplaceVars(d, config, "{{IntegrationConnectorsBasePath}}projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}") + if err != nil { + return err + } + + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for EndpointAttachment: %s", err) + } + billingProject = project + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + }) + if err != nil { + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("IntegrationConnectorsEndpointAttachment %q", d.Id())) + } + + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading EndpointAttachment: %s", err) + } + + if err := d.Set("create_time", flattenIntegrationConnectorsEndpointAttachmentCreateTime(res["createTime"], d, config)); err != nil { + return fmt.Errorf("Error reading EndpointAttachment: %s", err) + } + if err := d.Set("update_time", flattenIntegrationConnectorsEndpointAttachmentUpdateTime(res["updateTime"], d, config)); err != nil { + return fmt.Errorf("Error reading EndpointAttachment: %s", err) + } + if err := d.Set("description", flattenIntegrationConnectorsEndpointAttachmentDescription(res["description"], d, config)); err != nil { + return fmt.Errorf("Error reading EndpointAttachment: %s", err) + } + if err := d.Set("labels", flattenIntegrationConnectorsEndpointAttachmentLabels(res["labels"], d, config)); err != nil { + return fmt.Errorf("Error reading EndpointAttachment: %s", err) + } + if err := d.Set("service_attachment", flattenIntegrationConnectorsEndpointAttachmentServiceAttachment(res["serviceAttachment"], d, config)); err != nil { + return fmt.Errorf("Error reading EndpointAttachment: %s", err) + } + if err := d.Set("endpoint_ip", flattenIntegrationConnectorsEndpointAttachmentEndpointIp(res["endpointIp"], d, config)); err != nil { + return fmt.Errorf("Error reading EndpointAttachment: %s", err) + } + if err := d.Set("terraform_labels", flattenIntegrationConnectorsEndpointAttachmentTerraformLabels(res["labels"], d, config)); err != nil { + return fmt.Errorf("Error reading EndpointAttachment: %s", err) + } + if err := d.Set("effective_labels", flattenIntegrationConnectorsEndpointAttachmentEffectiveLabels(res["labels"], d, config)); err != nil { + return fmt.Errorf("Error reading EndpointAttachment: %s", err) + } + + return nil +} + +func resourceIntegrationConnectorsEndpointAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for EndpointAttachment: %s", err) + } + billingProject = project + + obj := make(map[string]interface{}) + descriptionProp, err := expandIntegrationConnectorsEndpointAttachmentDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + labelsProp, err := expandIntegrationConnectorsEndpointAttachmentEffectiveLabels(d.Get("effective_labels"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) { + obj["labels"] = labelsProp + } + + url, err := tpgresource.ReplaceVars(d, config, "{{IntegrationConnectorsBasePath}}projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating EndpointAttachment %q: %#v", d.Id(), obj) + updateMask := []string{} + + if d.HasChange("description") { + updateMask = append(updateMask, "description") + } + + if d.HasChange("effective_labels") { + updateMask = append(updateMask, "labels") + } + // updateMask is a URL parameter but not present in the schema, so ReplaceVars + // won't set it + url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) + if err != nil { + return err + } + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + // if updateMask is empty we are not updating anything so skip the post + if len(updateMask) > 0 { + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "PATCH", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutUpdate), + }) + + if err != nil { + return fmt.Errorf("Error updating EndpointAttachment %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating EndpointAttachment %q: %#v", d.Id(), res) + } + + err = IntegrationConnectorsOperationWaitTime( + config, res, project, "Updating EndpointAttachment", userAgent, + d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return err + } + } + + return resourceIntegrationConnectorsEndpointAttachmentRead(d, meta) +} + +func resourceIntegrationConnectorsEndpointAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for EndpointAttachment: %s", err) + } + billingProject = project + + url, err := tpgresource.ReplaceVars(d, config, "{{IntegrationConnectorsBasePath}}projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting EndpointAttachment %q", d.Id()) + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "DELETE", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutDelete), + }) + if err != nil { + return transport_tpg.HandleNotFoundError(err, d, "EndpointAttachment") + } + + err = IntegrationConnectorsOperationWaitTime( + config, res, project, "Deleting EndpointAttachment", userAgent, + d.Timeout(schema.TimeoutDelete)) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting EndpointAttachment %q: %#v", d.Id(), res) + return nil +} + +func resourceIntegrationConnectorsEndpointAttachmentImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*transport_tpg.Config) + if err := tpgresource.ParseImportId([]string{ + "^projects/(?P[^/]+)/locations/(?P[^/]+)/endpointAttachments/(?P[^/]+)$", + "^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)$", + "^(?P[^/]+)/(?P[^/]+)$", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenIntegrationConnectorsEndpointAttachmentCreateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenIntegrationConnectorsEndpointAttachmentUpdateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenIntegrationConnectorsEndpointAttachmentDescription(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenIntegrationConnectorsEndpointAttachmentLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v + } + + transformed := make(map[string]interface{}) + if l, ok := d.GetOkExists("labels"); ok { + for k := range l.(map[string]interface{}) { + transformed[k] = v.(map[string]interface{})[k] + } + } + + return transformed +} + +func flattenIntegrationConnectorsEndpointAttachmentServiceAttachment(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenIntegrationConnectorsEndpointAttachmentEndpointIp(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenIntegrationConnectorsEndpointAttachmentTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v + } + + transformed := make(map[string]interface{}) + if l, ok := d.GetOkExists("terraform_labels"); ok { + for k := range l.(map[string]interface{}) { + transformed[k] = v.(map[string]interface{})[k] + } + } + + return transformed +} + +func flattenIntegrationConnectorsEndpointAttachmentEffectiveLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func expandIntegrationConnectorsEndpointAttachmentDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandIntegrationConnectorsEndpointAttachmentServiceAttachment(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandIntegrationConnectorsEndpointAttachmentEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) { + if v == nil { + return map[string]string{}, nil + } + m := make(map[string]string) + for k, val := range v.(map[string]interface{}) { + m[k] = val.(string) + } + return m, nil +} diff --git a/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_generated_test.go b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_generated_test.go new file mode 100644 index 0000000000..b1d9e52cec --- /dev/null +++ b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_generated_test.go @@ -0,0 +1,109 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: MMv1 *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package integrationconnectors_test + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" +) + +func TestAccIntegrationConnectorsEndpointAttachment_integrationConnectorsEndpointAttachmentExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckIntegrationConnectorsEndpointAttachmentDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccIntegrationConnectorsEndpointAttachment_integrationConnectorsEndpointAttachmentExample(context), + }, + { + ResourceName: "google_integration_connectors_endpoint_attachment.sampleendpointattachment", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"location", "name", "labels", "terraform_labels"}, + }, + }, + }) +} + +func testAccIntegrationConnectorsEndpointAttachment_integrationConnectorsEndpointAttachmentExample(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_integration_connectors_endpoint_attachment" "sampleendpointattachment" { + name = "tf-test-test-endpoint-attachment%{random_suffix}" + location = "us-central1" + description = "tf created description" + service_attachment = "projects/connectors-example/regions/us-central1/serviceAttachments/test" + labels = { + foo = "bar" + } +} +`, context) +} + +func testAccCheckIntegrationConnectorsEndpointAttachmentDestroyProducer(t *testing.T) func(s *terraform.State) error { + return func(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_integration_connectors_endpoint_attachment" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := acctest.GoogleProviderConfig(t) + + url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{IntegrationConnectorsBasePath}}projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}") + if err != nil { + return err + } + + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: config.UserAgent, + }) + if err == nil { + return fmt.Errorf("IntegrationConnectorsEndpointAttachment still exists at %s", url) + } + } + + return nil + } +} diff --git a/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_sweeper.go b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_sweeper.go new file mode 100644 index 0000000000..b2245e0c40 --- /dev/null +++ b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_sweeper.go @@ -0,0 +1,139 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: MMv1 *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package integrationconnectors + +import ( + "context" + "log" + "strings" + "testing" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/sweeper" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" +) + +func init() { + sweeper.AddTestSweepers("IntegrationConnectorsEndpointAttachment", testSweepIntegrationConnectorsEndpointAttachment) +} + +// At the time of writing, the CI only passes us-central1 as the region +func testSweepIntegrationConnectorsEndpointAttachment(region string) error { + resourceName := "IntegrationConnectorsEndpointAttachment" + log.Printf("[INFO][SWEEPER_LOG] Starting sweeper for %s", resourceName) + + config, err := sweeper.SharedConfigForRegion(region) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error getting shared config for region: %s", err) + return err + } + + err = config.LoadAndValidate(context.Background()) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error loading: %s", err) + return err + } + + t := &testing.T{} + billingId := envvar.GetTestBillingAccountFromEnv(t) + + // Setup variables to replace in list template + d := &tpgresource.ResourceDataMock{ + FieldsInSchema: map[string]interface{}{ + "project": config.Project, + "region": region, + "location": region, + "zone": "-", + "billing_account": billingId, + }, + } + + listTemplate := strings.Split("https://connectors.googleapis.com/v1/projects/{{project}}/locations/{{location}}/endpointAttachments", "?")[0] + listUrl, err := tpgresource.ReplaceVars(d, config, listTemplate) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error preparing sweeper list url: %s", err) + return nil + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: config.Project, + RawURL: listUrl, + UserAgent: config.UserAgent, + }) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error in response from request %s: %s", listUrl, err) + return nil + } + + resourceList, ok := res["endpointAttachments"] + if !ok { + log.Printf("[INFO][SWEEPER_LOG] Nothing found in response.") + return nil + } + + rl := resourceList.([]interface{}) + + log.Printf("[INFO][SWEEPER_LOG] Found %d items in %s list response.", len(rl), resourceName) + // Keep count of items that aren't sweepable for logging. + nonPrefixCount := 0 + for _, ri := range rl { + obj := ri.(map[string]interface{}) + if obj["name"] == nil { + log.Printf("[INFO][SWEEPER_LOG] %s resource name was nil", resourceName) + return nil + } + + name := tpgresource.GetResourceNameFromSelfLink(obj["name"].(string)) + // Skip resources that shouldn't be sweeped + if !sweeper.IsSweepableTestResource(name) { + nonPrefixCount++ + continue + } + + deleteTemplate := "https://connectors.googleapis.com/v1/projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}" + deleteUrl, err := tpgresource.ReplaceVars(d, config, deleteTemplate) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err) + return nil + } + deleteUrl = deleteUrl + name + + // Don't wait on operations as we may have a lot to delete + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "DELETE", + Project: config.Project, + RawURL: deleteUrl, + UserAgent: config.UserAgent, + }) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error deleting for url %s : %s", deleteUrl, err) + } else { + log.Printf("[INFO][SWEEPER_LOG] Sent delete request for %s resource: %s", resourceName, name) + } + } + + if nonPrefixCount > 0 { + log.Printf("[INFO][SWEEPER_LOG] %d items were non-sweepable and skipped.", nonPrefixCount) + } + + return nil +} diff --git a/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_test.go b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_test.go new file mode 100644 index 0000000000..b9f076f36b --- /dev/null +++ b/google-beta/services/integrationconnectors/resource_integration_connectors_endpoint_attachment_test.go @@ -0,0 +1,81 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +package integrationconnectors_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" +) + +func TestAccIntegrationConnectorsEndpointAttachment_integrationConnectorsEndpointAttachmentExample_update(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckIntegrationConnectorsEndpointAttachmentDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccIntegrationConnectorsEndpointAttachment_integrationConnectorsEndpointAttachmentExample_full(context), + }, + { + ResourceName: "google_integration_connectors_endpoint_attachment.sampleendpointattachment", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"location", "name", "labels", "terraform_labels"}, + }, + { + Config: testAccIntegrationConnectorsEndpointAttachment_integrationConnectorsEndpointAttachmentExample_update(context), + }, + { + ResourceName: "google_integration_connectors_endpoint_attachment.sampleendpointattachment", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"location", "name", "labels", "terraform_labels"}, + }, + }, + }) +} + +func testAccIntegrationConnectorsEndpointAttachment_integrationConnectorsEndpointAttachmentExample_full(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_project" "test_project" { +} + +resource "google_integration_connectors_endpoint_attachment" "sampleendpointattachment" { + name = "tf-test-test-endpoint-attachment%{random_suffix}" + location = "us-central1" + description = "tf created description" + # Third party dependency, see https://github.com/GoogleCloudPlatform/magic-modules/pull/9616#discussion_r1429029155 + service_attachment = "projects/connectors-example/regions/us-central1/serviceAttachments/test" + labels = { + foo = "bar" + } +} +`, context) +} + +func testAccIntegrationConnectorsEndpointAttachment_integrationConnectorsEndpointAttachmentExample_update(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_project" "test_project" { +} + +resource "google_integration_connectors_endpoint_attachment" "sampleendpointattachment" { + name = "tf-test-test-endpoint-attachment%{random_suffix}" + location = "us-central1" + description = "tf updated description" + # Third party dependency, see https://github.com/GoogleCloudPlatform/magic-modules/pull/9616#discussion_r1429029155 + service_attachment = "projects/connectors-example/regions/us-central1/serviceAttachments/test" + labels = { + bar = "foo" + } +} +`, context) +} diff --git a/website/docs/r/integration_connectors_endpoint_attachment.html.markdown b/website/docs/r/integration_connectors_endpoint_attachment.html.markdown new file mode 100644 index 0000000000..f50ccc4522 --- /dev/null +++ b/website/docs/r/integration_connectors_endpoint_attachment.html.markdown @@ -0,0 +1,148 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. +# +# ---------------------------------------------------------------------------- +subcategory: "Integration Connectors" +description: |- + An Integration connectors Endpoint Attachment. +--- + +# google\_integration\_connectors\_endpoint\_attachment + +An Integration connectors Endpoint Attachment. + + +To get more information about EndpointAttachment, see: + +* [API documentation](https://cloud.google.com/integration-connectors/docs/reference/rest/v1/projects.locations.endpointAttachments) +* How-to Guides + * [Official Documentation](https://cloud.google.com/integration-connectors/docs/create-endpoint-attachment) + + +## Example Usage - Integration Connectors Endpoint Attachment + + +```hcl +resource "google_integration_connectors_endpoint_attachment" "sampleendpointattachment" { + name = "test-endpoint-attachment" + location = "us-central1" + description = "tf created description" + service_attachment = "projects/connectors-example/regions/us-central1/serviceAttachments/test" + labels = { + foo = "bar" + } +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `service_attachment` - + (Required) + The path of the service attachment. + +* `location` - + (Required) + Location in which Endpoint Attachment needs to be created. + +* `name` - + (Required) + Name of Endpoint Attachment needs to be created. + + +- - - + + +* `description` - + (Optional) + Description of the resource. + +* `labels` - + (Optional) + Resource labels to represent user provided metadata. + + **Note**: This field is non-authoritative, and will only manage the labels present in your configuration. + Please refer to the field `effective_labels` for all of the labels present on the resource. + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `id` - an identifier for the resource with format `projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}` + +* `create_time` - + Time the Namespace was created in UTC. + +* `update_time` - + Time the Namespace was updated in UTC. + +* `endpoint_ip` - + The Private Service Connect connection endpoint ip. + +* `terraform_labels` - + The combination of labels configured directly on the resource + and default labels configured on the provider. + +* `effective_labels` - + All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. + + +## Timeouts + +This resource provides the following +[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: + +- `create` - Default is 5 minutes. +- `update` - Default is 5 minutes. +- `delete` - Default is 5 minutes. + +## Import + + +EndpointAttachment can be imported using any of these accepted formats: + +* `projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}` +* `{{project}}/{{location}}/{{name}}` +* `{{location}}/{{name}}` + + +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import EndpointAttachment using one of the formats above. For example: + +```tf +import { + id = "projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}}" + to = google_integration_connectors_endpoint_attachment.default +} +``` + +When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), EndpointAttachment can be imported using one of the formats above. For example: + +``` +$ terraform import google_integration_connectors_endpoint_attachment.default projects/{{project}}/locations/{{location}}/endpointAttachments/{{name}} +$ terraform import google_integration_connectors_endpoint_attachment.default {{project}}/{{location}}/{{name}} +$ terraform import google_integration_connectors_endpoint_attachment.default {{location}}/{{name}} +``` + +## User Project Overrides + +This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).