Skip to content

Commit 45946b5

Browse files
Removed unnecessary post_create template for colab runtime template (#13957) (#22803)
[upstream:fd910977cf24595d2c04e3f0a369a82c79fdb8f8] Signed-off-by: Modular Magician <[email protected]>
1 parent ac61c1d commit 45946b5

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

google/services/colab/resource_colab_runtime_template.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -482,26 +482,32 @@ func resourceColabRuntimeTemplateCreate(d *schema.ResourceData, meta interface{}
482482
}
483483
d.SetId(id)
484484

485-
err = ColabOperationWaitTime(
486-
config, res, project, "Creating RuntimeTemplate", userAgent,
485+
// Use the resource in the operation response to populate
486+
// identity fields and d.Id() before read
487+
var opRes map[string]interface{}
488+
err = ColabOperationWaitTimeWithResponse(
489+
config, res, &opRes, project, "Creating RuntimeTemplate", userAgent,
487490
d.Timeout(schema.TimeoutCreate))
488-
489491
if err != nil {
490492
// The resource didn't actually create
491493
d.SetId("")
494+
492495
return fmt.Errorf("Error waiting to create RuntimeTemplate: %s", err)
493496
}
494497

495-
// The operation for this resource contains the generated name that we need
496-
// in order to perform a READ. We need to access the object inside of it as
497-
// a map[string]interface, so let's do that.
498+
// name is set by API when unset
499+
if tpgresource.IsEmptyValue(reflect.ValueOf(d.Get("name"))) {
500+
if err := d.Set("name", flattenColabRuntimeTemplateName(opRes["name"], d, config)); err != nil {
501+
return fmt.Errorf(`Error setting computed identity field "name": %s`, err)
502+
}
503+
}
498504

499-
resp := res["response"].(map[string]interface{})
500-
name := tpgresource.GetResourceNameFromSelfLink(resp["name"].(string))
501-
log.Printf("[DEBUG] Setting resource name to %s", name)
502-
if err := d.Set("name", name); err != nil {
503-
return fmt.Errorf("Error setting name: %s", err)
505+
// This may have caused the ID to update - update it if so.
506+
id, err = tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/notebookRuntimeTemplates/{{name}}")
507+
if err != nil {
508+
return fmt.Errorf("Error constructing id: %s", err)
504509
}
510+
d.SetId(id)
505511

506512
log.Printf("[DEBUG] Finished creating RuntimeTemplate %q: %#v", d.Id(), res)
507513

0 commit comments

Comments
 (0)