From cd7ec9306c526f3fb338763109905c7a40acbe9a Mon Sep 17 00:00:00 2001 From: jbristowe Date: Mon, 15 Mar 2021 10:35:02 +1000 Subject: [PATCH] Refactoring --- octopusdeploy/resource_variable.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/octopusdeploy/resource_variable.go b/octopusdeploy/resource_variable.go index a772402a1..c089fcb53 100644 --- a/octopusdeploy/resource_variable.go +++ b/octopusdeploy/resource_variable.go @@ -18,9 +18,7 @@ func resourceVariable() *schema.Resource { return &schema.Resource{ CreateContext: resourceVariableCreate, DeleteContext: resourceVariableDelete, - Importer: &schema.ResourceImporter{ - State: resourceVariableImport, - }, + Importer: &schema.ResourceImporter{State: resourceVariableImport}, ReadContext: resourceVariableRead, Schema: getVariableSchema(), UpdateContext: resourceVariableUpdate, @@ -50,24 +48,17 @@ func resourceVariableRead(ctx context.Context, d *schema.ResourceData, m interfa if err != nil { apiError := err.(*octopusdeploy.APIError) if apiError.StatusCode == 404 { + log.Printf("[INFO] variable (%s) not found; deleting from state", d.Id()) d.SetId("") return nil } return diag.FromErr(err) } - d.Set("name", variable.Name) - d.Set("type", variable.Type) - - isSensitive := d.Get("is_sensitive").(bool) - if isSensitive { - d.Set("value", nil) - } else { - d.Set("value", variable.Value) + if err := setVariable(ctx, d, variable); err != nil { + return diag.FromErr(err) } - d.Set("description", variable.Description) - log.Printf("[INFO] variable read (%s)", d.Id()) return nil }