Skip to content

Commit

Permalink
d/aws_mq_broker_instance_type_offerings: Switch to 'WithoutTimeout' C…
Browse files Browse the repository at this point in the history
…RUD handlers (#15090).

Acceptance test output:

% make testacc TESTARGS='-run=TestAccMQBrokerInstanceTypeOfferingsDataSource_' PKG=mq ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/mq/... -v -count 1 -parallel 2  -run=TestAccMQBrokerInstanceTypeOfferingsDataSource_ -timeout 180m
=== RUN   TestAccMQBrokerInstanceTypeOfferingsDataSource_basic
=== PAUSE TestAccMQBrokerInstanceTypeOfferingsDataSource_basic
=== CONT  TestAccMQBrokerInstanceTypeOfferingsDataSource_basic
--- PASS: TestAccMQBrokerInstanceTypeOfferingsDataSource_basic (18.12s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/mq	22.768s
  • Loading branch information
ewbankkit committed Nov 23, 2022
1 parent 63a212d commit 4b0d330
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions internal/service/mq/broker_instance_type_offerings_data_source.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package mq

import (
"fmt"
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/mq"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
Expand All @@ -13,7 +14,7 @@ import (

func DataSourceBrokerInstanceTypeOfferings() *schema.Resource {
return &schema.Resource{
Read: dataSourceBrokerInstanceTypeOfferingsRead,
ReadWithoutTimeout: dataSourceBrokerInstanceTypeOfferingsRead,

Schema: map[string]*schema.Schema{
"broker_instance_options": {
Expand Down Expand Up @@ -76,48 +77,43 @@ func DataSourceBrokerInstanceTypeOfferings() *schema.Resource {
}
}

func dataSourceBrokerInstanceTypeOfferingsRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceBrokerInstanceTypeOfferingsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).MQConn

input := &mq.DescribeBrokerInstanceOptionsInput{}

if v, ok := d.GetOk("host_instance_type"); ok {
input.HostInstanceType = aws.String(v.(string))
}

if v, ok := d.GetOk("engine_type"); ok {
input.EngineType = aws.String(v.(string))
}

if v, ok := d.GetOk("host_instance_type"); ok {
input.HostInstanceType = aws.String(v.(string))
}

if v, ok := d.GetOk("storage_type"); ok {
input.StorageType = aws.String(v.(string))
}

bios := make([]*mq.BrokerInstanceOption, 0)
for {
output, err := conn.DescribeBrokerInstanceOptions(input)
var output []*mq.BrokerInstanceOption

if err != nil {
return fmt.Errorf("error listing MQ Broker Instance Type Offerings: %w", err)
err := describeBrokerInstanceOptionsPagesWithContext(ctx, conn, input, func(page *mq.DescribeBrokerInstanceOptionsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

if output == nil {
return fmt.Errorf("empty response while reading MQ Broker Instance Type Offerings")
}
output = append(output, page.BrokerInstanceOptions...)

bios = append(bios, output.BrokerInstanceOptions...)

if aws.StringValue(output.NextToken) == "" {
break
}
return !lastPage
})

input.NextToken = output.NextToken
if err != nil {
return diag.Errorf("reading MQ Broker Instance Options: %s", err)
}

d.SetId(meta.(*conns.AWSClient).Region)

if err := d.Set("broker_instance_options", flattenBrokerInstanceOptions(bios)); err != nil {
return fmt.Errorf("error setting broker_instance_options: %w", err)
if err := d.Set("broker_instance_options", flattenBrokerInstanceOptions(output)); err != nil {
return diag.Errorf("setting broker_instance_options: %s", err)
}

return nil
Expand Down

0 comments on commit 4b0d330

Please sign in to comment.