diff --git a/CHANGELOG.md b/CHANGELOG.md index 33afe8a..e148865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,4 +2,6 @@ initial commit@ v 5...why not ## 1.2.5 (May 30, 2022) * add timeout -* add insecure_skip_verify \ No newline at end of file +* 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)). diff --git a/docs/data-sources/http.md b/docs/data-sources/http.md index 4e4a3be..6434377 100644 --- a/docs/data-sources/http.md +++ b/docs/data-sources/http.md @@ -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 diff --git a/internal/provider/data_source.go b/internal/provider/data_source.go index b4198f4..bdd93df 100644 --- a/internal/provider/data_source.go +++ b/internal/provider/data_source.go @@ -46,9 +46,6 @@ func dataSource() *schema.Resource { "url": { Type: schema.TypeString, Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, }, "method": { @@ -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, @@ -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)...) } diff --git a/internal/provider/data_source_test.go b/internal/provider/data_source_test.go index eb2d11c..08c8434 100644 --- a/internal/provider/data_source_test.go +++ b/internal/provider/data_source_test.go @@ -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" { @@ -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" { @@ -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" { @@ -164,7 +171,7 @@ data "http" "http_test" { } output "body" { - value = data.http.http_test.body + value = data.http.http_test.response_body } ` @@ -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, ) } @@ -210,7 +217,7 @@ output "status_code" { } output "body" { - value = "${data.http.http_test.body}" + value = "${data.http.http_test.response_body}" } ` @@ -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, ) } @@ -267,7 +274,7 @@ data "http" "http_test" { } output "body" { - value = "${data.http.http_test.body}" + value = "${data.http.http_test.response_body}" } ` @@ -302,7 +309,7 @@ data "http" "http_test" { } output "body" { - value = "${data.http.http_test.body}" + value = "${data.http.http_test.response_body}" } ` @@ -336,7 +343,7 @@ data "http" "http_test" { } output "body" { - value = "${data.http.http_test.body}" + value = "${data.http.http_test.response_body}" } ` @@ -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, ) } @@ -387,7 +394,7 @@ data "http" "http_test" { } output "body" { - value = "${data.http.http_test.body}" + value = "${data.http.http_test.response_body}" } ` @@ -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, ) } @@ -546,7 +553,7 @@ data "http" "http_test" { } output "body" { - value = "${data.http.http_test.body}" + value = "${data.http.http_test.response_body}" } ` @@ -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, ) } @@ -713,7 +720,7 @@ data "http" "http_test" { } output "body" { - value = "${data.http.http_test.body}" + value = "${data.http.http_test.response_body}" } ` @@ -739,7 +746,7 @@ data "http" "http_test" { } output "body" { - value = "${data.http.http_test.body}" + value = "${data.http.http_test.response_body}" } ` @@ -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, ) } @@ -783,7 +790,7 @@ data "http" "http_test" { } output "body" { - value = "${data.http.http_test.body}" + value = "${data.http.http_test.response_body}" } ` @@ -849,7 +856,7 @@ data "http" "http_test" { } output "body" { - value = "${data.http.http_test.body}" + value = "${data.http.http_test.response_body}" } ` @@ -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, ) }