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 node_repair_config to aws_eks_node_group #40698

Merged
62 changes: 61 additions & 1 deletion internal/service/eks/node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ func resourceNodeGroup() *schema.Resource {
ConflictsWith: []string{"node_group_name"},
ValidateFunc: validation.StringLenBetween(0, 63-id.UniqueIDSuffixLength),
},
"node_repair_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
"node_role_arn": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -341,6 +356,10 @@ func resourceNodeGroupCreate(ctx context.Context, d *schema.ResourceData, meta i
input.LaunchTemplate = expandLaunchTemplateSpecification(v)
}

if v, ok := d.GetOk("node_repair_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.NodeRepairConfig = expandNodegroupRepairConfig(v.([]interface{})[0].(map[string]interface{}))
}

if v, ok := d.GetOk("release_version"); ok {
input.ReleaseVersion = aws.String(v.(string))
}
Expand Down Expand Up @@ -414,6 +433,13 @@ func resourceNodeGroupRead(ctx context.Context, d *schema.ResourceData, meta int
}
d.Set("node_group_name", nodeGroup.NodegroupName)
d.Set("node_group_name_prefix", create.NamePrefixFromName(aws.ToString(nodeGroup.NodegroupName)))
if nodeGroup.NodeRepairConfig != nil {
if err := d.Set("node_repair_config", []interface{}{flattenNodeGroupRepairConfig(nodeGroup.NodeRepairConfig)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting node_repair_config: %s", err)
}
} else {
d.Set("node_repair_config", nil)
}
d.Set("node_role_arn", nodeGroup.NodeRole)
d.Set("release_version", nodeGroup.ReleaseVersion)
if err := d.Set("remote_access", flattenRemoteAccessConfig(nodeGroup.RemoteAccess)); err != nil {
Expand Down Expand Up @@ -508,7 +534,7 @@ func resourceNodeGroupUpdate(ctx context.Context, d *schema.ResourceData, meta i
}
}

if d.HasChanges("labels", "scaling_config", "taint", "update_config") {
if d.HasChanges("labels", "scaling_config", "taint", "update_config", "node_repair_config") {
oldLabelsRaw, newLabelsRaw := d.GetChange("labels")
oldTaintsRaw, newTaintsRaw := d.GetChange("taint")

Expand All @@ -520,6 +546,12 @@ func resourceNodeGroupUpdate(ctx context.Context, d *schema.ResourceData, meta i
Taints: expandUpdateTaintsPayload(oldTaintsRaw.(*schema.Set).List(), newTaintsRaw.(*schema.Set).List()),
}

if d.HasChange("node_repair_config") {
if v, ok := d.GetOk("node_repair_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.NodeRepairConfig = expandNodegroupRepairConfig(v.([]interface{})[0].(map[string]interface{}))
}
}

if d.HasChange("scaling_config") {
if v, ok := d.GetOk("scaling_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.ScalingConfig = expandNodegroupScalingConfig(v.([]interface{})[0].(map[string]interface{}))
Expand Down Expand Up @@ -915,6 +947,20 @@ func expandNodegroupUpdateConfig(tfMap map[string]interface{}) *types.NodegroupU
return apiObject
}

func expandNodegroupRepairConfig(tfMap map[string]interface{}) *types.NodeRepairConfig {
if tfMap == nil {
return nil
}

apiObject := &types.NodeRepairConfig{}

if v, ok := tfMap["enabled"].(bool); ok {
apiObject.Enabled = aws.Bool(v)
}

return apiObject
}

func expandUpdateLabelsPayload(ctx context.Context, oldLabelsMap, newLabelsMap interface{}) *types.UpdateLabelsPayload {
// EKS Labels operate similarly to keyvaluetags
oldLabels := tftags.New(ctx, oldLabelsMap)
Expand Down Expand Up @@ -1015,6 +1061,20 @@ func flattenNodeGroupScalingConfig(apiObject *types.NodegroupScalingConfig) map[
return tfMap
}

func flattenNodeGroupRepairConfig(apiObject *types.NodeRepairConfig) map[string]interface{} {
if apiObject == nil {
return nil
}

tfMap := make(map[string]interface{})

if v := apiObject.Enabled; v != nil {
tfMap["enabled"] = aws.ToBool(v)
}

return tfMap
}

func flattenNodeGroupUpdateConfig(apiObject *types.NodegroupUpdateConfig) map[string]interface{} {
if apiObject == nil {
return nil
Expand Down
56 changes: 56 additions & 0 deletions internal/service/eks/node_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,35 @@ func TestAccEKSNodeGroup_LaunchTemplate_version(t *testing.T) {
})
}

func TestAccEKSNodeGroup_RepairConfig(t *testing.T) {
ctx := acctest.Context(t)
var nodeGroup1 types.Nodegroup
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_eks_node_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EKSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckNodeGroupDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccNodeGroupConfig_repairConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckNodeGroupExists(ctx, resourceName, &nodeGroup1),
resource.TestCheckResourceAttr(resourceName, "node_repair_config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "node_repair_config.0.enabled", acctest.CtTrue),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccEKSNodeGroup_releaseVersion(t *testing.T) {
ctx := acctest.Context(t)
var nodeGroup1, nodeGroup2 types.Nodegroup
Expand Down Expand Up @@ -2044,6 +2073,33 @@ resource "aws_eks_node_group" "test" {
`, rName, taintKey1, taintValue1, taintEffect1, taintKey2, taintValue2, taintEffect2))
}

func testAccNodeGroupConfig_repairConfig(rName string) string {
return acctest.ConfigCompose(testAccNodeGroupBaseConfig(rName), fmt.Sprintf(`
resource "aws_eks_node_group" "test" {
cluster_name = aws_eks_cluster.test.name
node_group_name = %[1]q
node_role_arn = aws_iam_role.node.arn
subnet_ids = aws_subnet.test[*].id

scaling_config {
desired_size = 1
max_size = 3
min_size = 1
}

node_repair_config {
enabled = true
}

depends_on = [
aws_iam_role_policy_attachment.node-AmazonEKSWorkerNodePolicy,
aws_iam_role_policy_attachment.node-AmazonEKS_CNI_Policy,
aws_iam_role_policy_attachment.node-AmazonEC2ContainerRegistryReadOnly,
]
}
`, rName))
}

func testAccNodeGroupConfig_update1(rName string) string {
return acctest.ConfigCompose(testAccNodeGroupBaseConfig(rName), fmt.Sprintf(`
resource "aws_eks_node_group" "test" {
Expand Down
Loading