Skip to content

Commit

Permalink
Deprecating body and replacing with response_body (hashicorp#137)
Browse files Browse the repository at this point in the history
* Deprecating body and replacing with response_body

* Updating docs and CHANGELOG.md

* Rewording CHANGELOG.md

* Removing unneeded Elem from Schema

* Adding date to CHANGELOG.md
  • Loading branch information
bendbennett authored Jun 2, 2022
1 parent a9a1d6e commit 186887f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion docs/data-sources/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).


18 changes: 12 additions & 6 deletions internal/provider/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down Expand Up @@ -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)...)
}
Expand Down
3 changes: 3 additions & 0 deletions internal/provider/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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"),
),
},
},
Expand All @@ -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"),
),
},
},
Expand Down

0 comments on commit 186887f

Please sign in to comment.