1
1
package ovh
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"log"
6
7
"net/url"
7
8
"strings"
8
9
10
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
9
11
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10
12
)
11
13
12
14
func dataSourceDbaasLogsOutputGraylogStream () * schema.Resource {
13
15
return & schema.Resource {
14
- Read : func (d * schema.ResourceData , meta interface {}) error {
15
- return dataSourceDbaasLogsOutputGraylogStreamRead (d , meta )
16
- },
16
+ ReadContext : dataSourceDbaasLogsOutputGraylogStreamRead ,
17
17
Schema : map [string ]* schema.Schema {
18
18
"service_name" : {
19
19
Type : schema .TypeString ,
@@ -137,11 +137,17 @@ func dataSourceDbaasLogsOutputGraylogStream() *schema.Resource {
137
137
Description : "Enable Websocket" ,
138
138
Computed : true ,
139
139
},
140
+ "write_token" : {
141
+ Type : schema .TypeString ,
142
+ Description : "Write token of the stream" ,
143
+ Computed : true ,
144
+ Sensitive : true ,
145
+ },
140
146
},
141
147
}
142
148
}
143
149
144
- func dataSourceDbaasLogsOutputGraylogStreamRead (d * schema.ResourceData , meta interface {}) error {
150
+ func dataSourceDbaasLogsOutputGraylogStreamRead (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
145
151
config := meta .(* Config )
146
152
147
153
serviceName := d .Get ("service_name" ).(string )
@@ -154,7 +160,7 @@ func dataSourceDbaasLogsOutputGraylogStreamRead(d *schema.ResourceData, meta int
154
160
url .PathEscape (serviceName ),
155
161
)
156
162
if err := config .OVHClient .Get (endpoint , & res ); err != nil {
157
- return fmt .Errorf ("Error calling Get %s:\n \t %q" , endpoint , err )
163
+ return diag .Errorf ("Error calling Get %s:\n \t %q" , endpoint , err )
158
164
}
159
165
streams := []* DbaasLogsOutputGraylogStream {}
160
166
@@ -169,7 +175,7 @@ func dataSourceDbaasLogsOutputGraylogStreamRead(d *schema.ResourceData, meta int
169
175
170
176
stream := & DbaasLogsOutputGraylogStream {}
171
177
if err := config .OVHClient .Get (endpoint , & stream ); err != nil {
172
- return fmt .Errorf ("Error calling Get %s:\n \t %q" , endpoint , err )
178
+ return diag .Errorf ("Error calling Get %s:\n \t %q" , endpoint , err )
173
179
}
174
180
175
181
log .Printf ("[INFO]Comparing : %s ? %s" ,
@@ -183,12 +189,10 @@ func dataSourceDbaasLogsOutputGraylogStreamRead(d *schema.ResourceData, meta int
183
189
}
184
190
185
191
if len (streams ) == 0 {
186
- return fmt .Errorf ("Your query returned no results. " +
187
- "Please change your search criteria and try again." )
192
+ return diag .Errorf ("Your query returned no results. Please change your search criteria and try again." )
188
193
}
189
194
if len (streams ) > 1 {
190
- return fmt .Errorf ("Your query returned more than one result. " +
191
- "Please change your search criteria and try again." )
195
+ return diag .Errorf ("Your query returned more than one result. Please change your search criteria and try again." )
192
196
}
193
197
194
198
for k , v := range streams [0 ].ToMap () {
@@ -200,5 +204,12 @@ func dataSourceDbaasLogsOutputGraylogStreamRead(d *schema.ResourceData, meta int
200
204
}
201
205
}
202
206
207
+ // Get stream write token, if available
208
+ writeToken , err := resourceDbaasLogsOutputGraylogStreamGetWriteToken (ctx , config , serviceName , streams [0 ].StreamId )
209
+ if err != nil {
210
+ return diag .FromErr (err )
211
+ }
212
+ d .Set ("write_token" , writeToken )
213
+
203
214
return nil
204
215
}
0 commit comments