Skip to content

Commit

Permalink
Return the cty.Value of InstanceState from noForkExternal.fromInstanc…
Browse files Browse the repository at this point in the history
…eStateToJSONMap

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
  • Loading branch information
ulucinar committed Dec 22, 2023
1 parent b15649b commit 74159f8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/controller/external_nofork.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (n *noForkExternal) Observe(ctx context.Context, mg xpresource.Managed) (ma
addTTR(mg)
}
mg.SetConditions(xpv1.Available())
stateValueMap, err := n.fromInstanceStateToJSONMap(newState)
stateValueMap, _, err := n.fromInstanceStateToJSONMap(newState)
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "cannot convert instance state to JSON map")
}
Expand Down Expand Up @@ -601,12 +601,12 @@ func (n *noForkExternal) Create(ctx context.Context, mg xpresource.Managed) (man
}
n.opTracker.SetTfState(newState)

stateValueMap, err := n.fromInstanceStateToJSONMap(newState)
stateValueMap, _, err := n.fromInstanceStateToJSONMap(newState)
if err != nil {
return managed.ExternalCreation{}, errors.Wrap(err, "failed to convert instance state to map")
}
if _, err := n.setExternalName(mg, stateValueMap); err != nil {
return managed.ExternalCreation{}, errors.Wrapf(err, "failed to set the external-name of the managed resource during create")
return managed.ExternalCreation{}, errors.Wrap(err, "failed to set the external-name of the managed resource during create")
}
err = mg.(resource.Terraformed).SetObservation(stateValueMap)
if err != nil {
Expand Down Expand Up @@ -655,7 +655,7 @@ func (n *noForkExternal) Update(ctx context.Context, mg xpresource.Managed) (man
}
n.opTracker.SetTfState(newState)

stateValueMap, err := n.fromInstanceStateToJSONMap(newState)
stateValueMap, _, err := n.fromInstanceStateToJSONMap(newState)
if err != nil {
return managed.ExternalUpdate{}, err
}
Expand Down Expand Up @@ -686,15 +686,15 @@ func (n *noForkExternal) Delete(ctx context.Context, _ xpresource.Managed) error
return nil
}

func (n *noForkExternal) fromInstanceStateToJSONMap(newState *tf.InstanceState) (map[string]interface{}, error) {
func (n *noForkExternal) fromInstanceStateToJSONMap(newState *tf.InstanceState) (map[string]interface{}, cty.Value, error) {
impliedType := n.config.TerraformResource.CoreConfigSchema().ImpliedType()
attrsAsCtyValue, err := newState.AttrsAsObjectValue(impliedType)
if err != nil {
return nil, errors.Wrap(err, "could not convert attrs to cty value")
return nil, cty.NilVal, errors.Wrap(err, "could not convert attrs to cty value")
}
stateValueMap, err := schema.StateValueToJSONMap(attrsAsCtyValue, impliedType)
if err != nil {
return nil, errors.Wrap(err, "could not convert instance state value to JSON")
return nil, cty.NilVal, errors.Wrap(err, "could not convert instance state value to JSON")
}
return stateValueMap, nil
return stateValueMap, attrsAsCtyValue, nil
}

0 comments on commit 74159f8

Please sign in to comment.