.png)
HCP Terraform Integration Guide
Integrate HCP Terraform with enterprise systems through its versioned REST API, selected webhook notifications, asynchronous run operations, and scheduled reconciliation workflows.
HCP Terraform integration options at a glance
HCP Terraform’s primary integration mechanism is a versioned REST API using JSON:API-style resources for organizations, projects, workspaces, runs, state versions, variable sets, teams, and policies. Selected Terraform events can generate webhook-style notifications for external HTTP endpoints, although coverage is not universal. Runs and configuration operations are asynchronous, so integrations should correlate identifiers and use notifications or controlled polling. Configuration versions and state versions may involve file upload or download operations. Martini can securely consume the API, receive supported webhook notifications, expose orchestration APIs, schedule reconciliation workflows, transform JSON:API responses, and apply authorization, validation, retry, and idempotency rules.
Common HCP Terraform integration patterns
Common HCP Terraform data objects used in integrations
Authentication and security considerations
Bearer-token authentication
HCP Terraform API requests use bearer tokens. User, team, and organization API tokens are available, while OAuth clients and tokens support documented external application integrations.
Least-privilege access
Authentication does not guarantee authorization. Effective access depends on the token type, organization membership, team permissions, workspace permissions, and HCP Terraform access controls.
Secret and state protection
- Store API tokens and webhook credentials in Martini environment secrets.
- Prefer team or organization credentials for unattended integrations rather than personal user tokens.
- Do not place tokens in workflow definitions, mappings, source control, logs, or error messages.
- Treat Terraform state as sensitive infrastructure data and use restricted access, encryption, and retention controls.
Operational considerations for HCP Terraform integrations
Rate limits and pagination
Avoid uncontrolled polling, use bounded concurrency and exponential backoff, handle HTTP 429 responses centrally, and process every page returned by collection endpoints.
Asynchronous runs
Persist the HCP Terraform run identifier and treat run creation and completion as separate stages. Use supported notifications or controlled polling until a terminal status is reached.
Idempotency and webhooks
Webhook delivery and retries can produce duplicate processing. Use stable event, run, or resource identifiers before creating downstream changes, notifications, or compliance records.
API and schema evolution
Target the documented API version, validate required fields, tolerate unknown fields where safe, monitor deprecation notices, and keep resource mappings separate from business logic.
Testing and monitoring
Test authorized and unauthorized workspaces, pagination, policy failures, duplicate notifications, rate-limit responses, and incomplete relationships. Monitor workflow logs and preserve correlation identifiers for troubleshooting.
Why use Martini instead of scripts or point-to-point integrations?
Orchestration beyond point-to-point calls
Scripts can call the HCP Terraform API, but Martini provides a maintainable workflow layer for approvals, webhook handling, asynchronous run monitoring, scheduled reconciliation, and downstream updates.
Reusable integration logic
Martini centralizes authentication, validation, mappings, business rules, retries, and error routing so the same HCP Terraform behavior can support service management, delivery, governance, and reporting processes.
Controlled APIs and data models
Martini can expose a controlled API façade and transform JSON:API resources into canonical enterprise models without distributing HCP Terraform credentials or resource-specific logic across every consuming application.
Operational reliability
Workflows can handle pagination, high-water marks, idempotency, bounded polling, sensitive state controls, and observable failure paths more consistently than isolated scripts.