From 9aac2d36982394654ddf8eb17a4c39acd2d6318a Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Fri, 2 Sep 2022 15:46:08 -0500 Subject: [PATCH 1/3] Added Timeout configuration option for aws_eks_addon --- internal/service/eks/addon.go | 12 +++++++++--- internal/service/eks/wait.go | 16 ++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/internal/service/eks/addon.go b/internal/service/eks/addon.go index 267ab143e18b..34c6f9187254 100644 --- a/internal/service/eks/addon.go +++ b/internal/service/eks/addon.go @@ -33,6 +33,12 @@ func ResourceAddon() *schema.Resource { CustomizeDiff: verify.SetTagsDiff, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(20 * time.Minute), + Update: schema.DefaultTimeout(20 * time.Minute), + Delete: schema.DefaultTimeout(40 * time.Minute), + }, + Schema: map[string]*schema.Schema{ "addon_name": { Type: schema.TypeString, @@ -146,7 +152,7 @@ func resourceAddonCreate(ctx context.Context, d *schema.ResourceData, meta inter d.SetId(id) - _, err = waitAddonCreated(ctx, conn, clusterName, addonName) + _, err = waitAddonCreated(ctx, conn, clusterName, addonName, d.Timeout(schema.TimeoutCreate)) if err != nil { // Creating addon w/o setting resolve_conflicts to "OVERWRITE" @@ -248,7 +254,7 @@ func resourceAddonUpdate(ctx context.Context, d *schema.ResourceData, meta inter updateID := aws.StringValue(output.Update.Id) - _, err = waitAddonUpdateSuccessful(ctx, conn, clusterName, addonName, updateID) + _, err = waitAddonUpdateSuccessful(ctx, conn, clusterName, addonName, updateID, d.Timeout(schema.TimeoutUpdate)) if err != nil { if d.Get("resolve_conflicts") != eks.ResolveConflictsOverwrite { @@ -298,7 +304,7 @@ func resourceAddonDelete(ctx context.Context, d *schema.ResourceData, meta inter return diag.FromErr(fmt.Errorf("error deleting EKS Add-On (%s): %w", d.Id(), err)) } - _, err = waitAddonDeleted(ctx, conn, clusterName, addonName) + _, err = waitAddonDeleted(ctx, conn, clusterName, addonName, d.Timeout(schema.TimeoutDelete)) if err != nil { return diag.FromErr(fmt.Errorf("error waiting for EKS Add-On (%s) to delete: %w", d.Id(), err)) diff --git a/internal/service/eks/wait.go b/internal/service/eks/wait.go index 212ee4772d1d..ef555e421a3e 100644 --- a/internal/service/eks/wait.go +++ b/internal/service/eks/wait.go @@ -11,19 +11,15 @@ import ( ) const ( - addonCreatedTimeout = 20 * time.Minute - addonUpdatedTimeout = 20 * time.Minute - addonDeletedTimeout = 40 * time.Minute - clusterDeleteRetryTimeout = 60 * time.Minute ) -func waitAddonCreated(ctx context.Context, conn *eks.EKS, clusterName, addonName string) (*eks.Addon, error) { +func waitAddonCreated(ctx context.Context, conn *eks.EKS, clusterName, addonName string, timeout time.Duration) (*eks.Addon, error) { stateConf := resource.StateChangeConf{ Pending: []string{eks.AddonStatusCreating, eks.AddonStatusDegraded}, Target: []string{eks.AddonStatusActive}, Refresh: statusAddon(ctx, conn, clusterName, addonName), - Timeout: addonCreatedTimeout, + Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) @@ -39,12 +35,12 @@ func waitAddonCreated(ctx context.Context, conn *eks.EKS, clusterName, addonName return nil, err } -func waitAddonDeleted(ctx context.Context, conn *eks.EKS, clusterName, addonName string) (*eks.Addon, error) { +func waitAddonDeleted(ctx context.Context, conn *eks.EKS, clusterName, addonName string, timeout time.Duration) (*eks.Addon, error) { stateConf := &resource.StateChangeConf{ Pending: []string{eks.AddonStatusActive, eks.AddonStatusDeleting}, Target: []string{}, Refresh: statusAddon(ctx, conn, clusterName, addonName), - Timeout: addonDeletedTimeout, + Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) @@ -60,12 +56,12 @@ func waitAddonDeleted(ctx context.Context, conn *eks.EKS, clusterName, addonName return nil, err } -func waitAddonUpdateSuccessful(ctx context.Context, conn *eks.EKS, clusterName, addonName, id string) (*eks.Update, error) { +func waitAddonUpdateSuccessful(ctx context.Context, conn *eks.EKS, clusterName, addonName, id string, timeout time.Duration) (*eks.Update, error) { stateConf := resource.StateChangeConf{ Pending: []string{eks.UpdateStatusInProgress}, Target: []string{eks.UpdateStatusSuccessful}, Refresh: statusAddonUpdate(ctx, conn, clusterName, addonName, id), - Timeout: addonUpdatedTimeout, + Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) From 4ed86e3ef0afafad6716b721821c1e1122417f54 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Fri, 2 Sep 2022 15:46:53 -0500 Subject: [PATCH 2/3] Added Timeouts section to aws_eks_addon documentation --- website/docs/r/eks_addon.html.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/website/docs/r/eks_addon.html.markdown b/website/docs/r/eks_addon.html.markdown index d3bf6c5ceb8c..655da7754fb8 100644 --- a/website/docs/r/eks_addon.html.markdown +++ b/website/docs/r/eks_addon.html.markdown @@ -110,6 +110,14 @@ In addition to all arguments above, the following attributes are exported: * `modified_at` - Date and time in [RFC3339 format](https://tools.ietf.org/html/rfc3339#section-5.8) that the EKS add-on was updated. * `tags_all` - (Optional) Key-value map of resource tags, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). +## Timeouts + +[Configuration options](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts): + +* `create` - (Default `20m`) +* `update` - (Default `20m`) +* `delete` - (Default `40m`) + ## Import EKS add-on can be imported using the `cluster_name` and `addon_name` separated by a colon (`:`), e.g., From 5b979b0760ee9f22ba1d04c5e2f39296bd0b7fda Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Fri, 2 Sep 2022 16:18:27 -0500 Subject: [PATCH 3/3] Added changelog entry for enhancement --- .changelog/26629.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/26629.txt diff --git a/.changelog/26629.txt b/.changelog/26629.txt new file mode 100644 index 000000000000..21da3becd409 --- /dev/null +++ b/.changelog/26629.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_eks_addon: Support configurable timeouts for addon create, update, and delete +``` \ No newline at end of file