Skip to content

Commit

Permalink
add custom import file
Browse files Browse the repository at this point in the history
  • Loading branch information
wj-chen committed Oct 19, 2023
1 parent 2b01e76 commit b2d47a9
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
config := meta.(*transport_tpg.Config)
if err := tpgresource.ParseImportId([]string{
"^projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/capacityCommitments/(?P<capacity_commitment_id>[^/]+)$",
"^(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<capacity_commitment_id>[^/]+)$",
"^(?P<location>[^/]+)/(?P<capacity_commitment_id>[^/]+)$",
}, d, config); err != nil {
return nil, err
}

// Set name based on the components
if err := d.Set("name", "projects/{{project}}/locations/{{location}}/capacityCommitments/{{capacity_commitment_id}}"); err != nil {
return nil, fmt.Errorf("Error setting name: %s", err)
}

// Replace import id for the resource id
id, err := tpgresource.ReplaceVars(d, config, d.Get("name").(string))
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return []*schema.ResourceData{d}, nil

0 comments on commit b2d47a9

Please sign in to comment.