@@ -20,11 +20,10 @@ import (
2020 "github.com/hashicorp/go-retryablehttp"
2121 "github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
2222 "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
23+ "github.com/hashicorp/terraform-plugin-framework/diag"
2324 "github.com/hashicorp/terraform-plugin-framework/path"
2425 "github.com/hashicorp/terraform-plugin-framework/resource"
2526 rs "github.com/hashicorp/terraform-plugin-framework/resource/schema"
26- "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
27- "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2827 "github.com/hashicorp/terraform-plugin-framework/schema/validator"
2928 "github.com/hashicorp/terraform-plugin-framework/tfsdk"
3029 "github.com/hashicorp/terraform-plugin-framework/types"
@@ -48,30 +47,27 @@ func (r *httpResource) Metadata(_ context.Context, _ resource.MetadataRequest, r
4847func (r * httpResource ) Schema (ctx context.Context , req resource.SchemaRequest , resp * resource.SchemaResponse ) {
4948 resp .Schema = rs.Schema {
5049 Description : `
51- The ` + "`http`" + ` resource makes an HTTP request to the given URL and exports
52- information about the response.
50+ The ` + "`http`" + ` resource makes an HTTP request to the given URL and exports
51+ information about the response.
5352
54- The given URL may be either an ` + "`http`" + ` or ` + "`https`" + ` URL. This resource
55- will issue a warning if the result is not UTF-8 encoded.
53+ The given URL may be either an ` + "`http`" + ` or ` + "`https`" + ` URL. This resource
54+ will issue a warning if the result is not UTF-8 encoded.
5655
57- ~> **Important** Although ` + "`https`" + ` URLs can be used, there is currently no
58- mechanism to authenticate the remote server except for general verification of
59- the server certificate's chain of trust. Data retrieved from servers not under
60- your control should be treated as untrustworthy.
56+ ~> **Important** Although ` + "`https`" + ` URLs can be used, there is currently no
57+ mechanism to authenticate the remote server except for general verification of
58+ the server certificate's chain of trust. Data retrieved from servers not under
59+ your control should be treated as untrustworthy.
6160
62- By default, there are no retries. Configuring the retry block will result in
63- retries if an error is returned by the client (e.g., connection errors) or if
64- a 5xx-range (except 501) status code is received. For further details see
65- [go-retryablehttp](https://pkg.go.dev/github.com/hashicorp/go-retryablehttp).
66- ` ,
61+ By default, there are no retries. Configuring the retry block will result in
62+ retries if an error is returned by the client (e.g., connection errors) or if
63+ a 5xx-range (except 501) status code is received. For further details see
64+ [go-retryablehttp](https://pkg.go.dev/github.com/hashicorp/go-retryablehttp).
65+ ` ,
6766
6867 Attributes : map [string ]rs.Attribute {
6968 "id" : rs.StringAttribute {
7069 Description : "The URL used for the request." ,
7170 Computed : true ,
72- PlanModifiers : []planmodifier.String {
73- stringplanmodifier .UseStateForUnknown (),
74- },
7571 },
7672
7773 "url" : rs.StringAttribute {
@@ -117,6 +113,13 @@ a 5xx-range (except 501) status code is received. For further details see
117113 Computed : true ,
118114 },
119115
116+ "body" : rs.StringAttribute {
117+ Description : "The response body returned as a string. " +
118+ "**NOTE**: This is deprecated, use `response_body` instead." ,
119+ Computed : true ,
120+ DeprecationMessage : "Use response_body instead" ,
121+ },
122+
120123 "response_body_base64" : rs.StringAttribute {
121124 Description : "The response body encoded as base64 (standard) as defined in [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648#section-4)." ,
122125 Computed : true ,
@@ -225,9 +228,6 @@ func (r *httpResource) Read(ctx context.Context, req resource.ReadRequest, resp
225228 if resp .Diagnostics .HasError () {
226229 return
227230 }
228- if err := r .performRequest (ctx , & model , & resp .Diagnostics ); err != nil {
229- return
230- }
231231 diags = resp .State .Set (ctx , model )
232232 resp .Diagnostics .Append (diags ... )
233233}
@@ -250,7 +250,7 @@ func (r *httpResource) Delete(ctx context.Context, req resource.DeleteRequest, r
250250 // No remote deletion; removing from state is sufficient.
251251}
252252
253- func (r * httpResource ) performRequest (ctx context.Context , model * modelV0 , diags * resource .Diagnostics ) error {
253+ func (r * httpResource ) performRequest (ctx context.Context , model * modelV0 , diags * diag .Diagnostics ) error {
254254 requestURL := model .URL .ValueString ()
255255 method := model .Method .ValueString ()
256256 requestHeaders := model .RequestHeaders
@@ -443,10 +443,9 @@ func (r *httpResource) performRequest(ctx context.Context, model *modelV0, diags
443443 model .ID = types .StringValue (requestURL )
444444 model .ResponseHeaders = respHeadersState
445445 model .ResponseBody = types .StringValue (responseBody )
446+ model .Body = types .StringValue (responseBody )
446447 model .ResponseBodyBase64 = types .StringValue (responseBodyBase64Std )
447448 model .StatusCode = types .Int64Value (int64 (response .StatusCode ))
448449
449450 return nil
450451}
451-
452-
0 commit comments