Skip to content

Commit 09fad67

Browse files
authored
Merge pull request #39946 from bryantbiggs/feat/eks-zonal-shift
feat: Add support for `zonal_shift_config` to EKS cluster
2 parents a41cfd8 + bc1fa23 commit 09fad67

File tree

7 files changed

+157
-1
lines changed

7 files changed

+157
-1
lines changed

.changelog/39852.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_eks_cluster: Add `zonal_shift_config` argument
3+
```

internal/service/eks/cluster.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@ func resourceCluster() *schema.Resource {
341341
},
342342
},
343343
},
344+
"zonal_shift_config": {
345+
Type: schema.TypeList,
346+
MaxItems: 1,
347+
Optional: true,
348+
Elem: &schema.Resource{
349+
Schema: map[string]*schema.Schema{
350+
names.AttrEnabled: {
351+
Type: schema.TypeBool,
352+
Optional: true,
353+
},
354+
},
355+
},
356+
},
344357
},
345358
}
346359
}
@@ -381,6 +394,10 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
381394
input.Version = aws.String(v.(string))
382395
}
383396

397+
if v, ok := d.GetOk("zonal_shift_config"); ok {
398+
input.ZonalShiftConfig = expandZonalShiftConfig(v.([]interface{}))
399+
}
400+
384401
outputRaw, err := tfresource.RetryWhen(ctx, propagationTimeout,
385402
func() (interface{}, error) {
386403
return conn.CreateCluster(ctx, input)
@@ -491,6 +508,9 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter
491508
if err := d.Set(names.AttrVPCConfig, flattenVPCConfigResponse(cluster.ResourcesVpcConfig)); err != nil {
492509
return sdkdiag.AppendErrorf(diags, "setting vpc_config: %s", err)
493510
}
511+
if err := d.Set("zonal_shift_config", flattenZonalShiftConfig(cluster.ZonalShiftConfig)); err != nil {
512+
return sdkdiag.AppendErrorf(diags, "setting zonal_shift_config: %s", err)
513+
}
494514

495515
setTagsOut(ctx, cluster.Tags)
496516

@@ -642,6 +662,25 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int
642662
}
643663
}
644664

665+
if d.HasChange("zonal_shift_config") {
666+
input := &eks.UpdateClusterConfigInput{
667+
Name: aws.String(d.Id()),
668+
ZonalShiftConfig: expandZonalShiftConfig(d.Get("zonal_shift_config").([]interface{})),
669+
}
670+
671+
output, err := conn.UpdateClusterConfig(ctx, input)
672+
673+
if err != nil {
674+
return sdkdiag.AppendErrorf(diags, "updating EKS Cluster (%s) zonal shift config: %s", d.Id(), err)
675+
}
676+
677+
updateID := aws.ToString(output.Update.Id)
678+
679+
if _, err := waitClusterUpdateSuccessful(ctx, conn, d.Id(), updateID, d.Timeout(schema.TimeoutUpdate)); err != nil {
680+
return sdkdiag.AppendErrorf(diags, "waiting for EKS Cluster (%s) zonal shift config update (%s): %s", d.Id(), updateID, err)
681+
}
682+
}
683+
645684
return append(diags, resourceClusterRead(ctx, d, meta)...)
646685
}
647686

@@ -1083,6 +1122,25 @@ func expandUpgradePolicy(tfList []interface{}) *types.UpgradePolicyRequest {
10831122
return upgradePolicyRequest
10841123
}
10851124

1125+
func expandZonalShiftConfig(tfList []interface{}) *types.ZonalShiftConfigRequest {
1126+
if len(tfList) == 0 {
1127+
return nil
1128+
}
1129+
1130+
tfMap, ok := tfList[0].(map[string]interface{})
1131+
if !ok {
1132+
return nil
1133+
}
1134+
1135+
ZonalShiftConfigRequest := &types.ZonalShiftConfigRequest{}
1136+
1137+
if v, ok := tfMap[names.AttrEnabled].(bool); ok {
1138+
ZonalShiftConfigRequest.Enabled = aws.Bool(v)
1139+
}
1140+
1141+
return ZonalShiftConfigRequest
1142+
}
1143+
10861144
func flattenCertificate(certificate *types.Certificate) []map[string]interface{} {
10871145
if certificate == nil {
10881146
return []map[string]interface{}{}
@@ -1255,3 +1313,15 @@ func flattenUpgradePolicy(apiObject *types.UpgradePolicyResponse) []interface{}
12551313

12561314
return []interface{}{tfMap}
12571315
}
1316+
1317+
func flattenZonalShiftConfig(apiObject *types.ZonalShiftConfigResponse) []interface{} {
1318+
if apiObject == nil {
1319+
return nil
1320+
}
1321+
1322+
tfMap := map[string]interface{}{
1323+
names.AttrEnabled: apiObject.Enabled,
1324+
}
1325+
1326+
return []interface{}{tfMap}
1327+
}

internal/service/eks/cluster_data_source.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ func dataSourceCluster() *schema.Resource {
214214
},
215215
},
216216
},
217+
"zonal_shift_config": {
218+
Type: schema.TypeList,
219+
Computed: true,
220+
Elem: &schema.Resource{
221+
Schema: map[string]*schema.Schema{
222+
names.AttrEnabled: {
223+
Type: schema.TypeBool,
224+
Computed: true,
225+
},
226+
},
227+
},
228+
},
217229
},
218230
}
219231
}
@@ -268,6 +280,9 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int
268280
if err := d.Set(names.AttrVPCConfig, flattenVPCConfigResponse(cluster.ResourcesVpcConfig)); err != nil {
269281
return sdkdiag.AppendErrorf(diags, "setting vpc_config: %s", err)
270282
}
283+
if err := d.Set("zonal_shift_config", flattenZonalShiftConfig(cluster.ZonalShiftConfig)); err != nil {
284+
return sdkdiag.AppendErrorf(diags, "setting zonal_shift_config: %s", err)
285+
}
271286

272287
if err := d.Set(names.AttrTags, KeyValueTags(ctx, cluster.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
273288
return sdkdiag.AppendErrorf(diags, "setting tags: %s", err)

internal/service/eks/cluster_data_source_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func TestAccEKSClusterDataSource_basic(t *testing.T) {
6161
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.subnet_ids.#", dataSourceResourceName, "vpc_config.0.subnet_ids.#"),
6262
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.public_access_cidrs.#", dataSourceResourceName, "vpc_config.0.public_access_cidrs.#"),
6363
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.vpc_id", dataSourceResourceName, "vpc_config.0.vpc_id"),
64+
resource.TestCheckResourceAttr(resourceName, "zonal_shift_config.#", "0"),
6465
),
6566
},
6667
},

internal/service/eks/cluster_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func TestAccEKSCluster_basic(t *testing.T) {
7777
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "0"),
7878
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.subnet_ids.#", "2"),
7979
resource.TestMatchResourceAttr(resourceName, "vpc_config.0.vpc_id", regexache.MustCompile(`^vpc-.+`)),
80+
resource.TestCheckResourceAttr(resourceName, "zonal_shift_config.#", "0"),
8081
),
8182
},
8283
{
@@ -960,6 +961,44 @@ func TestAccEKSCluster_upgradePolicy(t *testing.T) {
960961
})
961962
}
962963

964+
func TestAccEKSCluster_zonalShiftConfig(t *testing.T) {
965+
ctx := acctest.Context(t)
966+
var cluster1, cluster2 types.Cluster
967+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
968+
resourceName := "aws_eks_cluster.test"
969+
970+
resource.ParallelTest(t, resource.TestCase{
971+
PreCheck: func() { acctest.PreCheck(ctx, t) },
972+
ErrorCheck: acctest.ErrorCheck(t, names.EKSServiceID),
973+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
974+
CheckDestroy: testAccCheckClusterDestroy(ctx),
975+
Steps: []resource.TestStep{
976+
{
977+
Config: testAccClusterConfig_basic(rName),
978+
Check: resource.ComposeTestCheckFunc(
979+
testAccCheckClusterExists(ctx, resourceName, &cluster1),
980+
resource.TestCheckResourceAttr(resourceName, "zonal_shift_config.#", "0"),
981+
),
982+
},
983+
{
984+
Config: testAccClusterConfig_zonalShiftConfig(rName, true),
985+
Check: resource.ComposeTestCheckFunc(
986+
testAccCheckClusterExists(ctx, resourceName, &cluster2),
987+
testAccCheckClusterNotRecreated(&cluster1, &cluster2),
988+
resource.TestCheckResourceAttr(resourceName, "zonal_shift_config.#", "1"),
989+
resource.TestCheckResourceAttr(resourceName, "zonal_shift_config.0.enabled", acctest.CtTrue),
990+
),
991+
},
992+
{
993+
ResourceName: resourceName,
994+
ImportState: true,
995+
ImportStateVerify: true,
996+
ImportStateVerifyIgnore: []string{"bootstrap_self_managed_addons"},
997+
},
998+
},
999+
})
1000+
}
1001+
9631002
func testAccCheckClusterExists(ctx context.Context, n string, v *types.Cluster) resource.TestCheckFunc {
9641003
return func(s *terraform.State) error {
9651004
rs, ok := s.RootModule().Resources[n]
@@ -1539,3 +1578,22 @@ resource "aws_eks_cluster" "test" {
15391578
}
15401579
`, rName, supportType))
15411580
}
1581+
1582+
func testAccClusterConfig_zonalShiftConfig(rName string, enabled bool) string {
1583+
return acctest.ConfigCompose(testAccClusterConfig_base(rName), fmt.Sprintf(`
1584+
resource "aws_eks_cluster" "test" {
1585+
name = %[1]q
1586+
role_arn = aws_iam_role.test.arn
1587+
1588+
vpc_config {
1589+
subnet_ids = aws_subnet.test[*].id
1590+
}
1591+
1592+
zonal_shift_config {
1593+
enabled = %[2]t
1594+
}
1595+
1596+
depends_on = [aws_iam_role_policy_attachment.test-AmazonEKSClusterPolicy]
1597+
}
1598+
`, rName, enabled))
1599+
}

