Exploring the HCP REST API
The Terraform provider for HCP can help automate HCP configuration, but if there is a need to access the API directly, the good news is that Packer is one of the simplest and best-documented of HCP‘s API endpoints. To begin interacting with any HCP API, you need to first get a bearer token using your service principal credentials. You can use the same environment variables as the Terraform examples for a simple curl
statement:
#!/bin/bash curl --silent --request POST \ --header "Content-Type: application/json" \ https://auth.hashicorp.com/oauth/token --data @- << EOF { "audience": "https://api.hashicorp.cloud", "grant_type": "client_credentials", "client_id": "$HCP_CLIENT_ID", "client_secret": "$HCP_CLIENT_SECRET" } EOF
On completion, this will return a JSON document containing...