@@ -610,6 +610,7 @@ func createClusterSpec(ctx context.Context, apiClient *openapiclient.APIClient,
610
610
clusterRegionInfo := []openapiclient.ClusterRegionInfo {}
611
611
totalNodes := 0
612
612
clusterType := plan .ClusterType .Value
613
+ isDefaultSet := false
613
614
for _ , regionInfo := range plan .ClusterRegionInfo {
614
615
regionNodes := regionInfo .NumNodes .Value
615
616
totalNodes += int (regionNodes )
@@ -694,7 +695,11 @@ func createClusterSpec(ctx context.Context, apiClient *openapiclient.APIClient,
694
695
info .SetIsAffinitized (regionInfo .IsPreferred .Value )
695
696
}
696
697
if ! regionInfo .IsDefault .IsUnknown () && ! regionInfo .IsDefault .IsNull () {
698
+ if isDefaultSet {
699
+ return nil , false , "Cluster must have exactly one default region."
700
+ }
697
701
info .SetIsDefault (regionInfo .IsDefault .Value )
702
+ isDefaultSet = true
698
703
}
699
704
clusterRegionInfo = append (clusterRegionInfo , info )
700
705
}
@@ -2013,7 +2018,6 @@ func (r resourceCluster) Update(ctx context.Context, req tfsdk.UpdateResourceReq
2013
2018
return
2014
2019
}
2015
2020
clusterSpec .ClusterInfo .SetVersion (int32 (clusterVersion ))
2016
-
2017
2021
_ , response , err := apiClient .ClusterApi .EditCluster (context .Background (), accountId , projectId , clusterId ).ClusterSpec (* clusterSpec ).Execute ()
2018
2022
if err != nil {
2019
2023
errMsg := getErrorMessage (response , err )
@@ -2041,6 +2045,7 @@ func (r resourceCluster) Update(ctx context.Context, req tfsdk.UpdateResourceReq
2041
2045
// Something similar will happen if changing the backup schedule or the CMK spec.
2042
2046
retries := 0
2043
2047
readClusterRetries := 0
2048
+ checkNewTaskSpawned := true
2044
2049
retryPolicy := retry .NewConstant (10 * time .Second )
2045
2050
retryPolicy = retry .WithMaxDuration (3600 * time .Second , retryPolicy )
2046
2051
err = retry .Do (ctx , retryPolicy , func (ctx context.Context ) error {
@@ -2049,12 +2054,6 @@ func (r resourceCluster) Update(ctx context.Context, req tfsdk.UpdateResourceReq
2049
2054
tflog .Info (ctx , "Cluster edit operation in progress, state: " + asState )
2050
2055
2051
2056
if readInfoOK {
2052
- if asState == string (openapiclient .TASKACTIONSTATEENUM_SUCCEEDED ) {
2053
- return nil
2054
- }
2055
- if asState == string (openapiclient .TASKACTIONSTATEENUM_FAILED ) {
2056
- return ErrFailedTask
2057
- }
2058
2057
if asState == "TASK_NOT_FOUND" {
2059
2058
// We try for a minute waiting for the tasks to be spawned. If edit cluster responded with a success
2060
2059
// without creating a task for about a minute, we can safely assume that a task is not required to be spawned.
@@ -2068,6 +2067,24 @@ func (r resourceCluster) Update(ctx context.Context, req tfsdk.UpdateResourceReq
2068
2067
return nil
2069
2068
}
2070
2069
}
2070
+ // There are cases this code flow checks for the state of previously spawned tasks instead of checking for new tasks.
2071
+ // Hence, we check whether a new task is spawned.
2072
+ if checkNewTaskSpawned {
2073
+ if asState == string (openapiclient .TASKACTIONSTATEENUM_IN_PROGRESS ) {
2074
+ checkNewTaskSpawned = false
2075
+ return retry .RetryableError (errors .New ("Cluster edit operation in progress" ))
2076
+ } else {
2077
+ tflog .Info (ctx , "Cluster edit task not found, the change would not have required a task creation" )
2078
+ return nil
2079
+ }
2080
+ }
2081
+ if asState == string (openapiclient .TASKACTIONSTATEENUM_SUCCEEDED ) {
2082
+ return nil
2083
+ }
2084
+ if asState == string (openapiclient .TASKACTIONSTATEENUM_FAILED ) {
2085
+ return ErrFailedTask
2086
+ }
2087
+
2071
2088
} else {
2072
2089
return handleReadFailureWithRetries (ctx , & readClusterRetries , 2 , message )
2073
2090
}
0 commit comments