Reputation: 793
i have deployed terraform script using Terraform Cloud. In tab 'STATE' I can see all the data of my VM machine. For my pipeline I need to download the sv-xxxx.tfstate file in order to get the VM IP. My question is how can I download this file using API? I looked in documentation but couldn't find any hint.
Upvotes: 0
Views: 1991
Reputation: 619
you can use this command that I found in this tutorial: https://developer.hashicorp.com/terraform/tutorials/cloud/cloud-state-api#modify-and-create-the-state-payload
#!/bin/bash
HTTP_RESPONSE=$(curl \
--header "Authorization: Bearer "$TFC_TOKEN"" \
--header "Content-Type: application/vnd.api+json" \
"https://app.terraform.io/api/v2/workspaces/"$WORKSPACE_ID"/current-state-version" | jq -r '.data | .attributes | ."hosted-state-download-url"')
curl -o state.tfstate $HTTP_RESPONSE
Upvotes: 2
Reputation: 4402
As the doc states, you can call
GET /workspaces/:workspace_id/current-state-version
whose response will include a hosted-state-download-url
attribute. This is the URL for the .tfstate
file.
Upvotes: 2