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 <[email protected]>
  • Loading branch information
ulucinar committed Dec 21, 2023
1 parent 962f619 commit d74b613
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 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 @@ -605,7 +605,7 @@ func (n *noForkExternal) Create(ctx context.Context, mg xpresource.Managed) (man
if _, err := n.setExternalName(mg, newState); err != nil {
return managed.ExternalCreation{}, errors.Wrapf(err, "failed to set the external-name of the managed resource during create")
}
stateValueMap, err := n.fromInstanceStateToJSONMap(newState)
stateValueMap, _, err := n.fromInstanceStateToJSONMap(newState)
if err != nil {
return managed.ExternalCreation{}, err
}
Expand Down Expand Up @@ -656,7 +656,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 @@ -687,15 +687,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 d74b613

Please sign in to comment.