Skip to content

Commit c3d07a5

Browse files
authored
PLT-1913: Added support for EKS cloud config day 2 operations (#655)
1 parent 4b2b6a0 commit c3d07a5

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/hashicorp/terraform-plugin-docs v0.16.0
1414
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
1515
github.com/robfig/cron v1.2.0
16-
github.com/spectrocloud/palette-sdk-go v0.0.0-20250813031623-91ef23e78e8f
16+
github.com/spectrocloud/palette-sdk-go v0.0.0-20250829121241-06ad6c5fc7b1
1717
github.com/stretchr/testify v1.10.0
1818
gopkg.in/yaml.v3 v3.0.1
1919
gotest.tools v2.2.0+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
598598
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
599599
github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0=
600600
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
601-
github.com/spectrocloud/palette-sdk-go v0.0.0-20250813031623-91ef23e78e8f h1:KAEMjdoWEQ9FlHIVybcLDILngTmuhD7BqsNve4z8W5E=
602-
github.com/spectrocloud/palette-sdk-go v0.0.0-20250813031623-91ef23e78e8f/go.mod h1:wIt8g7I7cmcQvTo5ktwhSF0/bWq6uRdxGBs9dwTpleU=
601+
github.com/spectrocloud/palette-sdk-go v0.0.0-20250829121241-06ad6c5fc7b1 h1:OI305NgUmRfuVnKyaHGMbs42dYsEUHqUk0vHIWPukas=
602+
github.com/spectrocloud/palette-sdk-go v0.0.0-20250829121241-06ad6c5fc7b1/go.mod h1:wIt8g7I7cmcQvTo5ktwhSF0/bWq6uRdxGBs9dwTpleU=
603603
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
604604
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
605605
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=

spectrocloud/resource_cluster_eks.go

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ func resourceClusterEks() *schema.Resource {
145145
},
146146
"cloud_config": {
147147
Type: schema.TypeList,
148-
ForceNew: true,
149148
Required: true,
150149
MaxItems: 1,
151150
Description: "The AWS environment configuration settings such as network parameters and encryption parameters that apply to this cluster.",
@@ -200,7 +199,6 @@ func resourceClusterEks() *schema.Resource {
200199
"public_access_cidrs": {
201200
Type: schema.TypeSet,
202201
Optional: true,
203-
ForceNew: true,
204202
Set: schema.HashString,
205203
Description: "List of CIDR blocks that define the allowed public access to the resource. Requests originating from addresses within these CIDR blocks will be permitted to access the resource. All other addresses will be denied access.",
206204
Elem: &schema.Schema{
@@ -210,7 +208,6 @@ func resourceClusterEks() *schema.Resource {
210208
"private_access_cidrs": {
211209
Type: schema.TypeSet,
212210
Optional: true,
213-
ForceNew: true,
214211
Set: schema.HashString,
215212
Description: "List of CIDR blocks that define the allowed private access to the resource. Only requests originating from addresses within these CIDR blocks will be permitted to access the resource.",
216213
Elem: &schema.Schema{
@@ -511,6 +508,7 @@ func flattenClusterConfigsEKS(cloudConfig *models.V1EksCloudConfig) interface{}
511508
if pool.Name == "cp-pool" {
512509
ret["az_subnets"] = pool.SubnetIds
513510
}
511+
514512
}
515513

516514
if cloudConfig.Spec.ClusterConfig.EncryptionConfig != nil && cloudConfig.Spec.ClusterConfig.EncryptionConfig.IsEnabled {
@@ -659,6 +657,15 @@ func resourceClusterEksUpdate(ctx context.Context, d *schema.ResourceData, m int
659657
}
660658
cloudConfigId := d.Get("cloud_config_id").(string)
661659

660+
if d.HasChange("cloud_config") {
661+
cloudConfig := d.Get("cloud_config").([]interface{})[0].(map[string]interface{})
662+
cloudConfigEntity := toCloudConfigEks(cloudConfig)
663+
err := c.UpdateCloudConfigEks(cloudConfigId, cloudConfigEntity)
664+
if err != nil {
665+
return diag.FromErr(err)
666+
}
667+
}
668+
662669
CloudConfig, err := c.GetCloudConfigEks(cloudConfigId)
663670
if err != nil {
664671
return diag.FromErr(err)
@@ -830,6 +837,7 @@ func toEksCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spectro
830837
cluster.Spec.CloudConfig.EndpointAccess = access
831838

832839
machinePoolConfigs := make([]*models.V1EksMachinePoolConfigEntity, 0)
840+
833841
// Following same logic as UI for setting up control plane for static cluster
834842
// Only add cp-pool for dynamic cluster provisioning when az_subnets is not empty and has more than one element
835843
if cloudConfig["az_subnets"] != nil && len(cloudConfig["az_subnets"].(map[string]interface{})) > 0 {
@@ -842,6 +850,7 @@ func toEksCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spectro
842850
}
843851
machinePoolConfigs = append(machinePoolConfigs, toMachinePoolEks(cpPool))
844852
}
853+
845854
for _, machinePool := range d.Get("machine_pool").([]interface{}) {
846855
mp := toMachinePoolEks(machinePool)
847856
machinePoolConfigs = append(machinePoolConfigs, mp)
@@ -1050,3 +1059,55 @@ func toFargateProfileEks(fargateProfile interface{}) *models.V1FargateProfile {
10501059

10511060
return f
10521061
}
1062+
1063+
func toCloudConfigEks(cloudConfig map[string]interface{}) *models.V1EksCloudClusterConfigEntity {
1064+
var encryptionConfig *models.V1EncryptionConfig
1065+
if cloudConfig["encryption_config_arn"] != nil && cloudConfig["encryption_config_arn"].(string) != "" {
1066+
encryptionConfig = &models.V1EncryptionConfig{
1067+
IsEnabled: true,
1068+
Provider: cloudConfig["encryption_config_arn"].(string),
1069+
}
1070+
}
1071+
1072+
access := &models.V1EksClusterConfigEndpointAccess{}
1073+
switch cloudConfig["endpoint_access"].(string) {
1074+
case "public":
1075+
access.Public = true
1076+
access.Private = false
1077+
case "private":
1078+
access.Public = false
1079+
access.Private = true
1080+
case "private_and_public":
1081+
access.Public = true
1082+
access.Private = true
1083+
}
1084+
1085+
if cloudConfig["public_access_cidrs"] != nil {
1086+
cidrs := make([]string, 0)
1087+
for _, cidr := range cloudConfig["public_access_cidrs"].(*schema.Set).List() {
1088+
cidrs = append(cidrs, cidr.(string))
1089+
}
1090+
access.PublicCIDRs = cidrs
1091+
}
1092+
1093+
if cloudConfig["private_access_cidrs"] != nil {
1094+
cidrs := make([]string, 0)
1095+
for _, cidr := range cloudConfig["private_access_cidrs"].(*schema.Set).List() {
1096+
cidrs = append(cidrs, cidr.(string))
1097+
}
1098+
access.PrivateCIDRs = cidrs
1099+
}
1100+
1101+
clusterConfigEntity := &models.V1EksCloudClusterConfigEntity{
1102+
ClusterConfig: &models.V1EksClusterConfig{
1103+
BastionDisabled: true,
1104+
VpcID: cloudConfig["vpc_id"].(string),
1105+
Region: types.Ptr(cloudConfig["region"].(string)),
1106+
SSHKeyName: cloudConfig["ssh_key_name"].(string),
1107+
EncryptionConfig: encryptionConfig,
1108+
EndpointAccess: access,
1109+
},
1110+
}
1111+
1112+
return clusterConfigEntity
1113+
}

0 commit comments

Comments
 (0)