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 #8768

Merged
merged 3 commits into from
Sep 6, 2023
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
7 changes: 4 additions & 3 deletions mmv1/products/bigquerydatatransfer/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: templates/terraform/constants/bigquery_data_transfer.go.erb
decoder: templates/terraform/decoders/bigquery_data_transfer.go.erb
encoder: templates/terraform/encoders/bigquery_data_transfer.go.erb
custom_import: templates/terraform/custom_import/self_link_as_name.erb
custom_import: templates/terraform/custom_import/bigquery_data_transfer_self_link_as_name_set_location.go.erb
post_create: templates/terraform/post_create/set_computed_name.erb
custom_diff: [
'sensitiveParamCustomizeDiff',
Expand Down Expand Up @@ -74,8 +74,9 @@ properties:
output: 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.
- !ruby/object:Api::Type::String
name: 'destinationDatasetId'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

config := meta.(*transport_tpg.Config)

// current import_formats can't import fields with forward slashes in their value
if err := tpgresource.ParseImportId([]string{"(?P<project>[^ ]+) (?P<name>[^ ]+)", "(?P<name>[^ ]+)"}, d, config); err != nil {
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