You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add delete-time destroy response templating for terracurl_request.
Resolve {response.<path>} placeholders from the stored create response at destroy time so APIs that return server-generated IDs can be deleted without Terraform self-references. Closes#125.
Co-authored-by: Cursor <cursoragent@cursor.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,9 @@
1
+
## 2.9.0
2
+
3
+
ENHANCEMENTS:
4
+
5
+
- Add delete-time `{response.<path>}` templating in `terracurl_request` destroy URL, body, headers, and query parameters, resolved from the stored create response. Includes create-time validation and supports nested JSON paths. Closes #125.
Use {response.path} placeholders in destroy configuration to inject values from the stored create response at delete time.
6
+
---
7
+
8
+
# Destroy Response Templating
9
+
10
+
Many REST APIs return a server-generated identifier when a resource is created. The delete API often requires that same identifier in the URL, request body, or query parameters. Terraform cannot reference a resource's own computed `response` attribute inside the same resource block, and TerraCurl reads destroy configuration from **stored state** at delete time rather than re-evaluating HCL expressions.
11
+
12
+
TerraCurl resolves **`{response.<path>}`** placeholders in destroy fields from the stored create response JSON when the resource is destroyed.
13
+
14
+
## When to use destroy templating
15
+
16
+
Use placeholders when:
17
+
18
+
- Create returns an ID (or other value) needed for delete
19
+
- The value lives in the create response JSON at a known path
20
+
- You manage create and destroy in a single `terracurl_request` resource
21
+
22
+
## Placeholder syntax
23
+
24
+
| Pattern | Meaning |
25
+
|---------|---------|
26
+
|`{response.id}`| Top-level `id` field in create response |
27
+
|`{response.data.uuid}`| Nested field using dot-separated path |
28
+
|`{response.items.0.id}`| Array element at index `0`|
29
+
30
+
`{response...}` refers to the **stored create response JSON**, not the Terraform resource `id` (which is always `name`).
31
+
32
+
Placeholders work in:
33
+
34
+
-`destroy_url`
35
+
-`destroy_request_body` and `destroy_request_body_wo`
36
+
-`destroy_request_parameters` (map values)
37
+
-`destroy_headers` and `destroy_headers_wo` (map values)
38
+
39
+
If a string contains no `{response.` substring, it is passed through unchanged.
After a successful create, TerraCurl validates that all `{response...}` placeholders in destroy configuration resolve against the create response. Mis-typed paths (for example `{response.uuid}` when the API returns `{response.id}`) fail at apply time instead of during a later destroy.
112
+
113
+
Validation is skipped when `skip_destroy = true`.
114
+
115
+
## Sensitive responses
116
+
117
+
When `response_sensitive = true`, placeholders resolve from `sensitive_response` in state. Template strings in destroy configuration remain in state as written; only the resolved values are sent on the wire at destroy time.
118
+
119
+
## Escaping literal braces
120
+
121
+
To include a literal `{response.id}` in a value without substitution, wrap the placeholder in double braces:
122
+
123
+
```text
124
+
{{response.id}}
125
+
```
126
+
127
+
This renders as `{response.id}` in the outbound request.
128
+
129
+
## Limitations
130
+
131
+
- Placeholders require a valid JSON create response stored in state
132
+
- Imported resources without a stored response cannot use destroy templating
133
+
- Paths must reference fields that remain after `ignore_response_fields` sanitization
134
+
- Only scalar values (string, number, boolean) can be substituted; objects and arrays as whole values are not supported
135
+
- Read-time templating for `read_url` / `read_request_body` is not supported in this release
136
+
137
+
## Related guides
138
+
139
+
-[Default Headers for Auth Tokens](default_headers) — refresh auth headers on every Terraform run, including destroy
140
+
-[Write-Only Headers and Request Bodies](write_only) — secrets in destroy bodies without persisting them in state
TerraCurl resolves `{response.<path>}` placeholders in destroy URL, body, headers, and query parameters from the stored create response at delete time. This supports APIs that return a server-generated ID needed for delete without Terraform self-references.
210
+
211
+
See the [Destroy Response Templating guide](guides/destroy_templating) for syntax, nested paths, body-based delete, and create-time validation.
Copy file name to clipboardExpand all lines: docs/resources/request.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,21 +34,21 @@ When `skip_read` is `false` and `read_url`, `read_method`, and `read_response_co
34
34
-`destroy_ca_cert_file` (String) Path to a file on local disk that will be used to validate the certificate presented by the server for the destroy call
35
35
-`destroy_cert_file` (String) Path to a file on local disk that contains the PEM-encoded certificate to present to the server for the destroy call
36
36
-`destroy_digest_auth` (Attributes, Sensitive) HTTP Digest authentication credentials for the destroy request. Overrides provider `default_digest_auth` when configured. (see [below for nested schema](#nestedatt--destroy_digest_auth))
37
-
-`destroy_headers` (Map of String) Map of headers to attach to the destroy API call. Host (case-insensitive) overrides the HTTP Host header sent on the wire, independent of the URL hostname.
37
+
-`destroy_headers` (Map of String) Map of headers to attach to the destroy API call. Host (case-insensitive) overrides the HTTP Host header sent on the wire, independent of the URL hostname. Values support `{response.<path>}` placeholders resolved from the stored create response at destroy time.
38
38
-`destroy_headers_wo` (Map of String, Sensitive, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Write-only headers for the destroy call. Snapshotted in provider private state for use during destroy.
39
39
-`destroy_headers_wo_version` (Number) Increment to trigger refreshing snapshotted `destroy_headers_wo` values.
40
40
-`destroy_key_file` (String) Path to a file on local disk that contains the PEM-encoded private key for which the authentication certificate was issued for the destroy call
41
41
-`destroy_max_retry` (Number) Maximum number of tries until it is marked as failed for the destroy call
42
42
-`destroy_method` (String) Destroy HTTP method to use in the API call
43
-
-`destroy_request_body` (String) A request body to attach to the destroy API call
43
+
-`destroy_request_body` (String) A request body to attach to the destroy API call. Supports `{response.<path>}` placeholders resolved from the stored create response at destroy time.
44
44
-`destroy_request_body_wo` (String, Sensitive, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Write-only request body for the destroy call. Not stored in Terraform state.
45
45
-`destroy_request_body_wo_version` (Number) Increment to trigger applying an updated `destroy_request_body_wo` value.
46
-
-`destroy_request_parameters` (Map of String) Map of parameters to attach to the destroy API call
46
+
-`destroy_request_parameters` (Map of String) Map of parameters to attach to the destroy API call. Values support `{response.<path>}` placeholders resolved from the stored create response at destroy time.
47
47
-`destroy_response_codes` (List of String) A list of expected response codes for the destroy call
48
48
-`destroy_retry_interval` (Number) Interval between each attempt for the destroy call
49
49
-`destroy_skip_tls_verify` (Boolean) Set this to true to disable verification of the server's TLS certificate for the destroy call
50
50
-`destroy_timeout` (Number) Time in seconds before each request times out for the destroy call. Defaults to 10
51
-
-`destroy_url` (String) Destroy API endpoint to call
51
+
-`destroy_url` (String) Destroy API endpoint to call. Supports `{response.<path>}` placeholders resolved from the stored create response at destroy time. See the [Destroy Response Templating guide](../guides/destroy_templating).
52
52
-`digest_auth` (Attributes, Sensitive) HTTP Digest authentication credentials for the create request. Overrides provider `default_digest_auth` when configured. (see [below for nested schema](#nestedatt--digest_auth))
53
53
-`headers` (Map of String) Map of headers to attach to the API call. Host (case-insensitive) overrides the HTTP Host header sent on the wire, independent of the URL hostname.
54
54
-`headers_wo` (Map of String, Sensitive, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Write-only headers for the create call. Not stored in Terraform state. Requires Terraform 1.11 or later.
MarkdownDescription: "Destroy API endpoint to call",
279
+
MarkdownDescription: "Destroy API endpoint to call. Supports `{response.<path>}` placeholders resolved from the stored create response at destroy time. See the [Destroy Response Templating guide](../guides/destroy_templating).",
MarkdownDescription: "A request body to attach to the destroy API call",
293
+
MarkdownDescription: "A request body to attach to the destroy API call. Supports `{response.<path>}` placeholders resolved from the stored create response at destroy time.",
MarkdownDescription: "Map of headers to attach to the destroy API call."+hostHeaderMarkdownSuffix,
306
+
MarkdownDescription: "Map of headers to attach to the destroy API call."+hostHeaderMarkdownSuffix+" Values support `{response.<path>}` placeholders resolved from the stored create response at destroy time.",
MarkdownDescription: "Map of parameters to attach to the destroy API call",
320
+
MarkdownDescription: "Map of parameters to attach to the destroy API call. Values support `{response.<path>}` placeholders resolved from the stored create response at destroy time.",
0 commit comments