Skip to content

Commit

Permalink
Deprecating body and replacing with response_body
Browse files Browse the repository at this point in the history
* Deprecating body and replacing with response_body

* Updating docs and CHANGELOG.md

* Removing unneeded Elem from Schema

(cherry picked from hashicorp/terraform-provider-http#137)
  • Loading branch information
orgads committed Sep 5, 2022
1 parent 99b66a7 commit 6829312
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 44 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
initial commit@ v 5...why not
## 1.2.5 (May 30, 2022)
* add timeout
* add insecure_skip_verify
* add insecure_skip_verify
## 1.3.1 (Sep 05, 2022)
* data-source/http: `body` is now deprecated and has been superseded by `response_body`. `body` will be removed in the next major release ([#11](https://github.com/salrashid123/terraform-provider-http-full/pull/11)).
4 changes: 3 additions & 1 deletion docs/data-sources/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ The following attributes are exported:

* `status_code` - The status_code of the HTTP response if not error

* `body` - The raw body of the HTTP response.
* `body` (String, Deprecated) The raw body of the HTTP response. **NOTE**: This is deprecated, use `response_body` instead.

* `response_body` (String) The raw body of the HTTP response.

* `response_headers` - A map of strings representing the response HTTP headers.
Duplicate headers are concatenated with `, ` according to
Expand Down
23 changes: 15 additions & 8 deletions internal/provider/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ func dataSource() *schema.Resource {
"url": {
Type: schema.TypeString,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"method": {
Expand Down Expand Up @@ -79,11 +76,17 @@ func dataSource() *schema.Resource {
},

"body": {
Type: schema.TypeString,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The raw body of the HTTP response. " +
"**NOTE**: This is deprecated, use `response_body` instead.",
Type: schema.TypeString,
Computed: true,
Deprecated: "Use response_body instead",
},

"response_body": {
Description: "The raw body of the HTTP response.",
Type: schema.TypeString,
Computed: true,
},
"sni": {
Type: schema.TypeString,
Expand Down Expand Up @@ -282,6 +285,10 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{
return append(diags, diag.Errorf("Error setting HTTP status_code: %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
75 changes: 41 additions & 34 deletions internal/provider/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data "http" "http_test" {
}
output "body" {
value = data.http.http_test.body
value = data.http.http_test.response_body
}
output "response_headers" {
Expand Down Expand Up @@ -62,6 +62,13 @@ func TestDataSource_http200(t *testing.T) {
)
}

if outputs["response_body"].Value != "1.0.0" {
return fmt.Errorf(
`'response_body' output is %s; want '1.0.0'`,
outputs["response_body"].Value,
)
}

response_headers := outputs["response_headers"].Value.(map[string]interface{})

if response_headers["X-Single"].(string) != "foobar" {
Expand Down Expand Up @@ -130,7 +137,7 @@ data "http" "http_test" {
}
output "body" {
value = data.http.http_test.body
value = data.http.http_test.response_body
}
output "response_headers" {
Expand Down Expand Up @@ -164,7 +171,7 @@ data "http" "http_test" {
}
output "body" {
value = data.http.http_test.body
value = data.http.http_test.response_body
}
`

Expand All @@ -186,10 +193,10 @@ func TestDataSource_withHeaders200(t *testing.T) {

outputs := s.RootModule().Outputs

if outputs["body"].Value != "1.0.0" {
if outputs["response_body"].Value != "1.0.0" {
return fmt.Errorf(
`'body' output is %s; want '1.0.0'`,
outputs["body"].Value,
`'response_body' output is %s; want '1.0.0'`,
outputs["response_body"].Value,
)
}

Expand All @@ -210,7 +217,7 @@ output "status_code" {
}
output "body" {
value = "${data.http.http_test.body}"
value = "${data.http.http_test.response_body}"
}
`

Expand Down Expand Up @@ -247,10 +254,10 @@ func TestDataSource_utf8(t *testing.T) {
)
}

if outputs["body"].Value != "1.0.0" {
if outputs["response_body"].Value != "1.0.0" {
return fmt.Errorf(
`'body' output is %s; want '1.0.0'`,
outputs["body"].Value,
`'response_body' output is %s; want '1.0.0'`,
outputs["response_body"].Value,
)
}

Expand All @@ -267,7 +274,7 @@ data "http" "http_test" {
}
output "body" {
value = "${data.http.http_test.body}"
value = "${data.http.http_test.response_body}"
}
`

Expand Down Expand Up @@ -302,7 +309,7 @@ data "http" "http_test" {
}
output "body" {
value = "${data.http.http_test.body}"
value = "${data.http.http_test.response_body}"
}
`

Expand Down Expand Up @@ -336,7 +343,7 @@ data "http" "http_test" {
}
output "body" {
value = "${data.http.http_test.body}"
value = "${data.http.http_test.response_body}"
}
`

Expand All @@ -361,10 +368,10 @@ func TestDataSource_post(t *testing.T) {

outputs := s.RootModule().Outputs

if outputs["body"].Value != "1.0.0" {
if outputs["response_body"].Value != "1.0.0" {
return fmt.Errorf(
`'body' output is %s; want '1.0.0'`,
outputs["body"].Value,
`'response_body' output is %s; want '1.0.0'`,
outputs["response_body"].Value,
)
}

Expand All @@ -387,7 +394,7 @@ data "http" "http_test" {
}
output "body" {
value = "${data.http.http_test.body}"
value = "${data.http.http_test.response_body}"
}
`

Expand All @@ -412,10 +419,10 @@ func TestDataSource_form_post(t *testing.T) {

outputs := s.RootModule().Outputs

if outputs["body"].Value != "1.0.0" {
if outputs["response_body"].Value != "1.0.0" {
return fmt.Errorf(
`'body' output is %s; want '1.0.0'`,
outputs["body"].Value,
`'response_body' output is %s; want '1.0.0'`,
outputs["response_body"].Value,
)
}

Expand Down Expand Up @@ -546,7 +553,7 @@ data "http" "http_test" {
}
output "body" {
value = "${data.http.http_test.body}"
value = "${data.http.http_test.response_body}"
}
`

Expand Down Expand Up @@ -614,10 +621,10 @@ func TestDataSource_mtls(t *testing.T) {

outputs := s.RootModule().Outputs

if outputs["body"].Value != "1.0.0" {
if outputs["response_body"].Value != "1.0.0" {
return fmt.Errorf(
`'body' output is %s; want '1.0.0'`,
outputs["body"].Value,
`'response_body' output is %s; want '1.0.0'`,
outputs["response_body"].Value,
)
}

Expand Down Expand Up @@ -713,7 +720,7 @@ data "http" "http_test" {
}
output "body" {
value = "${data.http.http_test.body}"
value = "${data.http.http_test.response_body}"
}
`

Expand All @@ -739,7 +746,7 @@ data "http" "http_test" {
}
output "body" {
value = "${data.http.http_test.body}"
value = "${data.http.http_test.response_body}"
}
`

Expand All @@ -761,10 +768,10 @@ func TestDataSource_skip_tls_verify_success(t *testing.T) {

outputs := s.RootModule().Outputs

if outputs["body"].Value != "1.0.0" {
if outputs["response_body"].Value != "1.0.0" {
return fmt.Errorf(
`'body' output is %s; want '1.0.0'`,
outputs["body"].Value,
`'response_body' output is %s; want '1.0.0'`,
outputs["response_body"].Value,
)
}

Expand All @@ -783,7 +790,7 @@ data "http" "http_test" {
}
output "body" {
value = "${data.http.http_test.body}"
value = "${data.http.http_test.response_body}"
}
`

Expand Down Expand Up @@ -849,7 +856,7 @@ data "http" "http_test" {
}
output "body" {
value = "${data.http.http_test.body}"
value = "${data.http.http_test.response_body}"
}
`

Expand Down Expand Up @@ -909,10 +916,10 @@ func TestDataSource_sni_success(t *testing.T) {

outputs := s.RootModule().Outputs

if outputs["body"].Value != "1.0.0" {
if outputs["response_body"].Value != "1.0.0" {
return fmt.Errorf(
`'body' output is %s; want '1.0.0'`,
outputs["body"].Value,
`'response_body' output is %s; want '1.0.0'`,
outputs["response_body"].Value,
)
}

Expand Down

0 comments on commit 6829312

Please sign in to comment.