@@ -5,14 +5,15 @@ import (
55 "crypto/tls"
66 "crypto/x509"
77 "fmt"
8- "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator"
9- "github.com/hashicorp/terraform-plugin-framework/path"
108 "io/ioutil"
119 "mime"
1210 "net/http"
1311 "regexp"
1412 "strings"
1513
14+ "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator"
15+ "github.com/hashicorp/terraform-plugin-framework/path"
16+
1617 "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1718 "github.com/hashicorp/terraform-plugin-framework/datasource"
1819 "github.com/hashicorp/terraform-plugin-framework/diag"
@@ -150,10 +151,10 @@ func (d *httpDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
150151 return
151152 }
152153
153- url := model .URL .Value
154- method := model .Method .Value
154+ url := model .URL .ValueString ()
155+ method := model .Method .ValueString ()
155156 requestHeaders := model .RequestHeaders
156- requestBody := strings .NewReader (model .RequestBody .Value )
157+ requestBody := strings .NewReader (model .RequestBody .ValueString () )
157158
158159 if method == "" {
159160 method = "GET"
@@ -166,13 +167,13 @@ func (d *httpDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
166167 }
167168
168169 if ! model .Insecure .IsNull () {
169- tr .TLSClientConfig .InsecureSkipVerify = model .Insecure .Value
170+ tr .TLSClientConfig .InsecureSkipVerify = model .Insecure .ValueBool ()
170171 }
171172
172173 // Use `ca_cert_pem` cert pool
173174 if ! caCertificate .IsNull () {
174175 caCertPool := x509 .NewCertPool ()
175- if ok := caCertPool .AppendCertsFromPEM ([]byte (caCertificate .Value )); ! ok {
176+ if ok := caCertPool .AppendCertsFromPEM ([]byte (caCertificate .ValueString () )); ! ok {
176177 resp .Diagnostics .AddError (
177178 "Error configuring TLS client" ,
178179 "Error tls: Can't add the CA certificate to certificate pool. Only PEM encoded certificates are supported." ,
@@ -196,7 +197,7 @@ func (d *httpDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
196197 return
197198 }
198199
199- for name , value := range requestHeaders .Elems {
200+ for name , value := range requestHeaders .Elements () {
200201 var header string
201202 diags = tfsdk .ValueAs (ctx , value , & header )
202203 resp .Diagnostics .Append (diags ... )
@@ -244,19 +245,17 @@ func (d *httpDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
244245 responseHeaders [k ] = strings .Join (v , ", " )
245246 }
246247
247- respHeadersState := types.Map {}
248-
249- diags = tfsdk .ValueFrom (ctx , responseHeaders , types.Map {ElemType : types .StringType }.Type (ctx ), & respHeadersState )
248+ respHeadersState , diags := types .MapValueFrom (ctx , types .StringType , responseHeaders )
250249 resp .Diagnostics .Append (diags ... )
251250 if resp .Diagnostics .HasError () {
252251 return
253252 }
254253
255- model .ID = types.String { Value : url }
254+ model .ID = types .StringValue ( url )
256255 model .ResponseHeaders = respHeadersState
257- model .ResponseBody = types.String { Value : responseBody }
258- model .Body = types.String { Value : responseBody }
259- model .StatusCode = types.Int64 { Value : int64 (response .StatusCode )}
256+ model .ResponseBody = types .StringValue ( responseBody )
257+ model .Body = types .StringValue ( responseBody )
258+ model .StatusCode = types .Int64Value ( int64 (response .StatusCode ))
260259
261260 diags = resp .State .Set (ctx , model )
262261 resp .Diagnostics .Append (diags ... )
0 commit comments