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. This resource will issue a warning if the result is not UTF-8 encoded.

By default, there are no retries. Configuring the retry block will result in retries if an error is returned by the client (e.g., connection errors) or if a 5xx-range (except 501) status code is received. For further details see go-retryablehttp.

Example Usage

// DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug
import { Construct } from "constructs";
import { TerraformStack } from "cdktf";
/*
 * Provider bindings are generated by running `cdktf get`.
 * See https://cdk.tf/provider-generation for more details.
 */
import { DataHttp } from "./.gen/providers/http/";
class MyConvertedCode extends TerraformStack {
  constructor(scope: Construct, name: string) {
    super(scope, name);
    new DataHttp(this, "example", {
      request_headers: [
        {
          Accept: "application/json",
        },
      ],
      url: "https://checkpoint-api.hashicorp.com/v1/check/terraform",
    });
    new DataHttp(this, "example_head", {
      method: "HEAD",
      url: "https://checkpoint-api.hashicorp.com/v1/check/terraform",
    });
    new DataHttp(this, "example_post", {
      method: "POST",
      request_body: "request body",
      url: "https://checkpoint-api.hashicorp.com/v1/check/terraform",
    });
  }
}

Usage with Postcondition

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

// DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug
import { Construct } from "constructs";
import { TerraformSelf, Fn, TerraformStack } from "cdktf";
/*
 * Provider bindings are generated by running `cdktf get`.
 * See https://cdk.tf/provider-generation for more details.
 */
import { DataHttp } from "./.gen/providers/http/";
class MyConvertedCode extends TerraformStack {
  constructor(scope: Construct, name: string) {
    super(scope, name);
    new DataHttp(this, "example", {
      lifecycle: {
        postcondition: [
          {
            condition: Fn.contains(
              [201, 204],
              TerraformSelf.getAny("status_code")
            ),
            errorMessage: "Status code invalid",
          },
        ],
      },
      request_headers: [
        {
          Accept: "application/json",
        },
      ],
      url: "https://checkpoint-api.hashicorp.com/v1/check/terraform",
    });
  }
}

Usage with Precondition

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

// DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug
import { Construct } from "constructs";
import { Fn, TerraformStack } from "cdktf";
/*
 * Provider bindings are generated by running `cdktf get`.
 * See https://cdk.tf/provider-generation for more details.
 */
import { DataHttp } from "./.gen/providers/http/";
import { Uuid } from "./.gen/providers/random/uuid";
class MyConvertedCode extends TerraformStack {
  constructor(scope: Construct, name: string) {
    super(scope, name);
    const dataHttpExample = new DataHttp(this, "example", {
      request_headers: [
        {
          Accept: "application/json",
        },
      ],
      url: "https://checkpoint-api.hashicorp.com/v1/check/terraform",
    });
    const randomUuidExample = new Uuid(this, "example_1", {
      lifecycle: {
        precondition: [
          {
            condition: Fn.contains([201, 204], dataHttpExample.statusCode),
            errorMessage: "Status code invalid",
          },
        ],
      },
    });
    /*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
    randomUuidExample.overrideLogicalId("example");
  }
}

Usage with Provisioner

Failure Behaviour can be leveraged within a provisioner in order to raise an error and stop applying.

// DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug
import { Construct } from "constructs";
import { Fn, TerraformStack } from "cdktf";
/*
 * Provider bindings are generated by running `cdktf get`.
 * See https://cdk.tf/provider-generation for more details.
 */
import { Resource } from "./.gen/providers/null/resource";
import { DataHttp } from "./.gen/providers/http/";
class MyConvertedCode extends TerraformStack {
  constructor(scope: Construct, name: string) {
    super(scope, name);
    const dataHttpExample = new DataHttp(this, "example", {
      request_headers: [
        {
          Accept: "application/json",
        },
      ],
      url: "https://checkpoint-api.hashicorp.com/v1/check/terraform",
    });
    const nullProviderResourceExample = new Resource(this, "example_1", {
      provisioners: [
        {
          type: "local-exec",
          command: Fn.contains([201, 204], dataHttpExample.statusCode),
        },
      ],
    });
    /*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
    nullProviderResourceExample.overrideLogicalId("example");
  }
}

Schema

Required

Optional

Read-Only

Nested Schema for retry

Optional: