Skip to content

Commit

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

* 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
  • Loading branch information
nat-henderson authored Nov 30, 2020
1 parent a1eff96 commit 70e2ea3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions products/datacatalog/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
required: false
default_from_api: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/set_id_name_with_slashes.go.erb
custom_import: templates/terraform/custom_import/extract_taxonomy.go.erb
PolicyTag: !ruby/object:Overrides::Terraform::ResourceOverride
import_format: ["{{name}}"]
examples:
Expand All @@ -218,7 +218,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
vars:
taxonomy_display_name: "taxonomy_display_name"
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/set_id_name_with_slashes.go.erb
custom_import: templates/terraform/custom_import/extract_taxonomy.go.erb
# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
Expand Down
16 changes: 16 additions & 0 deletions templates/terraform/custom_import/extract_taxonomy.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
config := meta.(*Config)

if err := parseImportId([]string{
"(?P<taxonomy>projects/[^/]+/locations/[^/]+/taxonomies/[^/]+)/policyTags/(?P<name>.+)"}, d, config); err != nil {
return nil, err
}

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)
}
d.SetId(name)
return []*schema.ResourceData{d}, nil

0 comments on commit 70e2ea3

Please sign in to comment.