From a9cc892ff61b5e6c3e993d4fe3ea3f019d0ba1a8 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 6 Sep 2023 13:05:50 +0000 Subject: [PATCH] Fix import of bigquery transfer config location (#8768) * Fix import of bigquery transfer config location * Fix import of bigquery transfer config when name does not contain location * Fix indentation in bigquery_data_transfer_self_link_as_name_set_location.go.erb Signed-off-by: Modular Magician --- .changelog/8768.txt | 3 +++ .../resource_bigquery_data_transfer_config.go | 17 +++++++++++++++-- .../bigquery_data_transfer_config.html.markdown | 5 +++-- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 .changelog/8768.txt diff --git a/.changelog/8768.txt b/.changelog/8768.txt new file mode 100644 index 00000000000..98b1c992614 --- /dev/null +++ b/.changelog/8768.txt @@ -0,0 +1,3 @@ +```release-note:bug +bigquerydatatransfer: fixed a bug when importing 'location' of 'google_bigquery_data_transfer_config' +``` diff --git a/google/services/bigquerydatatransfer/resource_bigquery_data_transfer_config.go b/google/services/bigquerydatatransfer/resource_bigquery_data_transfer_config.go index e5c3cc8bdb8..408250605a8 100644 --- a/google/services/bigquerydatatransfer/resource_bigquery_data_transfer_config.go +++ b/google/services/bigquerydatatransfer/resource_bigquery_data_transfer_config.go @@ -22,6 +22,7 @@ import ( "fmt" "log" "reflect" + "strings" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" @@ -271,8 +272,9 @@ requesting user calling this API has permissions to act as this service account. Type: schema.TypeString, Computed: true, Description: `The resource name of the transfer config. Transfer config names have the -form projects/{projectId}/locations/{location}/transferConfigs/{configId}. -Where configId is usually a uuid, but this is not required. +form projects/{projectId}/locations/{location}/transferConfigs/{configId} +or projects/{projectId}/transferConfigs/{configId}, +where configId is usually a uuid, but this is not required. The name is ignored when creating a transfer config.`, }, "project": { @@ -679,6 +681,17 @@ func resourceBigqueryDataTransferConfigImport(d *schema.ResourceData, meta inter return nil, err } + // import location if the name format follows: projects/{{project}}/locations/{{location}}/transferConfigs/{{config_id}} + name := d.Get("name").(string) + stringParts := strings.Split(name, "/") + if len(stringParts) == 6 { + if err := d.Set("location", stringParts[3]); err != nil { + return nil, fmt.Errorf("Error setting location: %s", err) + } + } else { + log.Printf("[INFO] Transfer config location not imported as it is not included in the name: %s", name) + } + return []*schema.ResourceData{d}, nil } diff --git a/website/docs/r/bigquery_data_transfer_config.html.markdown b/website/docs/r/bigquery_data_transfer_config.html.markdown index cb90f7b18aa..5afc3d4729c 100644 --- a/website/docs/r/bigquery_data_transfer_config.html.markdown +++ b/website/docs/r/bigquery_data_transfer_config.html.markdown @@ -209,8 +209,9 @@ In addition to the arguments listed above, the following computed attributes are * `name` - The resource name of the transfer config. Transfer config names have the - form projects/{projectId}/locations/{location}/transferConfigs/{configId}. - Where configId is usually a uuid, but this is not required. + form projects/{projectId}/locations/{location}/transferConfigs/{configId} + or projects/{projectId}/transferConfigs/{configId}, + where configId is usually a uuid, but this is not required. The name is ignored when creating a transfer config.