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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

F aws eks addon add timeouts #26629

Merged
merged 3 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions internal/service/eks/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
16 changes: 6 additions & 10 deletions internal/service/eks/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/eks_addon.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.,
Expand Down