1
1
package mq
2
2
3
3
import (
4
- "fmt "
4
+ "context "
5
5
6
6
"github.com/aws/aws-sdk-go/aws"
7
7
"github.com/aws/aws-sdk-go/service/mq"
8
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9
10
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
10
11
"github.com/hashicorp/terraform-provider-aws/internal/conns"
@@ -13,7 +14,7 @@ import (
13
14
14
15
func DataSourceBrokerInstanceTypeOfferings () * schema.Resource {
15
16
return & schema.Resource {
16
- Read : dataSourceBrokerInstanceTypeOfferingsRead ,
17
+ ReadWithoutTimeout : dataSourceBrokerInstanceTypeOfferingsRead ,
17
18
18
19
Schema : map [string ]* schema.Schema {
19
20
"broker_instance_options" : {
@@ -76,48 +77,43 @@ func DataSourceBrokerInstanceTypeOfferings() *schema.Resource {
76
77
}
77
78
}
78
79
79
- func dataSourceBrokerInstanceTypeOfferingsRead (d * schema.ResourceData , meta interface {}) error {
80
+ func dataSourceBrokerInstanceTypeOfferingsRead (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
80
81
conn := meta .(* conns.AWSClient ).MQConn
81
82
82
83
input := & mq.DescribeBrokerInstanceOptionsInput {}
83
84
84
- if v , ok := d .GetOk ("host_instance_type" ); ok {
85
- input .HostInstanceType = aws .String (v .(string ))
86
- }
87
-
88
85
if v , ok := d .GetOk ("engine_type" ); ok {
89
86
input .EngineType = aws .String (v .(string ))
90
87
}
91
88
89
+ if v , ok := d .GetOk ("host_instance_type" ); ok {
90
+ input .HostInstanceType = aws .String (v .(string ))
91
+ }
92
+
92
93
if v , ok := d .GetOk ("storage_type" ); ok {
93
94
input .StorageType = aws .String (v .(string ))
94
95
}
95
96
96
- bios := make ([]* mq.BrokerInstanceOption , 0 )
97
- for {
98
- output , err := conn .DescribeBrokerInstanceOptions (input )
97
+ var output []* mq.BrokerInstanceOption
99
98
100
- if err != nil {
101
- return fmt .Errorf ("error listing MQ Broker Instance Type Offerings: %w" , err )
99
+ err := describeBrokerInstanceOptionsPagesWithContext (ctx , conn , input , func (page * mq.DescribeBrokerInstanceOptionsOutput , lastPage bool ) bool {
100
+ if page == nil {
101
+ return ! lastPage
102
102
}
103
103
104
- if output == nil {
105
- return fmt .Errorf ("empty response while reading MQ Broker Instance Type Offerings" )
106
- }
104
+ output = append (output , page .BrokerInstanceOptions ... )
107
105
108
- bios = append (bios , output .BrokerInstanceOptions ... )
109
-
110
- if aws .StringValue (output .NextToken ) == "" {
111
- break
112
- }
106
+ return ! lastPage
107
+ })
113
108
114
- input .NextToken = output .NextToken
109
+ if err != nil {
110
+ return diag .Errorf ("reading MQ Broker Instance Options: %s" , err )
115
111
}
116
112
117
113
d .SetId (meta .(* conns.AWSClient ).Region )
118
114
119
- if err := d .Set ("broker_instance_options" , flattenBrokerInstanceOptions (bios )); err != nil {
120
- return fmt .Errorf ("error setting broker_instance_options: %w " , err )
115
+ if err := d .Set ("broker_instance_options" , flattenBrokerInstanceOptions (output )); err != nil {
116
+ return diag .Errorf ("setting broker_instance_options: %s " , err )
121
117
}
122
118
123
119
return nil
0 commit comments