Skip to content

Commit

Permalink
Merge pull request #38332 from szemek/b-wait-for-active-trust-store
Browse files Browse the repository at this point in the history
aws_lb_trust_store: wait for status ACTIVE
  • Loading branch information
ewbankkit authored Jul 12, 2024
2 parents ecaf0b4 + 7ecd2f1 commit d7ab117
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
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

0 comments on commit d7ab117

Please sign in to comment.