Skip to content

Commit

Permalink
Fix import of bigquery transfer config location (GoogleCloudPlatform#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
obada-ab authored and simonebruzzechesse committed Sep 7, 2023
1 parent 097a65b commit 32971ff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
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

0 comments on commit 32971ff

Please sign in to comment.