Skip to content

Commit

Permalink
write a new custom import that can extract taxonomy and name both. (#…
Browse files Browse the repository at this point in the history
…4262) (#2744)

* write a new custom import that can extract taxonomy and name both.

* move custom import to subfolder.

* update because project and location are set in the parent actually

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Nov 30, 2020
1 parent c3a995a commit 90096cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/4262.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
datacatalog: fixed permadiff on import for tags with a taxonomy set in config.
```
8 changes: 5 additions & 3 deletions google-beta/resource_data_catalog_policy_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,14 @@ func resourceDataCatalogPolicyTagDelete(d *schema.ResourceData, meta interface{}
func resourceDataCatalogPolicyTagImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)

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

name := d.Get("name").(string)
originalName := d.Get("name").(string)
originalTaxonomy := d.Get("taxonomy").(string)
name := fmt.Sprintf("%s/policyTags/%s", originalTaxonomy, originalName)

if err := d.Set("name", name); err != nil {
return nil, fmt.Errorf("Error setting name: %s", err)
Expand Down
8 changes: 5 additions & 3 deletions google-beta/resource_data_catalog_taxonomy.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,14 @@ func resourceDataCatalogTaxonomyDelete(d *schema.ResourceData, meta interface{})
func resourceDataCatalogTaxonomyImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)

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

name := d.Get("name").(string)
originalName := d.Get("name").(string)
originalTaxonomy := d.Get("taxonomy").(string)
name := fmt.Sprintf("%s/policyTags/%s", originalTaxonomy, originalName)

if err := d.Set("name", name); err != nil {
return nil, fmt.Errorf("Error setting name: %s", err)
Expand Down

0 comments on commit 90096cd

Please sign in to comment.