Skip to content

Latest commit

 

History

History
111 lines (87 loc) · 3.43 KB

File metadata and controls

111 lines (87 loc) · 3.43 KB
page_title subcategory description
http Data Source - terraform-provider-http
The http data source makes an HTTP GET request to the given URL and exports information about the response. The given URL may be either an http or https URL. At present this resource can only retrieve data from URLs that respond with text/* or application/json content types, and expects the result to be UTF-8 encoded regardless of the returned content type header. ~> Important Although https URLs can be used, there is currently no mechanism to authenticate the remote server except for general verification of the server certificate's chain of trust. Data retrieved from servers not under your control should be treated as untrustworthy.

http (Data Source)

The http data source makes an HTTP GET request to the given URL and exports information about the response.

The given URL may be either an http or https URL. At present this resource can only retrieve data from URLs that respond with text/* or application/json content types, and expects the result to be UTF-8 encoded regardless of the returned content type header.

~> Important Although https URLs can be used, there is currently no mechanism to authenticate the remote server except for general verification of the server certificate's chain of trust. Data retrieved from servers not under your control should be treated as untrustworthy.

Example Usage

# The following example shows how to issue an HTTP GET request supplying
# an optional request header.
data "http" "example" {
  url = "https://checkpoint-api.hashicorp.com/v1/check/terraform"

  # Optional request headers
  request_headers = {
    Accept = "application/json"
  }
}

Usage with Postcondition

Precondition and Postcondition checks are available with Terraform v1.2.0 and later.

data "http" "example" {
  url = "https://checkpoint-api.hashicorp.com/v1/check/terraform"

  # Optional request headers
  request_headers = {
    Accept = "application/json"
  }

  lifecycle {
    postcondition {
      condition     = contains([201, 204], self.status_code)
      error_message = "Status code invalid"
    }
  }
}

Usage with Precondition

Precondition and Postcondition checks are available with Terraform v1.2.0 and later.

data "http" "example" {
  url = "https://checkpoint-api.hashicorp.com/v1/check/terraform"

  # Optional request headers
  request_headers = {
    Accept = "application/json"
  }
}

resource "random_uuid" "example" {
  lifecycle {
    precondition {
      condition     = contains([201, 204], data.http.example.status_code)
      error_message = "Status code invalid"
    }
  }
}

Schema

Required

  • url (String) The URL for the request. Supported schemes are http and https.

Optional

  • request_headers (Map of String) A map of request header field names and values.

Read-Only

  • 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 according to RFC2616.
  • status_code (Number) The HTTP response status code.