From 3e4649fbc0d8432a70f156c3ae50e0a00a267cd7 Mon Sep 17 00:00:00 2001 From: Huy Nguyen <162080607+HuyPhanNguyen@users.noreply.github.com> Date: Thu, 12 Sep 2024 19:38:34 +1000 Subject: [PATCH] bugfix/sc-92561 issue with variable space_id (#781) --- octopusdeploy_framework/resource_variable.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/octopusdeploy_framework/resource_variable.go b/octopusdeploy_framework/resource_variable.go index dd31c49f..ea5baed8 100644 --- a/octopusdeploy_framework/resource_variable.go +++ b/octopusdeploy_framework/resource_variable.go @@ -125,15 +125,20 @@ func (r *variableTypeResource) Read(ctx context.Context, req resource.ReadReques } variable, err := variables.GetByID(r.Config.Client, data.SpaceID.ValueString(), variableOwnerID.ValueString(), data.ID.ValueString()) + + // API don't return SpaceID with the variable, so we need to manually set it here from the state + variable.SpaceID = data.SpaceID.ValueString() if err != nil { if err := errors.ProcessApiErrorV2(ctx, resp, data, err, schemas.VariableResourceDescription); err != nil { resp.Diagnostics.AddError("unable to load variable", err.Error()) } return } - - tflog.Info(ctx, fmt.Sprintf("variable read (%s)", data.ID)) + tflog.Info(ctx, fmt.Sprintf("Read variable: %+v", variable)) mapVariableToState(&data, variable) + + tflog.Info(ctx, fmt.Sprintf("SpaceID after mapping: %s", data.SpaceID.ValueString())) + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }