Skip to content

Commit

Permalink
Use custom import for datacatalog taxonomy and policy_tag (#4203) (#2694
Browse files Browse the repository at this point in the history
)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Nov 9, 2020
1 parent 6062073 commit 05b8a19
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .changelog/4203.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
datacatalog: fixed an issue in `google_data_catalog_taxonomy` and `google_data_catalog_policy_tag` where importing would fail
```
17 changes: 8 additions & 9 deletions google-beta/resource_data_catalog_policy_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,19 +295,18 @@ func resourceDataCatalogPolicyTagDelete(d *schema.ResourceData, meta interface{}

func resourceDataCatalogPolicyTagImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
if err := parseImportId([]string{
"(?P<name>[^/]+)",
}, d, config); err != nil {

// current import_formats can't import fields with forward slashes in their value
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}

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

if err := d.Set("name", name); err != nil {
return nil, fmt.Errorf("Error setting name: %s", err)
}
d.SetId(name)
return []*schema.ResourceData{d}, nil
}

Expand Down
17 changes: 8 additions & 9 deletions google-beta/resource_data_catalog_taxonomy.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,19 +323,18 @@ func resourceDataCatalogTaxonomyDelete(d *schema.ResourceData, meta interface{})

func resourceDataCatalogTaxonomyImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
if err := parseImportId([]string{
"(?P<name>[^/]+)",
}, d, config); err != nil {

// current import_formats can't import fields with forward slashes in their value
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}

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

if err := d.Set("name", name); err != nil {
return nil, fmt.Errorf("Error setting name: %s", err)
}
d.SetId(name)
return []*schema.ResourceData{d}, nil
}

Expand Down

0 comments on commit 05b8a19

Please sign in to comment.