@@ -168,6 +168,11 @@ func resourceCluster() *schema.Resource {
168
168
Type : schema .TypeString ,
169
169
Computed : true ,
170
170
},
171
+ names .AttrDeletionProtection : {
172
+ Type : schema .TypeBool ,
173
+ Optional : true ,
174
+ Computed : true ,
175
+ },
171
176
"enabled_cluster_log_types" : {
172
177
Type : schema .TypeSet ,
173
178
Optional : true ,
@@ -511,7 +516,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta any
511
516
conn := meta .(* conns.AWSClient ).EKSClient (ctx )
512
517
513
518
name := d .Get (names .AttrName ).(string )
514
- input := & eks.CreateClusterInput {
519
+ input := eks.CreateClusterInput {
515
520
BootstrapSelfManagedAddons : aws .Bool (d .Get ("bootstrap_self_managed_addons" ).(bool )),
516
521
EncryptionConfig : expandEncryptionConfig (d .Get ("encryption_config" ).([]any )),
517
522
Logging : expandLogging (d .Get ("enabled_cluster_log_types" ).(* schema.Set )),
@@ -521,12 +526,16 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta any
521
526
Tags : getTagsIn (ctx ),
522
527
}
523
528
529
+ if v , ok := d .GetOk ("access_config" ); ok {
530
+ input .AccessConfig = expandCreateAccessConfigRequest (v .([]any ))
531
+ }
532
+
524
533
if v , ok := d .GetOk ("compute_config" ); ok {
525
534
input .ComputeConfig = expandComputeConfigRequest (v .([]any ))
526
535
}
527
536
528
- if v , ok := d .GetOk ("access_config" ); ok {
529
- input .AccessConfig = expandCreateAccessConfigRequest (v .([] any ))
537
+ if v , ok := d .GetOk (names . AttrDeletionProtection ); ok {
538
+ input .DeletionProtection = aws . Bool (v .(bool ))
530
539
}
531
540
532
541
if v , ok := d .GetOk ("kubernetes_network_config" ); ok {
@@ -559,7 +568,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta any
559
568
560
569
outputRaw , err := tfresource .RetryWhen (ctx , propagationTimeout ,
561
570
func () (any , error ) {
562
- return conn .CreateCluster (ctx , input )
571
+ return conn .CreateCluster (ctx , & input )
563
572
},
564
573
func (err error ) (bool , error ) {
565
574
// InvalidParameterException: roleArn, arn:aws:iam::123456789012:role/XXX, does not exist
@@ -643,6 +652,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta any)
643
652
return sdkdiag .AppendErrorf (diags , "setting compute_config: %s" , err )
644
653
}
645
654
d .Set (names .AttrCreatedAt , cluster .CreatedAt .Format (time .RFC3339 ))
655
+ d .Set (names .AttrDeletionProtection , cluster .DeletionProtection )
646
656
if err := d .Set ("enabled_cluster_log_types" , flattenLogging (cluster .Logging )); err != nil {
647
657
return sdkdiag .AppendErrorf (diags , "setting enabled_cluster_log_types: %s" , err )
648
658
}
@@ -692,7 +702,7 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta any
692
702
693
703
// Do any version update first.
694
704
if d .HasChange (names .AttrVersion ) {
695
- input := & eks.UpdateClusterVersionInput {
705
+ input := eks.UpdateClusterVersionInput {
696
706
Name : aws .String (d .Id ()),
697
707
Version : aws .String (d .Get (names .AttrVersion ).(string )),
698
708
}
@@ -701,7 +711,7 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta any
701
711
input .Force = v .(bool )
702
712
}
703
713
704
- output , err := conn .UpdateClusterVersion (ctx , input )
714
+ output , err := conn .UpdateClusterVersion (ctx , & input )
705
715
706
716
if err != nil {
707
717
return sdkdiag .AppendErrorf (diags , "updating EKS Cluster (%s) version: %s" , d .Id (), err )
@@ -716,12 +726,12 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta any
716
726
717
727
if d .HasChange ("access_config" ) {
718
728
if v , ok := d .GetOk ("access_config" ); ok {
719
- input := & eks.UpdateClusterConfigInput {
729
+ input := eks.UpdateClusterConfigInput {
720
730
AccessConfig : expandUpdateAccessConfigRequest (v .([]any )),
721
731
Name : aws .String (d .Id ()),
722
732
}
723
733
724
- output , err := conn .UpdateClusterConfig (ctx , input )
734
+ output , err := conn .UpdateClusterConfig (ctx , & input )
725
735
726
736
if err != nil {
727
737
return sdkdiag .AppendErrorf (diags , "updating EKS Cluster (%s) access configuration: %s" , d .Id (), err )
@@ -741,15 +751,14 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta any
741
751
computeConfig := expandComputeConfigRequest (d .Get ("compute_config" ).([]any ))
742
752
kubernetesNetworkConfig := expandKubernetesNetworkConfigRequest (d .Get ("kubernetes_network_config" ).([]any ))
743
753
storageConfig := expandStorageConfigRequest (d .Get ("storage_config" ).([]any ))
744
-
745
- input := & eks.UpdateClusterConfigInput {
746
- Name : aws .String (d .Id ()),
754
+ input := eks.UpdateClusterConfigInput {
747
755
ComputeConfig : computeConfig ,
748
756
KubernetesNetworkConfig : kubernetesNetworkConfig ,
757
+ Name : aws .String (d .Id ()),
749
758
StorageConfig : storageConfig ,
750
759
}
751
760
752
- output , err := conn .UpdateClusterConfig (ctx , input )
761
+ output , err := conn .UpdateClusterConfig (ctx , & input )
753
762
754
763
if err != nil {
755
764
return sdkdiag .AppendErrorf (diags , "updating EKS Cluster (%s) compute config: %s" , d .Id (), err )
@@ -762,16 +771,20 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta any
762
771
}
763
772
}
764
773
765
- if d .HasChange ("encryption_config" ) {
766
- o , n := d .GetChange ("encryption_config" )
774
+ if d .HasChange (names .AttrDeletionProtection ) {
775
+ if err := updateClusterDeletionProtection (ctx , conn , d .Id (), d .Get (names .AttrDeletionProtection ).(bool ), d .Timeout (schema .TimeoutUpdate )); err != nil {
776
+ return sdkdiag .AppendFromErr (diags , err )
777
+ }
778
+ }
767
779
768
- if len (o .([]any )) == 0 && len (n .([]any )) == 1 {
769
- input := & eks.AssociateEncryptionConfigInput {
780
+ if d .HasChange ("encryption_config" ) {
781
+ if o , n := d .GetChange ("encryption_config" ); len (o .([]any )) == 0 && len (n .([]any )) == 1 {
782
+ input := eks.AssociateEncryptionConfigInput {
770
783
ClusterName : aws .String (d .Id ()),
771
784
EncryptionConfig : expandEncryptionConfig (d .Get ("encryption_config" ).([]any )),
772
785
}
773
786
774
- output , err := conn .AssociateEncryptionConfig (ctx , input )
787
+ output , err := conn .AssociateEncryptionConfig (ctx , & input )
775
788
776
789
if err != nil {
777
790
return sdkdiag .AppendErrorf (diags , "associating EKS Cluster (%s) encryption config: %s" , d .Id (), err )
@@ -786,12 +799,12 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta any
786
799
}
787
800
788
801
if d .HasChange ("enabled_cluster_log_types" ) {
789
- input := & eks.UpdateClusterConfigInput {
802
+ input := eks.UpdateClusterConfigInput {
790
803
Logging : expandLogging (d .Get ("enabled_cluster_log_types" ).(* schema.Set )),
791
804
Name : aws .String (d .Id ()),
792
805
}
793
806
794
- output , err := conn .UpdateClusterConfig (ctx , input )
807
+ output , err := conn .UpdateClusterConfig (ctx , & input )
795
808
796
809
if err != nil {
797
810
return sdkdiag .AppendErrorf (diags , "updating EKS Cluster (%s) logging: %s" , d .Id (), err )
@@ -805,12 +818,12 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta any
805
818
}
806
819
807
820
if d .HasChange ("upgrade_policy" ) {
808
- input := & eks.UpdateClusterConfigInput {
821
+ input := eks.UpdateClusterConfigInput {
809
822
Name : aws .String (d .Id ()),
810
823
UpgradePolicy : expandUpgradePolicy (d .Get ("upgrade_policy" ).([]any )),
811
824
}
812
825
813
- output , err := conn .UpdateClusterConfig (ctx , input )
826
+ output , err := conn .UpdateClusterConfig (ctx , & input )
814
827
815
828
if err != nil {
816
829
return sdkdiag .AppendErrorf (diags , "updating EKS Cluster (%s) upgrade policy: %s" , d .Id (), err )
@@ -824,7 +837,7 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta any
824
837
}
825
838
826
839
if d .HasChanges ("vpc_config.0.endpoint_private_access" , "vpc_config.0.endpoint_public_access" , "vpc_config.0.public_access_cidrs" ) {
827
- config := & types.VpcConfigRequest {
840
+ config := types.VpcConfigRequest {
828
841
EndpointPrivateAccess : aws .Bool (d .Get ("vpc_config.0.endpoint_private_access" ).(bool )),
829
842
EndpointPublicAccess : aws .Bool (d .Get ("vpc_config.0.endpoint_public_access" ).(bool )),
830
843
}
@@ -833,39 +846,39 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta any
833
846
config .PublicAccessCidrs = flex .ExpandStringValueSet (v .(* schema.Set ))
834
847
}
835
848
836
- if err := updateVPCConfig (ctx , conn , d .Id (), config , d .Timeout (schema .TimeoutUpdate )); err != nil {
849
+ if err := updateClusterVPCConfig (ctx , conn , d .Id (), & config , d .Timeout (schema .TimeoutUpdate )); err != nil {
837
850
return sdkdiag .AppendFromErr (diags , err )
838
851
}
839
852
}
840
853
841
854
// API only allows one type of update at at time.
842
855
if d .HasChange ("vpc_config.0.subnet_ids" ) {
843
- config := & types.VpcConfigRequest {
856
+ config := types.VpcConfigRequest {
844
857
SubnetIds : flex .ExpandStringValueSet (d .Get ("vpc_config.0.subnet_ids" ).(* schema.Set )),
845
858
}
846
859
847
- if err := updateVPCConfig (ctx , conn , d .Id (), config , d .Timeout (schema .TimeoutUpdate )); err != nil {
860
+ if err := updateClusterVPCConfig (ctx , conn , d .Id (), & config , d .Timeout (schema .TimeoutUpdate )); err != nil {
848
861
return sdkdiag .AppendFromErr (diags , err )
849
862
}
850
863
}
851
864
852
865
if d .HasChange ("vpc_config.0.security_group_ids" ) {
853
- config := & types.VpcConfigRequest {
866
+ config := types.VpcConfigRequest {
854
867
SecurityGroupIds : flex .ExpandStringValueSet (d .Get ("vpc_config.0.security_group_ids" ).(* schema.Set )),
855
868
}
856
869
857
- if err := updateVPCConfig (ctx , conn , d .Id (), config , d .Timeout (schema .TimeoutUpdate )); err != nil {
870
+ if err := updateClusterVPCConfig (ctx , conn , d .Id (), & config , d .Timeout (schema .TimeoutUpdate )); err != nil {
858
871
return sdkdiag .AppendFromErr (diags , err )
859
872
}
860
873
}
861
874
862
875
if d .HasChange ("zonal_shift_config" ) {
863
- input := & eks.UpdateClusterConfigInput {
876
+ input := eks.UpdateClusterConfigInput {
864
877
Name : aws .String (d .Id ()),
865
878
ZonalShiftConfig : expandZonalShiftConfig (d .Get ("zonal_shift_config" ).([]any )),
866
879
}
867
880
868
- output , err := conn .UpdateClusterConfig (ctx , input )
881
+ output , err := conn .UpdateClusterConfig (ctx , & input )
869
882
870
883
if err != nil {
871
884
return sdkdiag .AppendErrorf (diags , "updating EKS Cluster (%s) zonal shift config: %s" , d .Id (), err )
@@ -886,20 +899,19 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta any
886
899
887
900
conn := meta .(* conns.AWSClient ).EKSClient (ctx )
888
901
889
- input := & eks.DeleteClusterInput {
890
- Name : aws .String (d .Id ()),
891
- }
892
-
893
902
// If a cluster is scaling up due to load a delete request will fail
894
903
// This is a temporary workaround until EKS supports multiple parallel mutating operations
895
904
const (
896
905
timeout = 60 * time .Minute
897
906
)
898
907
log .Printf ("[DEBUG] Deleting EKS Cluster: %s" , d .Id ())
908
+ input := eks.DeleteClusterInput {
909
+ Name : aws .String (d .Id ()),
910
+ }
899
911
err := tfresource .Retry (ctx , timeout , func () * retry.RetryError {
900
912
var err error
901
913
902
- _ , err = conn .DeleteCluster (ctx , input )
914
+ _ , err = conn .DeleteCluster (ctx , & input )
903
915
904
916
if errs .IsAErrorMessageContains [* types.ResourceInUseException ](err , "in progress" ) {
905
917
return retry .RetryableError (err )
@@ -913,7 +925,7 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta any
913
925
}, tfresource .WithDelayRand (1 * time .Minute ), tfresource .WithPollInterval (30 * time .Second ))
914
926
915
927
if tfresource .TimedOut (err ) {
916
- _ , err = conn .DeleteCluster (ctx , input )
928
+ _ , err = conn .DeleteCluster (ctx , & input )
917
929
}
918
930
919
931
if errs.IsA [* types.ResourceNotFoundException ](err ) {
@@ -938,10 +950,14 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta any
938
950
}
939
951
940
952
func findClusterByName (ctx context.Context , conn * eks.Client , name string ) (* types.Cluster , error ) {
941
- input := & eks.DescribeClusterInput {
953
+ input := eks.DescribeClusterInput {
942
954
Name : aws .String (name ),
943
955
}
944
956
957
+ return findCluster (ctx , conn , & input )
958
+ }
959
+
960
+ func findCluster (ctx context.Context , conn * eks.Client , input * eks.DescribeClusterInput ) (* types.Cluster , error ) {
945
961
output , err := conn .DescribeCluster (ctx , input )
946
962
947
963
// Sometimes the EKS API returns the ResourceNotFound error in this form:
@@ -964,33 +980,58 @@ func findClusterByName(ctx context.Context, conn *eks.Client, name string) (*typ
964
980
return output .Cluster , nil
965
981
}
966
982
967
- func updateVPCConfig (ctx context.Context , conn * eks.Client , name string , vpcConfig * types.VpcConfigRequest , timeout time.Duration ) error {
968
- input := & eks.UpdateClusterConfigInput {
983
+ func updateClusterDeletionProtection (ctx context.Context , conn * eks.Client , name string , deletionProtection bool , timeout time.Duration ) error {
984
+ input := eks.UpdateClusterConfigInput {
985
+ DeletionProtection : aws .Bool (deletionProtection ),
986
+ Name : aws .String (name ),
987
+ }
988
+
989
+ output , err := conn .UpdateClusterConfig (ctx , & input )
990
+
991
+ if err != nil {
992
+ return fmt .Errorf ("updating EKS Cluster (%s) deletion protection (%t): %w" , name , deletionProtection , err )
993
+ }
994
+
995
+ updateID := aws .ToString (output .Update .Id )
996
+
997
+ if _ , err := waitClusterUpdateSuccessful (ctx , conn , name , updateID , timeout ); err != nil {
998
+ return fmt .Errorf ("waiting for EKS Cluster (%s) deletion protection update (%s): %w" , name , updateID , err )
999
+ }
1000
+
1001
+ return nil
1002
+ }
1003
+
1004
+ func updateClusterVPCConfig (ctx context.Context , conn * eks.Client , name string , vpcConfig * types.VpcConfigRequest , timeout time.Duration ) error {
1005
+ input := eks.UpdateClusterConfigInput {
969
1006
Name : aws .String (name ),
970
1007
ResourcesVpcConfig : vpcConfig ,
971
1008
}
972
1009
973
- output , err := conn .UpdateClusterConfig (ctx , input )
1010
+ output , err := conn .UpdateClusterConfig (ctx , & input )
974
1011
975
1012
if err != nil {
976
- return fmt .Errorf ("updating EKS Cluster (%s) VPC configuration: %s " , name , err )
1013
+ return fmt .Errorf ("updating EKS Cluster (%s) VPC configuration: %w " , name , err )
977
1014
}
978
1015
979
1016
updateID := aws .ToString (output .Update .Id )
980
1017
981
1018
if _ , err := waitClusterUpdateSuccessful (ctx , conn , name , updateID , timeout ); err != nil {
982
- return fmt .Errorf ("waiting for EKS Cluster (%s) VPC configuration update (%s): %s " , name , updateID , err )
1019
+ return fmt .Errorf ("waiting for EKS Cluster (%s) VPC configuration update (%s): %w " , name , updateID , err )
983
1020
}
984
1021
985
1022
return nil
986
1023
}
987
1024
988
- func findClusterUpdateByTwoPartKey (ctx context.Context , conn * eks.Client , name , id string ) (* types.Update , error ) {
989
- input := & eks.DescribeUpdateInput {
1025
+ func findUpdateByTwoPartKey (ctx context.Context , conn * eks.Client , name , id string ) (* types.Update , error ) {
1026
+ input := eks.DescribeUpdateInput {
990
1027
Name : aws .String (name ),
991
1028
UpdateId : aws .String (id ),
992
1029
}
993
1030
1031
+ return findUpdate (ctx , conn , & input )
1032
+ }
1033
+
1034
+ func findUpdate (ctx context.Context , conn * eks.Client , input * eks.DescribeUpdateInput ) (* types.Update , error ) {
994
1035
output , err := conn .DescribeUpdate (ctx , input )
995
1036
996
1037
if errs.IsA [* types.ResourceNotFoundException ](err ) {
@@ -1027,9 +1068,9 @@ func statusCluster(ctx context.Context, conn *eks.Client, name string) retry.Sta
1027
1068
}
1028
1069
}
1029
1070
1030
- func statusClusterUpdate (ctx context.Context , conn * eks.Client , name , id string ) retry.StateRefreshFunc {
1071
+ func statusUpdate (ctx context.Context , conn * eks.Client , name , id string ) retry.StateRefreshFunc {
1031
1072
return func () (any , string , error ) {
1032
- output , err := findClusterUpdateByTwoPartKey (ctx , conn , name , id )
1073
+ output , err := findUpdateByTwoPartKey (ctx , conn , name , id )
1033
1074
1034
1075
if tfresource .NotFound (err ) {
1035
1076
return nil , "" , nil
@@ -1085,7 +1126,7 @@ func waitClusterUpdateSuccessful(ctx context.Context, conn *eks.Client, name, id
1085
1126
stateConf := & retry.StateChangeConf {
1086
1127
Pending : enum .Slice (types .UpdateStatusInProgress ),
1087
1128
Target : enum .Slice (types .UpdateStatusSuccessful ),
1088
- Refresh : statusClusterUpdate (ctx , conn , name , id ),
1129
+ Refresh : statusUpdate (ctx , conn , name , id ),
1089
1130
Timeout : timeout ,
1090
1131
}
1091
1132
0 commit comments