Skip to content

Commit 82b7e07

Browse files
committed
internal/provider/sdkv2: support non-refresh apply in identity interceptor
Previously a non-refresh apply would result in the identity interceptor short circuiting for any resources with immutable identities, even if the existing identity was fully null. This change adds an additional check for fully null identity attributes, enabling cases where a non-refresh apply is executed immediately after upgrading to a provider version which newly supports resource identity for a given resource.
1 parent 5b9de4e commit 82b7e07

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

internal/provider/sdkv2/identity_interceptor.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (r identityInterceptor) run(ctx context.Context, opts crudInterceptorOption
2929
case After:
3030
switch why {
3131
case Create, Read, Update:
32-
if why == Update && !(r.identitySpec.IsMutable && r.identitySpec.IsSetOnUpdate) {
32+
if why == Update && !(r.identitySpec.IsMutable && r.identitySpec.IsSetOnUpdate) && !identityIsFullyNull(d, r.identitySpec) {
3333
break
3434
}
3535
if d.Id() == "" {
@@ -68,6 +68,24 @@ func (r identityInterceptor) run(ctx context.Context, opts crudInterceptorOption
6868
return diags
6969
}
7070

71+
// identityIsFullyNull returns true if a resource supports identity and
72+
// all attributes are set to null values
73+
func identityIsFullyNull(d schemaResourceData, identitySpec *inttypes.Identity) bool {
74+
identity, err := d.Identity()
75+
if err != nil {
76+
return false
77+
}
78+
79+
for _, attr := range identitySpec.Attributes {
80+
value := identity.Get(attr.Name())
81+
if value != "" {
82+
return false
83+
}
84+
}
85+
86+
return true
87+
}
88+
7189
func getAttributeOk(d schemaResourceData, name string) (string, bool) {
7290
if name == "id" {
7391
return d.Id(), true
@@ -82,16 +100,12 @@ func getAttributeOk(d schemaResourceData, name string) (string, bool) {
82100
func newIdentityInterceptor(identitySpec *inttypes.Identity) interceptorInvocation {
83101
interceptor := interceptorInvocation{
84102
when: After,
85-
why: Create | Read,
103+
why: Create | Read | Update,
86104
interceptor: identityInterceptor{
87105
identitySpec: identitySpec,
88106
},
89107
}
90108

91-
if identitySpec.IsMutable && identitySpec.IsSetOnUpdate {
92-
interceptor.why |= Update
93-
}
94-
95109
return interceptor
96110
}
97111

0 commit comments

Comments
 (0)