|
| 1 | +--- |
| 2 | +page_title: "http Resource - terraform-provider-http" |
| 3 | +subcategory: "" |
| 4 | +description: |- |
| 5 | + The http resource makes an HTTP request to the given URL and exports |
| 6 | + information about the response. |
| 7 | + The given URL may be either an http or https URL. This resource |
| 8 | + will issue a warning if the result is not UTF-8 encoded. |
| 9 | + ~> Important Although https URLs can be used, there is currently no |
| 10 | + mechanism to authenticate the remote server except for general verification of |
| 11 | + the server certificate's chain of trust. Data retrieved from servers not under |
| 12 | + your control should be treated as untrustworthy. |
| 13 | + By default, there are no retries. Configuring the retry block will result in |
| 14 | + retries if an error is returned by the client (e.g., connection errors) or if |
| 15 | + a 5xx-range (except 501) status code is received. For further details see |
| 16 | + go-retryablehttp https://pkg.go.dev/github.com/hashicorp/go-retryablehttp. |
| 17 | +--- |
| 18 | + |
| 19 | + |
| 20 | +<!-- Please do not edit this file, it is generated. --> |
| 21 | +# http (Resource) |
| 22 | + |
| 23 | +The `http` resource makes an HTTP request to the given URL and exports |
| 24 | +information about the response. |
| 25 | + |
| 26 | +The given URL may be either an `http` or `https` URL. This resource |
| 27 | +will issue a warning if the result is not UTF-8 encoded. |
| 28 | + |
| 29 | +~> **Important** Although `https` URLs can be used, there is currently no |
| 30 | +mechanism to authenticate the remote server except for general verification of |
| 31 | +the server certificate's chain of trust. Data retrieved from servers not under |
| 32 | +your control should be treated as untrustworthy. |
| 33 | + |
| 34 | +By default, there are no retries. Configuring the retry block will result in |
| 35 | +retries if an error is returned by the client (e.g., connection errors) or if |
| 36 | +a 5xx-range (except 501) status code is received. For further details see |
| 37 | +[go-retryablehttp](https://pkg.go.dev/github.com/hashicorp/go-retryablehttp). |
| 38 | + |
| 39 | +## Example Usage |
| 40 | + |
| 41 | +```python |
| 42 | +# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug |
| 43 | +from constructs import Construct |
| 44 | +from cdktf import TerraformStack |
| 45 | +# |
| 46 | +# Provider bindings are generated by running `cdktf get`. |
| 47 | +# See https://cdk.tf/provider-generation for more details. |
| 48 | +# |
| 49 | +from imports.http. import ResourceHttp |
| 50 | +class MyConvertedCode(TerraformStack): |
| 51 | + def __init__(self, scope, name): |
| 52 | + super().__init__(scope, name) |
| 53 | + ResourceHttp(self, "example", |
| 54 | + request_headers=[{ |
| 55 | + "Accept": "application/json" |
| 56 | + } |
| 57 | + ], |
| 58 | + url="https://checkpoint-api.hashicorp.com/v1/check/terraform" |
| 59 | + ) |
| 60 | + ResourceHttp(self, "example_head", |
| 61 | + method="HEAD", |
| 62 | + url="https://checkpoint-api.hashicorp.com/v1/check/terraform" |
| 63 | + ) |
| 64 | + ResourceHttp(self, "example_post", |
| 65 | + method="POST", |
| 66 | + request_body="request body", |
| 67 | + url="https://checkpoint-api.hashicorp.com/v1/check/terraform" |
| 68 | + ) |
| 69 | +``` |
| 70 | + |
| 71 | +## Controlling when the request is sent |
| 72 | + |
| 73 | +Use the resource argument `when` to control whether the HTTP request is executed during apply operations or only during destroy: |
| 74 | + |
| 75 | +- `apply` (default): request is executed during create and update. |
| 76 | +- `destroy`: request is executed only during resource destruction. |
| 77 | + |
| 78 | +```python |
| 79 | +# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug |
| 80 | +from constructs import Construct |
| 81 | +from cdktf import TerraformStack |
| 82 | +from imports.http. import ResourceHttp |
| 83 | +class MyConvertedCode(TerraformStack): |
| 84 | + def __init__(self, scope, name): |
| 85 | + super().__init__(scope, name) |
| 86 | + ResourceHttp(self, "cleanup", |
| 87 | + method="DELETE", |
| 88 | + url="https://api.example.com/cleanup", |
| 89 | + when="destroy" |
| 90 | + ) |
| 91 | +``` |
| 92 | + |
| 93 | +## Usage with Postcondition |
| 94 | + |
| 95 | +Note: Pre/postconditions validate values during apply. They are only meaningful when the resource executes the HTTP request during apply, i.e., when `when = "apply"` (default). If `when = "destroy"`, these conditions will not evaluate against a fresh request result. |
| 96 | + |
| 97 | +```python |
| 98 | +# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug |
| 99 | +from constructs import Construct |
| 100 | +from cdktf import TerraformSelf, Fn, TerraformStack |
| 101 | +# |
| 102 | +# Provider bindings are generated by running `cdktf get`. |
| 103 | +# See https://cdk.tf/provider-generation for more details. |
| 104 | +# |
| 105 | +from imports.http. import ResourceHttp |
| 106 | +class MyConvertedCode(TerraformStack): |
| 107 | + def __init__(self, scope, name): |
| 108 | + super().__init__(scope, name) |
| 109 | + ResourceHttp(self, "example", |
| 110 | + lifecycle={ |
| 111 | + "postcondition": [{ |
| 112 | + "condition": Fn.contains([201, 204], |
| 113 | + TerraformSelf.get_any("status_code")), |
| 114 | + "error_message": "Status code invalid" |
| 115 | + } |
| 116 | + ] |
| 117 | + }, |
| 118 | + request_headers=[{ |
| 119 | + "Accept": "application/json" |
| 120 | + } |
| 121 | + ], |
| 122 | + url="https://checkpoint-api.hashicorp.com/v1/check/terraform", |
| 123 | + when="apply" |
| 124 | + ) |
| 125 | +``` |
| 126 | + |
| 127 | +## Usage with Precondition |
| 128 | + |
| 129 | +Note: Pre/postconditions validate values during apply. They are only meaningful when the resource executes the HTTP request during apply, i.e., when `when = "apply"` (default). If `when = "destroy"`, these conditions will not evaluate against a fresh request result. |
| 130 | + |
| 131 | +```python |
| 132 | +# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug |
| 133 | +from constructs import Construct |
| 134 | +from cdktf import Fn, TerraformStack |
| 135 | +# |
| 136 | +# Provider bindings are generated by running `cdktf get`. |
| 137 | +# See https://cdk.tf/provider-generation for more details. |
| 138 | +# |
| 139 | +from imports.http. import ResourceHttp |
| 140 | +class MyConvertedCode(TerraformStack): |
| 141 | + def __init__(self, scope, name): |
| 142 | + super().__init__(scope, name) |
| 143 | + http_example = ResourceHttp(self, "example", |
| 144 | + request_headers=[{ |
| 145 | + "Accept": "application/json" |
| 146 | + } |
| 147 | + ], |
| 148 | + url="https://checkpoint-api.hashicorp.com/v1/check/terraform", |
| 149 | + when="apply" |
| 150 | + ) |
| 151 | + http_example.add_override("lifecycle.precondition", [{ |
| 152 | + "condition": Fn.contains([200, 201, 204], http_example.status_code), |
| 153 | + "error_message": "Unexpected status code" |
| 154 | + } |
| 155 | + ]) |
| 156 | +``` |
| 157 | + |
| 158 | +## Usage with Provisioner |
| 159 | + |
| 160 | +[Failure Behaviour](https://www.terraform.io/language/resources/provisioners/syntax#failure-behavior) |
| 161 | +can be leveraged within a provisioner in order to raise an error and stop applying. |
| 162 | + |
| 163 | +```python |
| 164 | +# DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug |
| 165 | +from constructs import Construct |
| 166 | +from cdktf import Fn, TerraformStack |
| 167 | +# |
| 168 | +# Provider bindings are generated by running `cdktf get`. |
| 169 | +# See https://cdk.tf/provider-generation for more details. |
| 170 | +# |
| 171 | +from imports.null.resource import Resource |
| 172 | +from imports.http. import ResourceHttp |
| 173 | +class MyConvertedCode(TerraformStack): |
| 174 | + def __init__(self, scope, name): |
| 175 | + super().__init__(scope, name) |
| 176 | + http_example = ResourceHttp(self, "example", |
| 177 | + request_headers=[{ |
| 178 | + "Accept": "application/json" |
| 179 | + } |
| 180 | + ], |
| 181 | + url="https://checkpoint-api.hashicorp.com/v1/check/terraform" |
| 182 | + ) |
| 183 | + null_provider_resource_example = Resource(self, "example_1", |
| 184 | + provisioners=[{ |
| 185 | + "type": "local-exec", |
| 186 | + "command": Fn.contains([201, 204], http_example.status_code) |
| 187 | + } |
| 188 | + ] |
| 189 | + ) |
| 190 | + # This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match. |
| 191 | + null_provider_resource_example.override_logical_id("example") |
| 192 | +``` |
| 193 | + |
| 194 | +<!-- schema generated by tfplugindocs --> |
| 195 | +## Schema |
| 196 | + |
| 197 | +### Required |
| 198 | + |
| 199 | +- `url` (String) The URL for the request. Supported schemes are `http` and `https`. |
| 200 | + |
| 201 | +### Optional |
| 202 | + |
| 203 | +- `ca_cert_pem` (String) Certificate Authority (CA) in [PEM (RFC 1421)](https://datatracker.ietf.org/doc/html/rfc1421) format. |
| 204 | +- `client_cert_pem` (String) Client certificate in [PEM (RFC 1421)](https://datatracker.ietf.org/doc/html/rfc1421) format. |
| 205 | +- `client_key_pem` (String) Client key in [PEM (RFC 1421)](https://datatracker.ietf.org/doc/html/rfc1421) format. |
| 206 | +- `insecure` (Boolean) Disables verification of the server's certificate chain and hostname. Defaults to `false` |
| 207 | +- `method` (String) The HTTP Method for the request. Allowed methods are a subset of methods defined in [RFC7231](https://datatracker.ietf.org/doc/html/rfc7231#section-4.3) namely, `GET`, `HEAD`, and `POST`. `POST` support is only intended for read-only URLs, such as submitting a search. |
| 208 | +- `request_body` (String) The request body as a string. |
| 209 | +- `request_headers` (Map of String) A map of request header field names and values. |
| 210 | +- `request_timeout_ms` (Number) The request timeout in milliseconds. |
| 211 | +- `retry` (Block, Optional) Retry request configuration. By default there are no retries. Configuring this 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](https://pkg.go.dev/github.com/hashicorp/go-retryablehttp). (see [below for nested schema](#nestedblock--retry)) |
| 212 | +- `when` (String) When to send the HTTP request. Valid values are `apply` (default) and `destroy`. When set to `apply`, the request is sent during resource creation and updates. When set to `destroy`, the request is only sent during resource destruction. |
| 213 | + |
| 214 | +### Read-Only |
| 215 | + |
| 216 | +- `body` (String, Deprecated) The response body returned as a string. **NOTE**: This is deprecated, use `response_body` instead. |
| 217 | +- `id` (String) The URL used for the request. |
| 218 | +- `response_body` (String) The response body returned as a string. |
| 219 | +- `response_body_base64` (String) The response body encoded as base64 (standard) as defined in [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648#section-4). |
| 220 | +- `response_headers` (Map of String) A map of response header field names and values. Duplicate headers are concatenated according to [RFC2616](https://www.rfc-editor.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2). |
| 221 | +- `status_code` (Number) The HTTP response status code. |
| 222 | + |
| 223 | +<a id="nestedblock--retry"></a> |
| 224 | +### Nested Schema for `retry` |
| 225 | + |
| 226 | +Optional: |
| 227 | + |
| 228 | +- `attempts` (Number) The number of times the request is to be retried. For example, if 2 is specified, the request will be tried a maximum of 3 times. |
| 229 | +- `max_delay_ms` (Number) The maximum delay between retry requests in milliseconds. |
| 230 | +- `min_delay_ms` (Number) The minimum delay between retry requests in milliseconds. |
| 231 | +<!-- cache-key: cdktf-0.20.8 input-resource-http-py --> |
| 232 | + |
| 233 | + |
0 commit comments