Skip to content

Commit

Permalink
private state only accepts JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu committed Nov 13, 2024
1 parent ac6dbc7 commit 1ab4943
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions internal/services/azapi_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
)

const PrivateStateKeyCreateMode = "create_mode"
const FlagMoveState = "move_state"

type AzapiResourceModel struct {
Expand Down Expand Up @@ -908,7 +907,7 @@ func (r *AzapiResource) Read(ctx context.Context, request resource.ReadRequest,
state.Body = payload
}

if v, _ := request.Private.GetKey(ctx, PrivateStateKeyCreateMode); v != nil && string(v) == FlagMoveState {
if v, _ := request.Private.GetKey(ctx, FlagMoveState); v != nil && string(v) == "true" {
payload, err := flattenBody(responseBody, id.ResourceDef)
if err != nil {
response.Diagnostics.AddError("Invalid body", err.Error())
Expand Down Expand Up @@ -1068,7 +1067,7 @@ func (r *AzapiResource) MoveState(ctx context.Context) []resource.StateMover {
state.ParentID = types.StringValue(id.ParentId)
state.Type = types.StringValue(fmt.Sprintf("%s@%s", id.AzureResourceType, id.ApiVersion))

response.TargetPrivate.SetKey(ctx, PrivateStateKeyCreateMode, []byte(FlagMoveState))
response.Diagnostics.Append(response.TargetPrivate.SetKey(ctx, FlagMoveState, []byte("true"))...)
response.Diagnostics.Append(response.TargetState.Set(ctx, state)...)
},
},
Expand Down

0 comments on commit 1ab4943

Please sign in to comment.