@@ -149,6 +149,10 @@ func gcpAuthBackendRoleResource() *schema.Resource {
149149 Update : gcpAuthResourceUpdate ,
150150 Read : gcpAuthResourceRead ,
151151 Delete : gcpAuthResourceDelete ,
152+ Exists : gcpAuthResourceExists ,
153+ Importer : & schema.ResourceImporter {
154+ State : schema .ImportStatePassthrough ,
155+ },
152156 Schema : fields ,
153157 }
154158}
@@ -278,6 +282,17 @@ func gcpAuthResourceRead(d *schema.ResourceData, meta interface{}) error {
278282 return nil
279283 }
280284
285+ backend , err := gcpAuthResourceBackendFromPath (path )
286+ if err != nil {
287+ return fmt .Errorf ("invalid path %q for GCP auth backend role: %s" , path , err )
288+ }
289+ d .Set ("backend" , backend )
290+ role , err := gcpAuthResourceRoleFromPath (path )
291+ if err != nil {
292+ return fmt .Errorf ("invalid path %q for GCP auth backend role: %s" , path , err )
293+ }
294+ d .Set ("role" , role )
295+
281296 readTokenFields (d , resp )
282297
283298 // Check if the user is using the deprecated `policies`
@@ -367,3 +382,33 @@ func gcpAuthResourceDelete(d *schema.ResourceData, meta interface{}) error {
367382
368383 return nil
369384}
385+
386+ func gcpAuthResourceExists (d * schema.ResourceData , meta interface {}) (bool , error ) {
387+ client := meta .(* api.Client )
388+ path := d .Id ()
389+
390+ log .Printf ("[DEBUG] Checking if gcp auth role %q exists" , path )
391+ resp , err := client .Logical ().Read (path )
392+ if err != nil {
393+ return true , fmt .Errorf ("error checking for existence of gcp auth resource config %q: %s" , path , err )
394+ }
395+ log .Printf ("[DEBUG] Checked if gcp auth role %q exists" , path )
396+
397+ return resp != nil , nil
398+ }
399+
400+ func gcpAuthResourceBackendFromPath (path string ) (string , error ) {
401+ var parts = strings .Split (path , "/" )
402+ if len (parts ) != 4 {
403+ return "" , fmt .Errorf ("Expecdted 4 parts in path '%s'" , path )
404+ }
405+ return parts [1 ], nil
406+ }
407+
408+ func gcpAuthResourceRoleFromPath (path string ) (string , error ) {
409+ var parts = strings .Split (path , "/" )
410+ if len (parts ) != 4 {
411+ return "" , fmt .Errorf ("Expecdted 4 parts in path '%s'" , path )
412+ }
413+ return parts [3 ], nil
414+ }
0 commit comments