Skip to content

Commit

Permalink
Save generated credentialsID from update response in state before re-…
Browse files Browse the repository at this point in the history
…reading from server to avoid perpetual drift
  • Loading branch information
Tsonov committed Nov 14, 2024
1 parent d65b795 commit 0340737
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions castai/resource_aks_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func updateAKSClusterSettings(ctx context.Context, data *schema.ResourceData, cl
// Retries are required for newly created IAM resources to initialise on Azure side.
b := backoff.WithContext(backoff.WithMaxRetries(backoff.NewConstantBackOff(10*time.Second), 30), ctx)
var lastErr error
var credentialsID string
if err = backoff.RetryNotify(func() error {
response, err := client.ExternalClusterAPIUpdateClusterWithResponse(ctx, data.Id(), req)
if err != nil {
Expand All @@ -247,13 +248,7 @@ func updateAKSClusterSettings(ctx context.Context, data *schema.ResourceData, cl
return fmt.Errorf("error in update cluster response: %w", err)
}

//if err == nil {
// log.Printf("======after updating in API the credentials are (%v), existing (%v)", *response.JSON200.CredentialsId, data.Get(FieldClusterCredentialsId))
// err = data.Set(FieldClusterCredentialsId, *response.JSON200.CredentialsId)
// if err != nil {
// panic(err) // TODO
// }
//}
credentialsID = *response.JSON200.CredentialsId
return nil
}, b, func(err error, _ time.Duration) {
// Only store non-context errors so we can surface the last "real" error to the user at the end
Expand All @@ -278,5 +273,9 @@ func updateAKSClusterSettings(ctx context.Context, data *schema.ResourceData, cl
return fmt.Errorf("updating cluster configuration: %w", err)
}

// In case the update succeeded, we must update the state with the *generated* credentials_id before re-reading.
// This is because on update, the credentials_id always changes => read drift detection would see that and trigger infinite drift
err = data.Set(FieldClusterCredentialsId, credentialsID)

Check failure on line 278 in castai/resource_aks_cluster.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)

return nil
}

0 comments on commit 0340737

Please sign in to comment.