Skip to content

Commit

Permalink
Fix import of bigquery transfer config location (hashicorp#8768)
Browse files Browse the repository at this point in the history
* 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 <magic-modules@google.com>
  • Loading branch information
modular-magician committed Sep 6, 2023
1 parent c110b47 commit a9cc892
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
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

0 comments on commit a9cc892

Please sign in to comment.