File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ variable "api_url" {
2+ default = " https://www.google.com"
3+ }
4+
5+ resource "terraform_data" "api_call" {
6+ # This ensures the call runs whenever the URL changes
7+ triggers_replace = {
8+ url = var.api_url
9+ }
10+
11+ provisioner "local-exec" {
12+ # -o /dev/null hides the response body
13+ # -w "%%{http_code}" captures only the status code (e.g., 200)
14+ command = " curl -s -o /dev/null -w \" %%{http_code}\" ${ var . api_url } > status_code.txt"
15+ }
16+ }
17+
18+ data "local_file" "status_code" {
19+ # Explicit dependency ensures we wait for the curl command to finish
20+ depends_on = [terraform_data . api_call ]
21+ filename = " ${ path . module } /status_code.txt"
22+ }
23+
24+ output "http_response_code" {
25+ value = data. local_file . status_code . content
26+ description = " The HTTP status code returned by the API"
27+ }
You can’t perform that action at this time.
0 commit comments