Skip to content

Commit

Permalink
Support GCP auth backend role import
Browse files Browse the repository at this point in the history
  • Loading branch information
julianvmodesto committed Aug 27, 2019
1 parent ff85da1 commit cef97aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions vault/resource_gcp_auth_backend_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func gcpAuthBackendRoleResource() *schema.Resource {
Update: gcpAuthResourceUpdate,
Read: gcpAuthResourceRead,
Delete: gcpAuthResourceDelete,
Exists: gcpAuthResourceExists,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: fields,
}
}
Expand Down Expand Up @@ -367,3 +371,17 @@ func gcpAuthResourceDelete(d *schema.ResourceData, meta interface{}) error {

return nil
}

func gcpAuthResourceExists(d *schema.ResourceData, meta interface{}) (bool, error) {
client := meta.(*api.Client)
path := d.Id()

log.Printf("[DEBUG] Checking if gcp auth role %q exists", path)
resp, err := client.Logical().Read(path)
if err != nil {
return true, fmt.Errorf("error checking for existence of gcp auth resource config %q: %s", path, err)
}
log.Printf("[DEBUG] Checked if gcp auth role %q exists", path)

return resp != nil, nil
}
5 changes: 5 additions & 0 deletions vault/resource_gcp_auth_backend_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func TestGCPAuthBackendRole_basic(t *testing.T) {
"token_policies.#", "0"),
),
},
{
ResourceName: name,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down

0 comments on commit cef97aa

Please sign in to comment.