Skip to content

Commit

Permalink
Convert old import formats (using non-/) to use /. (#2638)
Browse files Browse the repository at this point in the history
* Convert old import formats (using non-/) to use /.
  • Loading branch information
nat-henderson authored and rileykarson committed Nov 13, 2019
1 parent 9ee652e commit 9381806
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func dataSourceGoogleFolderOrganizationPolicy() *schema.Resource {

func datasourceGoogleFolderOrganizationPolicyRead(d *schema.ResourceData, meta interface{}) error {

d.SetId(fmt.Sprintf("%s:%s", d.Get("folder"), d.Get("constraint")))
d.SetId(fmt.Sprintf("%s/%s", d.Get("folder"), d.Get("constraint")))

return resourceGoogleFolderOrganizationPolicyRead(d, meta)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func resourceFolderOrgPolicyImporter(d *schema.ResourceData, meta interface{}) (
config := meta.(*Config)

if err := parseImportId([]string{
"folders/(?P<folder>[^/]+):constraints/(?P<constraint>[^/]+)",
"(?P<folder>[^/]+):(?P<constraint>[^/]+)"},
"folders/(?P<folder>[^/]+)/constraints/(?P<constraint>[^/]+)",
"(?P<folder>[^/]+)/(?P<constraint>[^/]+)"},
d, config); err != nil {
return nil, err
}
Expand All @@ -59,7 +59,7 @@ func resourceFolderOrgPolicyImporter(d *schema.ResourceData, meta interface{}) (
}

func resourceGoogleFolderOrganizationPolicyCreate(d *schema.ResourceData, meta interface{}) error {
d.SetId(fmt.Sprintf("%s:%s", d.Get("folder"), d.Get("constraint")))
d.SetId(fmt.Sprintf("%s/%s", d.Get("folder"), d.Get("constraint")))

if isOrganizationPolicyUnset(d) {
return resourceGoogleFolderOrganizationPolicyDelete(d, meta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func resourceGoogleOrganizationPolicy() *schema.Resource {
}

func resourceGoogleOrganizationPolicyCreate(d *schema.ResourceData, meta interface{}) error {
d.SetId(fmt.Sprintf("%s:%s", d.Get("org_id"), d.Get("constraint").(string)))
d.SetId(fmt.Sprintf("%s/%s", d.Get("org_id"), d.Get("constraint").(string)))

if isOrganizationPolicyUnset(d) {
return resourceGoogleOrganizationPolicyDelete(d, meta)
Expand Down Expand Up @@ -224,9 +224,9 @@ func resourceGoogleOrganizationPolicyDelete(d *schema.ResourceData, meta interfa
}

func resourceGoogleOrganizationPolicyImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), ":")
parts := strings.SplitN(d.Id(), "/", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("Invalid id format. Expecting {org_id}:{constraint}, got '%s' instead.", d.Id())
return nil, fmt.Errorf("Invalid id format. Expecting {org_id}/{constraint}, got '%s' instead.", d.Id())
}

d.Set("org_id", parts[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,5 @@ exported:
BigQuery tables can be imported using the `project`, `dataset_id`, and `table_id`, e.g.

```
$ terraform import google_bigquery_table.default gcp-project:foo.bar
$ terraform import google_bigquery_table.default gcp-project/foo/bar
```
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ exported:
Folder organization policies can be imported using any of the follow formats:

```
$ terraform import google_folder_organization_policy.policy folders/folder-1234:constraints/serviceuser.services
$ terraform import google_folder_organization_policy.policy folder-1234:serviceuser.services
$ terraform import google_folder_organization_policy.policy folders/folder-1234/constraints/serviceuser.services
$ terraform import google_folder_organization_policy.policy folder-1234/serviceuser.services
```
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ exported:
Organization Policies can be imported using the `org_id` and the `constraint`, e.g.

```
$ terraform import google_organization_policy.services_policy 123456789:constraints/serviceuser.services
$ terraform import google_organization_policy.services_policy 123456789/constraints/serviceuser.services
```

It is all right if the constraint contains a slash, as in the example above.

0 comments on commit 9381806

Please sign in to comment.