Skip to content

Commit

Permalink
Set the RawPlan for a new terraform.InstanceState returned from an ob…
Browse files Browse the repository at this point in the history
…servation

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
  • Loading branch information
ulucinar committed Dec 22, 2023
1 parent 74159f8 commit f0de67a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/controller/external_nofork.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,21 @@ func (n *noForkExternal) Observe(ctx context.Context, mg xpresource.Managed) (ma
if diag != nil && diag.HasError() {
return managed.ExternalObservation{}, errors.Errorf("failed to observe the resource: %v", diag)
}
diffState := n.opTracker.GetTfState()
n.opTracker.SetTfState(newState) // TODO: missing RawConfig & RawPlan here...

resourceExists := newState != nil && newState.ID != ""
instanceDiff, err := n.getResourceDataDiff(mg.(resource.Terraformed), ctx, newState, resourceExists)

var stateValueMap map[string]any
if resourceExists {
jsonMap, stateValue, err := n.fromInstanceStateToJSONMap(newState)
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "cannot convert instance state to JSON map")
}
stateValueMap = jsonMap
newState.RawPlan = stateValue
diffState = newState
}
instanceDiff, err := n.getResourceDataDiff(mg.(resource.Terraformed), ctx, diffState, resourceExists)
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "cannot compute the instance diff")
}
Expand All @@ -496,10 +507,6 @@ func (n *noForkExternal) Observe(ctx context.Context, mg xpresource.Managed) (ma
addTTR(mg)
}
mg.SetConditions(xpv1.Available())
stateValueMap, _, err := n.fromInstanceStateToJSONMap(newState)
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "cannot convert instance state to JSON map")
}

buff, err := json.TFParser.Marshal(stateValueMap)
if err != nil {
Expand Down

0 comments on commit f0de67a

Please sign in to comment.