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 provider default_headers for fresh auth on destroy.
Provider-level headers are re-evaluated on every Terraform run and override
stale resource header values during destroy, fixing expired token failures.
Closes#83
Co-authored-by: Cursor <cursoragent@cursor.com>
Configure provider-level default headers for short-lived authentication tokens that must stay fresh during destroy.
6
+
---
7
+
8
+
# Default Headers for Auth Tokens
9
+
10
+
Short-lived authentication tokens (OAuth access tokens, GCP ID tokens, session cookies) often expire between `terraform apply` and a later `terraform destroy`. TerraCurl stores resource header values in Terraform state at apply time. During destroy, the provider reads those stored values—not the freshly evaluated configuration—so destroy requests can fail with `401 Unauthorized` if the token has expired.
11
+
12
+
Provider `default_headers` solves this by applying headers from the provider block on **every** outbound HTTP request. Provider configuration is re-evaluated on each Terraform run, including destroy, so dynamic token expressions stay current.
13
+
14
+
## When to use default_headers
15
+
16
+
Use provider `default_headers` when:
17
+
18
+
- Auth tokens expire quickly (for example, GCP Cloud Run ID tokens, ~1 hour TTL)
19
+
- The same auth header is needed on create, read, and destroy
20
+
- You reference a data source or variable for the token value
- Tokens set only in resource `headers` or `destroy_headers` are still persisted in state. For destroy-only refresh, move auth to `default_headers` or run `terraform apply` before destroy to update state.
83
+
- Write-only resource headers (see issue #115) are a separate follow-up to avoid persisting secrets in state entirely.
84
+
-`default_headers` is marked sensitive in the provider schema and will not appear in plan output.
85
+
86
+
## Workaround without default_headers
87
+
88
+
If you cannot upgrade yet, run `terraform apply` (with no infrastructure changes) before `terraform destroy`. That updates header values in state with freshly evaluated tokens, then destroy succeeds. This is fragile when `lifecycle { ignore_changes = ... }` blocks header updates.
Copy file name to clipboardExpand all lines: docs/index.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,4 +65,51 @@ provider "terracurl" {
65
65
}
66
66
```
67
67
68
+
## Default Headers for Auth Tokens
69
+
70
+
TerraCurl supports provider-level `default_headers` for short-lived authentication tokens that must be refreshed on every Terraform run, including destroy.
71
+
72
+
See the [Default Headers for Auth Tokens guide](guides/default_headers) for configuration examples, merge behavior, and migration from resource-level auth headers.
73
+
74
+
```terraform
75
+
# Provider default_headers can be configured in the provider block:
76
+
#
77
+
# provider "terracurl" {
78
+
# default_headers = {
79
+
# Authorization = "Bearer ${var.api_token}"
80
+
# }
81
+
# }
82
+
#
83
+
# Use default_headers for short-lived auth tokens that must be refreshed on
84
+
# every Terraform run, including destroy. Provider headers override resource
0 commit comments