diff --git a/go.mod b/go.mod index e138385b..4056b8f7 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/hashicorp/terraform-plugin-docs v0.13.0 - github.com/hashicorp/terraform-plugin-framework v0.14.0 + github.com/hashicorp/terraform-plugin-framework v0.15.0 github.com/hashicorp/terraform-plugin-framework-validators v0.5.0 github.com/hashicorp/terraform-plugin-go v0.14.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 diff --git a/go.sum b/go.sum index 0dddb61e..e635a248 100644 --- a/go.sum +++ b/go.sum @@ -139,8 +139,8 @@ github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM= github.com/hashicorp/terraform-plugin-docs v0.13.0 h1:6e+VIWsVGb6jYJewfzq2ok2smPzZrt1Wlm9koLeKazY= github.com/hashicorp/terraform-plugin-docs v0.13.0/go.mod h1:W0oCmHAjIlTHBbvtppWHe8fLfZ2BznQbuv8+UD8OucQ= -github.com/hashicorp/terraform-plugin-framework v0.14.0 h1:Mwj55u+Jc/QGM6fLBPCe1P+ZF3cuYs6wbCdB15lx/Dg= -github.com/hashicorp/terraform-plugin-framework v0.14.0/go.mod h1:wcZdk4+Uef6Ng+BiBJjGAcIPlIs5bhlEV/TA1k6Xkq8= +github.com/hashicorp/terraform-plugin-framework v0.15.0 h1:6f4UY2yfp5UsSX9JhUA6RSptjd+ojStBGWA4jrPhB6Q= +github.com/hashicorp/terraform-plugin-framework v0.15.0/go.mod h1:wcZdk4+Uef6Ng+BiBJjGAcIPlIs5bhlEV/TA1k6Xkq8= github.com/hashicorp/terraform-plugin-framework-validators v0.5.0 h1:eD79idhnJOBajkUMEbm0c8dOyOb/F49STbUEVojT6F4= github.com/hashicorp/terraform-plugin-framework-validators v0.5.0/go.mod h1:NfGgclDM3FZqvNVppPKE2aHI1JAyT002ypPRya7ch3I= github.com/hashicorp/terraform-plugin-go v0.14.0 h1:ttnSlS8bz3ZPYbMb84DpcPhY4F5DsQtcAS7cHo8uvP4= diff --git a/internal/provider/data_source_http.go b/internal/provider/data_source_http.go index a0eb8734..e25be389 100644 --- a/internal/provider/data_source_http.go +++ b/internal/provider/data_source_http.go @@ -5,14 +5,15 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator" - "github.com/hashicorp/terraform-plugin-framework/path" "io/ioutil" "mime" "net/http" "regexp" "strings" + "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -150,10 +151,10 @@ func (d *httpDataSource) Read(ctx context.Context, req datasource.ReadRequest, r return } - url := model.URL.Value - method := model.Method.Value + url := model.URL.ValueString() + method := model.Method.ValueString() requestHeaders := model.RequestHeaders - requestBody := strings.NewReader(model.RequestBody.Value) + requestBody := strings.NewReader(model.RequestBody.ValueString()) if method == "" { method = "GET" @@ -166,13 +167,13 @@ func (d *httpDataSource) Read(ctx context.Context, req datasource.ReadRequest, r } if !model.Insecure.IsNull() { - tr.TLSClientConfig.InsecureSkipVerify = model.Insecure.Value + tr.TLSClientConfig.InsecureSkipVerify = model.Insecure.ValueBool() } // Use `ca_cert_pem` cert pool if !caCertificate.IsNull() { caCertPool := x509.NewCertPool() - if ok := caCertPool.AppendCertsFromPEM([]byte(caCertificate.Value)); !ok { + if ok := caCertPool.AppendCertsFromPEM([]byte(caCertificate.ValueString())); !ok { resp.Diagnostics.AddError( "Error configuring TLS client", "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 return } - for name, value := range requestHeaders.Elems { + for name, value := range requestHeaders.Elements() { var header string diags = tfsdk.ValueAs(ctx, value, &header) resp.Diagnostics.Append(diags...) @@ -244,19 +245,17 @@ func (d *httpDataSource) Read(ctx context.Context, req datasource.ReadRequest, r responseHeaders[k] = strings.Join(v, ", ") } - respHeadersState := types.Map{} - - diags = tfsdk.ValueFrom(ctx, responseHeaders, types.Map{ElemType: types.StringType}.Type(ctx), &respHeadersState) + respHeadersState, diags := types.MapValueFrom(ctx, types.StringType, responseHeaders) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } - model.ID = types.String{Value: url} + model.ID = types.StringValue(url) model.ResponseHeaders = respHeadersState - model.ResponseBody = types.String{Value: responseBody} - model.Body = types.String{Value: responseBody} - model.StatusCode = types.Int64{Value: int64(response.StatusCode)} + model.ResponseBody = types.StringValue(responseBody) + model.Body = types.StringValue(responseBody) + model.StatusCode = types.Int64Value(int64(response.StatusCode)) diags = resp.State.Set(ctx, model) resp.Diagnostics.Append(diags...)