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

aws_lb_trust_store: wait for status ACTIVE #38332

Merged
merged 5 commits into from
Jul 12, 2024
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/38332.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_lb_trust_store: Wait until trust store is `ACTIVE` on resource Create
```
40 changes: 40 additions & 0 deletions internal/service/elbv2/trust_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/enum"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
Expand Down Expand Up @@ -149,6 +150,10 @@ func resourceTrustStoreCreate(ctx context.Context, d *schema.ResourceData, meta
return sdkdiag.AppendErrorf(diags, "waiting for ELBv2 Trust Store (%s) create: %s", d.Id(), err)
}

if _, err := waitTrustStoreActive(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ELBv2 Trust Store (%s) create: %s", d.Id(), err)
}

// For partitions not supporting tag-on-create, attempt tag after create.
if tags := getTagsIn(ctx); input.Tags == nil && len(tags) > 0 {
err := createTags(ctx, conn, d.Id(), tags)
Expand Down Expand Up @@ -294,6 +299,41 @@ func findTrustStores(ctx context.Context, conn *elasticloadbalancingv2.Client, i
return output, nil
}

func statusTrustStore(ctx context.Context, conn *elasticloadbalancingv2.Client, arn string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := findTrustStoreByARN(ctx, conn, arn)

if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

return output, string(output.Status), nil
}
}

func waitTrustStoreActive(ctx context.Context, conn *elasticloadbalancingv2.Client, arn string, timeout time.Duration) (*awstypes.TrustStore, error) {
stateConf := &retry.StateChangeConf{
Pending: enum.Slice(awstypes.TrustStoreStatusCreating),
Target: enum.Slice(awstypes.TrustStoreStatusActive),
Refresh: statusTrustStore(ctx, conn, arn),
Timeout: timeout,
MinTimeout: 10 * time.Second,
Delay: 30 * time.Second,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*awstypes.TrustStore); ok {
return output, err
}

return nil, err
}

func findTrustStoreAssociations(ctx context.Context, conn *elasticloadbalancingv2.Client, input *elasticloadbalancingv2.DescribeTrustStoreAssociationsInput) ([]awstypes.TrustStoreAssociation, error) {
var output []awstypes.TrustStoreAssociation

Expand Down
Loading