Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import of bigquery transfer config location #15734

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/8768.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
bigquerydatatransfer: fixed a bug when importing 'location' of 'google_bigquery_data_transfer_config'
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"log"
"reflect"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/bigquery_data_transfer_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down