Skip to content

Commit

Permalink
Merge pull request #1126 from mjura/eks-desired-size
Browse files Browse the repository at this point in the history
Verify desired_size in EKSConfig NodeGroups
  • Loading branch information
mjura committed May 31, 2023
2 parents 0c6226a + 21788ec commit 24a48c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rancher2/resource_rancher2_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func resourceRancher2ClusterCreate(d *schema.ResourceData, meta interface{}) err
cluster.EnableClusterMonitoring = false
newCluster := &Cluster{}
if cluster.EKSConfig != nil && !cluster.EKSConfig.Imported {
if !checkClusterEKSConfigV2NodeGroupsDesiredSize(cluster) {
return fmt.Errorf("[ERROR] can't create %s EKS cluster with node group desired_size = 0", cluster.Name)
}
clusterStr, _ := interfaceToJSON(cluster)
clusterMap, _ := jsonToMapInterface(clusterStr)
clusterMap["eksConfig"] = fixClusterEKSConfigV2(d.Get("eks_config_v2").([]interface{}), structToMap(cluster.EKSConfig))
Expand Down
13 changes: 13 additions & 0 deletions rancher2/structure_cluster_eks_config_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,16 @@ func fixClusterEKSConfigV2NodeGroupsLaunchTemplate(p []interface{}) map[string]i

return obj
}

func checkClusterEKSConfigV2NodeGroupsDesiredSize(cluster *Cluster) bool {
if len(cluster.EKSConfig.NodeGroups) == 0 {
return false
}

for _, v := range cluster.EKSConfig.NodeGroups {
if *v.DesiredSize == 0 {
return false
}
}
return true
}

0 comments on commit 24a48c4

Please sign in to comment.