website/docs/d/eks_cluster.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ This data source exports the following attributes in addition to the arguments a
7777
* `security_group_ids` – List of security group IDs
7878
* `subnet_ids` – List of subnet IDs
7979
* `vpc_id` – The VPC associated with your cluster.
80+
* `zonal_shift_config` - Contains Zonal Shift Configuration.
81+
* `enabled` - Whether zonal shift is enabled.

website/docs/r/eks_cluster.html.markdown

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,13 @@ The following arguments are optional:
217217
* `access_config` - (Optional) Configuration block for the access config associated with your cluster, see [Amazon EKS Access Entries](https://docs.aws.amazon.com/eks/latest/userguide/access-entries.html).
218218
* `bootstrap_self_managed_addons` - (Optional) Install default unmanaged add-ons, such as `aws-cni`, `kube-proxy`, and CoreDNS during cluster creation. If `false`, you must manually install desired add-ons. Changing this value will force a new cluster to be created. Defaults to `true`.
219219
* `enabled_cluster_log_types` - (Optional) List of the desired control plane logging to enable. For more information, see [Amazon EKS Control Plane Logging](https://docs.aws.amazon.com/eks/latest/userguide/control-plane-logs.html).
220-
* `encryption_config` - (Optional) Configuration block with encryption configuration for the cluster. Only available on Kubernetes 1.13 and above clusters created after March 6, 2020. Detailed below.
220+
* `encryption_config` - (Optional) Configuration block with encryption configuration for the cluster. Detailed below.
221221
* `kubernetes_network_config` - (Optional) Configuration block with kubernetes network configuration for the cluster. Detailed below. If removed, Terraform will only perform drift detection if a configuration value is provided.
222222
* `outpost_config` - (Optional) Configuration block representing the configuration of your local Amazon EKS cluster on an AWS Outpost. This block isn't available for creating Amazon EKS clusters on the AWS cloud.
223223
* `tags` - (Optional) Key-value map of resource tags. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
224224
* `upgrade_policy` - (Optional) Configuration block for the support policy to use for the cluster. See [upgrade_policy](#upgrade_policy) for details.
225225
* `version` – (Optional) Desired Kubernetes master version. If you do not specify a value, the latest available version at resource creation is used and no upgrades will occur except those automatically triggered by EKS. The value must be configured and increased to upgrade the version when desired. Downgrades are not supported by EKS.
226+
* `zonal_shift_config` - (Optional) Configuration block with zonal shift configuration for the cluster. Detailed below.
226227

227228
### access_config
228229

@@ -292,6 +293,12 @@ The `upgrade_policy` configuration block supports the following arguments:
292293

293294
* `support_type` - (Optional) Support type to use for the cluster. If the cluster is set to `EXTENDED`, it will enter extended support at the end of standard support. If the cluster is set to `STANDARD`, it will be automatically upgraded at the end of standard support. Valid values are `EXTENDED`, `STANDARD`
294295

296+
### zonal_shift_config
297+
298+
The `zonal_shift_config` configuration block supports the following arguments:
299+
300+
* `enabled` - (Optional) Whether zonal shift is enabled for the cluster.
301+
295302
## Attribute Reference
296303

297304
This resource exports the following attributes in addition to the arguments above:

0 commit comments

Comments
 (0)