From c74bf1538fdee3f6066d1770fae0bde8664d56a7 Mon Sep 17 00:00:00 2001 From: Quentin Brosse Date: Fri, 22 Nov 2019 16:14:38 +0100 Subject: [PATCH] fix(instance): read server image during import (#337) --- scaleway/resource_instance_server.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scaleway/resource_instance_server.go b/scaleway/resource_instance_server.go index cc49165f4..5fbaaa79d 100644 --- a/scaleway/resource_instance_server.go +++ b/scaleway/resource_instance_server.go @@ -329,10 +329,9 @@ func resourceScalewayInstanceServerRead(d *schema.ResourceData, m interface{}) e state, err := serverStateFlatten(response.Server.State) if err != nil { return err - } else { - d.Set("state", state) } + d.Set("state", state) d.Set("zone", string(zone)) d.Set("name", response.Server.Name) d.Set("type", response.Server.CommercialType) @@ -341,9 +340,11 @@ func resourceScalewayInstanceServerRead(d *schema.ResourceData, m interface{}) e d.Set("enable_ipv6", response.Server.EnableIPv6) d.Set("disable_dynamic_ip", !response.Server.DynamicIPRequired) - // TODO: If image is a label, check that response.Server.Image.ID match the label. - // It could be useful if the user edit the image with another tool. - if response.Server.Image != nil && isUUID(d.Get("image").(string)) { + // Image could be empty in an import context. + image := d.Get("image").(string) + if response.Server.Image != nil && (image == "" || isUUID(image)) { + // TODO: If image is a label, check that response.Server.Image.ID match the label. + // It could be useful if the user edit the image with another tool. d.Set("image", response.Server.Image.ID) }