Skip to content

Commit

Permalink
Merge pull request #24218 from stijndehaes/feature/add-support-for-ek…
Browse files Browse the repository at this point in the history
…s-add-on-preserve

feat: Add support for preserve to eks add-on
  • Loading branch information
ewbankkit authored Apr 13, 2022
2 parents f5d5c02 + c333c9b commit d0c49cd
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .changelog/24218.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_eks_addon: Add `preserve` argument
```
16 changes: 13 additions & 3 deletions internal/service/eks/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func ResourceAddon() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"preserve": {
Type: schema.TypeBool,
Optional: true,
},
"resolve_conflicts": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -279,11 +283,17 @@ func resourceAddonDelete(ctx context.Context, d *schema.ResourceData, meta inter
return diag.FromErr(err)
}

log.Printf("[DEBUG] Deleting EKS Add-On: %s", d.Id())
_, err = conn.DeleteAddonWithContext(ctx, &eks.DeleteAddonInput{
input := &eks.DeleteAddonInput{
AddonName: aws.String(addonName),
ClusterName: aws.String(clusterName),
})
}

if v, ok := d.GetOk("preserve"); ok {
input.Preserve = aws.Bool(v.(bool))
}

log.Printf("[DEBUG] Deleting EKS Add-On: %s", d.Id())
_, err = conn.DeleteAddonWithContext(ctx, input)

if err != nil {
return diag.FromErr(fmt.Errorf("error deleting EKS Add-On (%s): %w", d.Id(), err))
Expand Down
6 changes: 3 additions & 3 deletions internal/service/eks/addon_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAccEKSAddonDataSource_basic(t *testing.T) {
CheckDestroy: testAccCheckAddonDestroy,
Steps: []resource.TestStep{
{
Config: testAccAddonDataSourceConfig_Basic(rName, addonName),
Config: testAccAddonDataSourceConfig(rName, addonName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAddonExists(ctx, dataSourceResourceName, &addon),
acctest.MatchResourceAttrRegionalARN(dataSourceResourceName, "arn", "eks", regexp.MustCompile(fmt.Sprintf("addon/%s/%s/.+$", rName, addonName))),
Expand All @@ -43,8 +43,8 @@ func TestAccEKSAddonDataSource_basic(t *testing.T) {
})
}

func testAccAddonDataSourceConfig_Basic(rName, addonName string) string {
return acctest.ConfigCompose(testAccAddonConfig_Base(rName), fmt.Sprintf(`
func testAccAddonDataSourceConfig(rName, addonName string) string {
return acctest.ConfigCompose(testAccAddonBaseConfig(rName), fmt.Sprintf(`
resource "aws_eks_addon" "test" {
addon_name = %[2]q
cluster_name = aws_eks_cluster.test.name
Expand Down
Loading

0 comments on commit d0c49cd

Please sign in to comment.