diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dc54708..6ee93140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## 2.2.0 (June 02, 2022) + +ENHANCEMENTS: + +* data-source/http: `body` is now deprecated and has been superseded by `response_body`. `body` will be removed in the next major release ([#137](https://github.com/hashicorp/terraform-provider-http/pull/137)). + +NOTES: + +* "Uplift" aligned with Utility Providers Upgrade ([#135](https://github.com/hashicorp/terraform-provider-http/issues/135)). + ## 2.1.0 (February 19, 2021) Binary releases of this provider now include the darwin-arm64 platform. This version contains no further changes. diff --git a/docs/data-sources/http.md b/docs/data-sources/http.md index 368af5e2..c2819df1 100644 --- a/docs/data-sources/http.md +++ b/docs/data-sources/http.md @@ -58,8 +58,9 @@ data "http" "example" { ### Read-Only -- `body` (String) The response body returned as a string. +- `body` (String, Deprecated) The response body returned as a string. **NOTE**: This is deprecated, use `response_body` instead. - `id` (String) The ID of this resource. +- `response_body` (String) The response body returned as a string. - `response_headers` (Map of String) A map of response header field names and values. Duplicate headers are concatenated with according to [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2). diff --git a/internal/provider/data_source.go b/internal/provider/data_source.go index c11e54b9..75fc8508 100644 --- a/internal/provider/data_source.go +++ b/internal/provider/data_source.go @@ -35,9 +35,6 @@ your control should be treated as untrustworthy.`, Description: "The URL for the request. Supported schemes are `http` and `https`.", Type: schema.TypeString, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, }, "request_headers": { @@ -50,12 +47,17 @@ your control should be treated as untrustworthy.`, }, "body": { + Description: "The response body returned as a string. " + + "**NOTE**: This is deprecated, use `response_body` instead.", + Type: schema.TypeString, + Computed: true, + Deprecated: "Use response_body instead", + }, + + "response_body": { Description: "The response body returned as a string.", Type: schema.TypeString, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, }, "response_headers": { @@ -122,6 +124,10 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{ return append(diags, diag.Errorf("Error setting HTTP response body: %s", err)...) } + if err = d.Set("response_body", string(bytes)); err != nil { + return append(diags, diag.Errorf("Error setting HTTP response body: %s", err)...) + } + if err = d.Set("response_headers", responseHeaders); err != nil { return append(diags, diag.Errorf("Error setting HTTP response headers: %s", err)...) } diff --git a/internal/provider/data_source_test.go b/internal/provider/data_source_test.go index 26a12111..8c032a67 100644 --- a/internal/provider/data_source_test.go +++ b/internal/provider/data_source_test.go @@ -22,6 +22,7 @@ func TestDataSource_http200(t *testing.T) { Config: fmt.Sprintf(testDataSourceConfigBasic, testHttpMock.server.URL, 200), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.http.http_test", "body", "1.0.0"), + resource.TestCheckResourceAttr("data.http.http_test", "response_body", "1.0.0"), resource.TestCheckResourceAttr("data.http.http_test", "response_headers.X-Single", "foobar"), resource.TestCheckResourceAttr("data.http.http_test", "response_headers.X-Double", "1, 2"), ), @@ -58,6 +59,7 @@ func TestDataSource_withHeaders200(t *testing.T) { Config: fmt.Sprintf(testDataSourceConfigWithHeaders, testHttpMock.server.URL, 200), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.http.http_test", "body", "1.0.0"), + resource.TestCheckResourceAttr("data.http.http_test", "response_body", "1.0.0"), ), }, }, @@ -76,6 +78,7 @@ func TestDataSource_utf8(t *testing.T) { Config: fmt.Sprintf(testDataSourceConfigUTF8, testHttpMock.server.URL, 200), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.http.http_test", "body", "1.0.0"), + resource.TestCheckResourceAttr("data.http.http_test", "response_body", "1.0.0"), ), }, },