mijailr/terraform-cloud

Handle Terraform Plans JsonOutput

Opened this issue · 0 comments

Our current implementation of Plans(#16) endpoint doesn't have the ability to download the Plan JSON output

From the Terraform Cloud API documentation:

These endpoints generate a temporary authenticated URL to the location of the JSON formatted execution plan. When successful, this endpoint responds with a temporary redirect that should be followed. If using a client that can follow redirects, you can use this endpoint to save the .json file locally without needing to save the temporary URL.

This temporary URL provided by the redirect has a life of 1 minute, and should not be relied upon beyond the initial request. If you need repeat access, you should use this endpoint to generate a new URL each time.

So we need to allow a HTTP 307 response on axios client to return the redirect URL and not follow the redirect.

for example:

const jsonOutputUrl = Plans.jsonOutput('plan-id')
console.log(jsonOutputUrl)

// returns: "https://{full url to json file}}"