Skip to content

Commit

Permalink
Merge pull request #343 from mergenci/external-client-check-lateiniti…
Browse files Browse the repository at this point in the history
…alize-management-policy

Check LateInitialize management policy in SDKv2 external client
  • Loading branch information
ulucinar authored Feb 14, 2024
2 parents 66ff8b2 + 1ed1df0 commit f6a1a0d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/controller/external_tfpluginsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
tf "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/crossplane/upjet/pkg/config"
Expand Down Expand Up @@ -522,9 +523,14 @@ func (n *terraformPluginSDKExternal) Observe(ctx context.Context, mg xpresource.
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "cannot marshal the attributes of the new state for late-initialization")
}
specUpdateRequired, err = mg.(resource.Terraformed).LateInitialize(buff)
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "cannot late-initialize the managed resource")

policySet := sets.New[xpv1.ManagementAction](mg.(resource.Terraformed).GetManagementPolicies()...)
policyHasLateInit := policySet.HasAny(xpv1.ManagementActionLateInitialize, xpv1.ManagementActionAll)
if policyHasLateInit {
specUpdateRequired, err = mg.(resource.Terraformed).LateInitialize(buff)
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "cannot late-initialize the managed resource")
}
}

err = mg.(resource.Terraformed).SetObservation(stateValueMap)
Expand Down

0 comments on commit f6a1a0d

Please sign in to comment.