diff --git a/datasource/http/data.go b/datasource/http/data.go index f31172148..e94e153ad 100644 --- a/datasource/http/data.go +++ b/datasource/http/data.go @@ -21,10 +21,10 @@ import ( type Config struct { common.PackerConfig `mapstructure:",squash"` - // The URL to request data from. This URL must respond with a `200 OK` response and a `text/*` or `application/json` Content-Type + // The URL to request data from. This URL must respond with a `200 OK` response and a `text/*` or `application/json` Content-Type. Url string `mapstructure:"url" required:"true"` // A map of strings representing additional HTTP headers to include in the request. - Request_headers map[string]string `mapstructure:"request_headers" required:"false"` + RequestHeaders map[string]string `mapstructure:"request_headers" required:"false"` } type Datasource struct { @@ -32,13 +32,13 @@ type Datasource struct { } type DatasourceOutput struct { - // The URL the data was requested from. - Url string `mapstructure:"url"` + // The URL the data was requested from. + Url string `mapstructure:"url"` // The raw body of the HTTP response. - Response_body string `mapstructure:"body"` - // A map of strings representing the response HTTP headers. - // Duplicate headers are contatenated with , according to [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2) - Response_headers map[string]string `mapstructure:"request_headers"` + ResponseBody string `mapstructure:"body"` + // A map of strings representing the response HTTP headers. + // Duplicate headers are concatenated with, according to [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2). + ResponseHeaders map[string]string `mapstructure:"request_headers"` } func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { @@ -99,7 +99,7 @@ func isContentTypeText(contentType string) bool { // https://github.com/hashicorp/terraform-provider-http/blob/main/internal/provider/data_source.go func (d *Datasource) Execute() (cty.Value, error) { ctx := context.TODO() - url, headers := d.config.Url, d.config.Request_headers + url, headers := d.config.Url, d.config.RequestHeaders client := &http.Client{} req, err := http.NewRequestWithContext(ctx, "GET", url, nil) @@ -149,9 +149,9 @@ func (d *Datasource) Execute() (cty.Value, error) { } output := DatasourceOutput{ - Url: d.config.Url, - Response_headers: responseHeaders, - Response_body: string(bytes), + Url: d.config.Url, + ResponseHeaders: responseHeaders, + ResponseBody: string(bytes), } return hcl2helper.HCL2ValueFromConfig(output, d.OutputSpec()), nil } diff --git a/datasource/http/data.hcl2spec.go b/datasource/http/data.hcl2spec.go index 07d3b6b81..fb9bfc616 100644 --- a/datasource/http/data.hcl2spec.go +++ b/datasource/http/data.hcl2spec.go @@ -19,7 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` Url *string `mapstructure:"url" required:"true" cty:"url" hcl:"url"` - Request_headers map[string]string `mapstructure:"request_headers" required:"false" cty:"request_headers" hcl:"request_headers"` + RequestHeaders map[string]string `mapstructure:"request_headers" required:"false" cty:"request_headers" hcl:"request_headers"` } // FlatMapstructure returns a new FlatConfig. @@ -51,9 +51,9 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { // FlatDatasourceOutput is an auto-generated flat version of DatasourceOutput. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatDatasourceOutput struct { - Url *string `mapstructure:"url" cty:"url" hcl:"url"` - Response_body *string `mapstructure:"body" cty:"body" hcl:"body"` - Response_headers map[string]string `mapstructure:"request_headers" cty:"request_headers" hcl:"request_headers"` + Url *string `mapstructure:"url" cty:"url" hcl:"url"` + ResponseBody *string `mapstructure:"body" cty:"body" hcl:"body"` + ResponseHeaders map[string]string `mapstructure:"request_headers" cty:"request_headers" hcl:"request_headers"` } // FlatMapstructure returns a new FlatDatasourceOutput. diff --git a/website/content/docs/datasources/http.mdx b/website/content/docs/datasources/http.mdx index e5140f9fb..12903eb5d 100644 --- a/website/content/docs/datasources/http.mdx +++ b/website/content/docs/datasources/http.mdx @@ -1,6 +1,6 @@ --- description: | - The http Data Source retrieves information from an http endpoint to be used + The HTTP Data Source retrieves information from an http endpoint to be used during Packer builds page_title: Http - Data Sources --- @@ -19,7 +19,7 @@ The `http` data source makes an HTTP GET request to the given URL and exports in ## Basic Example -```hcl +```hcl data "http" "example" { url = "https://checkpoint-api.hashicorp.com/v1/check/terraform" @@ -28,6 +28,7 @@ data "http" "example" { Accept = "application/json" } } +``` ## Configuration Reference diff --git a/website/content/partials/datasource/http/Config-not-required.mdx b/website/content/partials/datasource/http/Config-not-required.mdx index 1344f2aae..24814625f 100644 --- a/website/content/partials/datasource/http/Config-not-required.mdx +++ b/website/content/partials/datasource/http/Config-not-required.mdx @@ -1,5 +1,5 @@ -- `request_headers` (map[string]string) - Request headers for call +- `request_headers` (map[string]string) - A map of strings representing additional HTTP headers to include in the request. diff --git a/website/content/partials/datasource/http/Config-required.mdx b/website/content/partials/datasource/http/Config-required.mdx index f40d0df69..a9cc5183b 100644 --- a/website/content/partials/datasource/http/Config-required.mdx +++ b/website/content/partials/datasource/http/Config-required.mdx @@ -1,5 +1,5 @@ -- `url` (string) - Url where should be getting things from +- `url` (string) - The URL to request data from. This URL must respond with a `200 OK` response and a `text/*` or `application/json` Content-Type. diff --git a/website/content/partials/datasource/http/DatasourceOutput.mdx b/website/content/partials/datasource/http/DatasourceOutput.mdx index bdafc1249..8581fa962 100644 --- a/website/content/partials/datasource/http/DatasourceOutput.mdx +++ b/website/content/partials/datasource/http/DatasourceOutput.mdx @@ -1,9 +1,10 @@ -- `url` (string) - Url +- `url` (string) - The URL the data was requested from. -- `body` (string) - Response _ body +- `body` (string) - The raw body of the HTTP response. -- `request_headers` (map[string]string) - Response _ headers +- `request_headers` (map[string]string) - A map of strings representing the response HTTP headers. + Duplicate headers are concatenated with, according to [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2).