Skip to content

Commit 474ec55

Browse files
committed
Don't set empty values in the state unless they have changed
If values are optional and we set them to the empty-value, terraform interprets this as a change and attempts an update. As we never set these value in the state (as they are optional and not provided), this means that terraform attempts and update every single time. Fix by comparing values, and only updating the state if they are different.
1 parent 094d97b commit 474ec55

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

internal/provider/service_account_resource.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,24 @@ func (r *serviceAccountResource) Read(ctx context.Context, req resource.ReadRequ
206206
state.ID = types.StringValue(sa.ID)
207207
state.Name = types.StringValue(sa.Name)
208208
state.Owner = types.StringValue(sa.Owner)
209-
state.PublicKey = types.StringValue(sa.PublicKey)
210-
state.CredentialLifetime = types.Int32Value(sa.CredentialLifetime)
209+
if sa.PublicKey != state.PublicKey.ValueString() {
210+
state.PublicKey = types.StringValue(sa.PublicKey)
211+
}
212+
if sa.CredentialLifetime != state.CredentialLifetime.ValueInt32() {
213+
state.CredentialLifetime = types.Int32Value(sa.CredentialLifetime)
214+
}
215+
if sa.JwksURI != state.JwksURI.ValueString() {
216+
state.JwksURI = types.StringValue(sa.JwksURI)
217+
}
218+
if sa.IssuerURL != state.IssuerURL.ValueString() {
219+
state.IssuerURL = types.StringValue(sa.IssuerURL)
220+
}
221+
if sa.Audience != state.Audience.ValueString() {
222+
state.Audience = types.StringValue(sa.Audience)
223+
}
224+
if sa.Subject != state.Subject.ValueString() {
225+
state.Subject = types.StringValue(sa.Subject)
226+
}
211227

212228
scopes := []types.String{}
213229
for _, v := range sa.Scopes {

0 commit comments

Comments
 (0)