Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bootstrapSelfManagedAddons flag in aws_eks_cluster resource #38162

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/38162.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_eks_cluster: Add `bootstrap_self_managed_addons` argument
```
32 changes: 26 additions & 6 deletions internal/service/eks/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ func resourceCluster() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceClusterV0().CoreConfigSchema().ImpliedType(),
Upgrade: clusterStateUpgradeV0,
Version: 0,
},
},

CustomizeDiff: customdiff.Sequence(
verify.SetTagsDiff,
customdiff.ForceNewIfChange("encryption_config", func(_ context.Context, old, new, meta interface{}) bool {
Expand Down Expand Up @@ -83,6 +92,12 @@ func resourceCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"bootstrap_self_managed_addons": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Default: true,
},
"certificate_authority": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -321,12 +336,13 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int

name := d.Get(names.AttrName).(string)
input := &eks.CreateClusterInput{
EncryptionConfig: expandEncryptionConfig(d.Get("encryption_config").([]interface{})),
Logging: expandLogging(d.Get("enabled_cluster_log_types").(*schema.Set)),
Name: aws.String(name),
ResourcesVpcConfig: expandVpcConfigRequest(d.Get(names.AttrVPCConfig).([]interface{})),
RoleArn: aws.String(d.Get(names.AttrRoleARN).(string)),
Tags: getTagsIn(ctx),
BootstrapSelfManagedAddons: aws.Bool(d.Get("bootstrap_self_managed_addons").(bool)),
EncryptionConfig: expandEncryptionConfig(d.Get("encryption_config").([]interface{})),
Logging: expandLogging(d.Get("enabled_cluster_log_types").(*schema.Set)),
Name: aws.String(name),
ResourcesVpcConfig: expandVpcConfigRequest(d.Get(names.AttrVPCConfig).([]interface{})),
RoleArn: aws.String(d.Get(names.AttrRoleARN).(string)),
Tags: getTagsIn(ctx),
}

if v, ok := d.GetOk("access_config"); ok {
Expand Down Expand Up @@ -418,6 +434,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter
return sdkdiag.AppendErrorf(diags, "setting access_config: %s", err)
}
d.Set(names.AttrARN, cluster.Arn)
d.Set("bootstrap_self_managed_addons", d.Get("bootstrap_self_managed_addons"))
if err := d.Set("certificate_authority", flattenCertificate(cluster.CertificateAuthority)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting certificate_authority: %s", err)
}
Expand Down Expand Up @@ -770,6 +787,9 @@ func waitClusterDeleted(ctx context.Context, conn *eks.Client, name string, time
Target: []string{},
Refresh: statusCluster(ctx, conn, name),
Timeout: timeout,
// An attempt to avoid "ResourceInUseException: Cluster already exists with name: ..." errors
// in acceptance tests when recreating a cluster with the same randomly generated name.
ContinuousTargetOccurence: 3,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)
Expand Down
270 changes: 270 additions & 0 deletions internal/service/eks/cluster_migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package eks

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)

// aws_eks_cluster resource's Schema @v5.56.1 minus validators.
func resourceClusterV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"access_config": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"authentication_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"bootstrap_cluster_creator_admin_permissions": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
},
},
},
names.AttrARN: {
Type: schema.TypeString,
Computed: true,
},
"certificate_authority": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"data": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"cluster_id": {
Type: schema.TypeString,
Computed: true,
},
names.AttrCreatedAt: {
Type: schema.TypeString,
Computed: true,
},
"enabled_cluster_log_types": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"encryption_config": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"provider": {
Type: schema.TypeList,
MaxItems: 1,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key_arn": {
Type: schema.TypeString,
Required: true,
},
},
},
},
names.AttrResources: {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
names.AttrEndpoint: {
Type: schema.TypeString,
Computed: true,
},
"identity": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"oidc": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrIssuer: {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
"kubernetes_network_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_family": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"service_ipv4_cidr": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"service_ipv6_cidr": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
names.AttrName: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"outpost_config": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"control_plane_instance_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"control_plane_placement": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrGroupName: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
},
},
"outpost_arns": {
Type: schema.TypeSet,
Required: true,
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"platform_version": {
Type: schema.TypeString,
Computed: true,
},
names.AttrRoleARN: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
names.AttrStatus: {
Type: schema.TypeString,
Computed: true,
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
names.AttrVersion: {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
names.AttrVPCConfig: {
Type: schema.TypeList,
MinItems: 1,
MaxItems: 1,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cluster_security_group_id": {
Type: schema.TypeString,
Computed: true,
},
"endpoint_private_access": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"endpoint_public_access": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"public_access_cidrs": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
names.AttrSecurityGroupIDs: {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
names.AttrSubnetIDs: {
Type: schema.TypeSet,
Required: true,
MinItems: 1,
Elem: &schema.Schema{Type: schema.TypeString},
},
names.AttrVPCID: {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}

func clusterStateUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
if rawState == nil {
rawState = map[string]interface{}{}
}

if _, ok := rawState["bootstrap_self_managed_addons"]; !ok {
rawState["bootstrap_self_managed_addons"] = "true"
}

return rawState, nil
}
Loading
Loading