> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useshipd.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Terraform provider reference

> Configuration, resources, data sources, imports, and lifecycle behavior for the shipd Terraform provider.

## Overview

The `alasti-company/shipd` provider manages shipd resources through the control-plane API. For installation and a complete configuration, see [Manage projects and environments with Terraform](https://docs.useshipd.com/integrations/terraform.md).

Install the published [alasti-company/shipd provider](https://registry.terraform.io/providers/alasti-company/shipd/latest/docs) with `terraform init`. The v0.1 release manages projects and environments. Webhook resources require a provider release that includes them and API support for `snapshotWebhook/createConfig` and `eventWebhook/createConfig`. Credential resources require a provider release that includes them and a shipd API with credential registration support.

## Provider configuration

```hcl provider.tf theme={null}
provider "shipd" {
  organization_id = "YOUR_ORGANIZATION_ID"
}
```

| Argument | Type | Default | Behavior |
| - | - | - | - |
| `api_key` | Sensitive string | `SHIPD_API_KEY` | Service account token (`shipd_sa_…`) or management API key (`shipd_mgmt_…`). Must be known during planning. |
| `api_url` | String | `SHIPD_API_URL` or `https://api.useshipd.com` | HTTPS is required except for localhost or loopback IP addresses. |
| `organization_id` | String | `SHIPD_ORGANIZATION_ID` | Optional check that credentials belong to the expected organization. Does not switch organizations. |

Prefer `SHIPD_API_KEY` over putting credentials in configuration. SDK keys cannot authenticate the provider.

Creating projects requires an organization-wide service account token. Management API keys work within their bindings but cannot create projects. Project-bound service account tokens can manage environments in that project; environment-bound credentials cannot create environments. Read-only consumers need the corresponding `project:read` and `environment:read` scopes. See [token scopes and binding](https://docs.useshipd.com/reference/service-account-tokens.md).

## Resources

### shipd\_project

Creates a project in the credential's organization.

| Attribute | Type | Requirement | Behavior |
| - | - | - | - |
| `name` | String | Required | Display name; updates in place. |
| `slug` | String | Required | Project slug, at least three characters; updates in place. |
| `id` | String | Computed | Stable project ID. |
| `organization_id` | String | Computed | Owning organization ID. |
| `version` | Number | Computed | API version used for optimistic concurrency checks. |

### shipd\_environment

Creates an environment within a project.

| Attribute | Type | Requirement | Behavior |
| - | - | - | - |
| `project_id` | String | Required | Owning project ID. Changing it replaces the environment. |
| `name` | String | Required | Display name; updates in place. |
| `slug` | String | Required | Unique within the project; updates in place. |
| `type` | String | Optional | Free-form classification; defaults to `development`. Does not control permissions. |
| `is_production` | Boolean | Optional | Defaults to `false`. Only one environment per project may be production. |
| `id` | String | Computed | Stable environment ID. |
| `version` | Number | Computed | API version used for optimistic concurrency checks. |

### shipd\_snapshot\_webhook

Sends `snapshot.published` notifications to a Convex HTTP action. Each environment supports one destination.

| Attribute | Type | Requirement | Behavior |
| - | - | - | - |
| `environment_id` | String | Required | Owning environment ID. Changing it replaces the webhook. |
| `url` | Sensitive string | Required | HTTPS callback on a `.convex.site` hostname without user information or a fragment. Updates in place. |
| `enabled` | Boolean | Optional | Defaults to `true`. Updates in place. |
| `id` | String | Computed | Stable destination ID. |

Use a service account token with `environment:read` and `snapshot_webhook:read`, plus `snapshot_webhook:manage` for writes. See [Connect Convex](https://docs.useshipd.com/sdks/convex.md) for receiver setup.

### shipd\_event\_webhook

Sends customer events to an HTTPS endpoint. The event type set filters which events are delivered.

| Attribute | Type | Requirement | Behavior |
| - | - | - | - |
| `environment_id` | String | Required | Owning environment ID. Changing it replaces the webhook. |
| `name` | String | Required | Display name. Changing it replaces the webhook. |
| `url` | Sensitive string | Required | HTTPS endpoint without user information or a fragment. Changing it replaces the webhook. |
| `event_types` | Set of strings | Required | One to 100 event types. Use `"*"` to match all types. Updates in place. |
| `enabled` | Boolean | Optional | Defaults to `true`. Updates in place. |
| `id` | String | Computed | Stable endpoint ID. |

Use a service account token with `event_webhook:read`, plus `event_webhook:manage` for writes. The organization must have customer event webhooks enabled to create endpoints. See [Receive customer events](https://docs.useshipd.com/operations/receive-customer-events.md) for receiver setup.

### Webhook credentials and delivery

Terraform manages webhook configuration. Set up signing secrets, test deliveries, view delivery history, and redeliver events in shipd.

* **Signing secrets.** shipd generates a secret on creation. Terraform receives and stores only configuration. For a new webhook, set `enabled = false`, use **Rotate secret** for a Convex destination or **Rotate signing secret** for an event endpoint, and save the returned secret in the receiver's secret manager. Then set `enabled = true` and apply. Existing webhooks keep their signing secret when imported or updated. Replacing a webhook creates a new secret.
* **Destination URLs.** Terraform marks URLs sensitive and stores each complete URL in plans and state. Use URLs without credentials, including credentials in paths or query strings. Protect plan and state files if you import an existing URL that contains a credential.
* **Drift and deletion.** Refresh reads the current configuration, including enabled state and event subscriptions. Terraform plans to recreate webhooks deleted outside Terraform. Destroy deletes the webhook. Deleting an event endpoint also cancels its pending deliveries.
* **Interrupted creation.** The provider reuses the request's idempotency key during retries. If an apply stops before it records the webhook in state, check the environment in shipd and import any webhook the apply created.

## Data sources

Read existing objects without taking ownership of their lifecycle:

```hcl data.tf theme={null}
data "shipd_project" "app" {
  slug = "web-app"
}

data "shipd_environment" "production" {
  project_id = data.shipd_project.app.id
  slug       = "production"
}
```

Both data sources accept exactly one of `id` or `slug`. The environment data source also requires `project_id`.

| Data source | Returned attributes |
| - | - |
| `shipd_project` | `id`, `slug`, `name`, `organization_id`, `version` |
| `shipd_environment` | `id`, `slug`, `name`, `project_id`, `type`, `is_production`, `version` |

## Import existing resources

Declare the matching resource blocks first, then import:

```bash theme={null}
terraform import shipd_project.app PROJECT_ID
terraform import shipd_environment.production PROJECT_ID/ENVIRONMENT_ID
terraform import shipd_snapshot_webhook.convex ENVIRONMENT_ID/DESTINATION_ID
terraform import shipd_event_webhook.invoices ENVIRONMENT_ID/ENDPOINT_ID
terraform plan
```

Set `type` and `is_production` explicitly when importing an environment whose values differ from the defaults (`development` and `false`). Set `enabled = false` in configuration when importing a disabled webhook. Review the plan before applying changes.

## Lifecycle and drift

* **Ownership.** Terraform manages only resources declared in configuration. Data sources leave ownership with shipd.
* **Destroy.** Destroy archives projects and environments. Recovery and slug reservation last seven days. Creating again does not automatically restore or adopt it: restore through the dashboard and import, choose another slug, or wait for the reservation to expire. Archiving a project also makes its child resources inaccessible.
* **Protection.** Use `lifecycle { prevent_destroy = true }` for important resources. Approval policies may block archive or production changes; the provider returns the API error and retains state. It does not approve requests.
* **Production changes.** To move production to another environment, first set `is_production = false` on the current one and apply. Then set `is_production = true` on the replacement and apply again. Implicit demotion is rejected, including during concurrent writes. Setting `type = "production"` alone does not designate production.
* **Drift.** External changes appear in the next plan. Project and environment updates use the refreshed API version. A concurrent project or environment change returns a conflict; run a fresh plan before retrying.
* **Reads.** Objects that no longer exist are removed from Terraform state. Authorization and transport failures return errors instead of treating objects as missing.
* **Interrupted creation.** Retries reuse an idempotency key within one operation. If creation commits but the process stops or response retries are exhausted, inspect shipd and import the existing ID before retrying.

Environment updates require API support for `environment/updateWithoutHandoff`. Older servers reject the operation instead of falling back to an update that could demote another environment.

## Manage credentials from CI

Use Terraform 1.11 or later for `shipd_sdk_key` and `shipd_service_account_token`. Use a dashboard-created [service account token](https://docs.useshipd.com/enterprise/service-accounts.md) as `SHIPD_API_KEY` and keep that bootstrap account and token outside the configuration they authenticate. If Terraform also manages the workload account, grant the separate service account administration scopes required by `shipd_service_account`.

| Credential | CI permissions | Binding and expiry |
| - | - | - |
| Client and server SDK keys | `sdk_key:create` to register, `sdk_key:read` to refresh, `sdk_key:revoke` to destroy | Each key belongs to one project and environment. Scope the CI token to those IDs when possible. Set `expires_at` for automatic expiry, or omit it for a non-expiring key. |
| Workload service account tokens | `service_account_token:create` to register, `service_account_token:read` to refresh, `service_account_token:revoke` to destroy | Use an organization-wide bootstrap token with no project or environment binding. For registration and revocation, the bootstrap token must hold every scope on the workload token. Workload tokens cannot receive `service_account_token` or `apiKey` scopes through Terraform. Bind each workload token as narrowly as its job allows and set a future `expires_at`. |
| Management API keys | Supported as provider authentication within their existing bindings | Create, rotate, and revoke these user-bound keys through the existing user-session workflows. Use a service account token for CI-managed credentials. |

Set `scopes` explicitly. SDK keys accept `snapshot:read`, `events:write`, and `stream:connect`. Server SDK keys can also receive `identity:read`. Service account token scopes use the [resource-to-verbs map](https://docs.useshipd.com/reference/service-account-tokens.md#scopes). For example, a token that reads projects needs only `project = ["read"]`. Use RFC3339 timestamps for expiry.

### Generate and deliver a secret

Generate a lowercase UUIDv4 for the credential's `id`. Use the prefix `shipd_sdk_client_`, `shipd_sdk_server_`, or `shipd_sa_`, followed by 32 random bytes encoded as unpadded base64url, a dot, and the first 32 lowercase hex characters of the organization ID's SHA-256 digest.

```python generate_credential.py theme={null}
import hashlib
import secrets

def generate_credential(prefix: str, organization_id: str) -> str:
    tag = hashlib.sha256(organization_id.encode("utf-8")).hexdigest()[:32]
    return f"{prefix}{secrets.token_urlsafe(32)}.{tag}"
```

Save the generated secret in a versioned secret store before applying. Set `secret_version` to the nonsecret version identifier and use that same version for every attempt. Pass the secret value to Terraform through a sensitive, ephemeral variable and the `secret_wo` argument. After registration succeeds, configure the consumer to read the same secret-store version. On a self-hosted installation, deploy the matching edge and WebSocket gateway builds before using registered SDK keys.

```hcl sdk-key.tf theme={null}
variable "runtime_sdk_key_id" {
  type = string
}

variable "runtime_sdk_key_version" {
  type = string
}

variable "runtime_sdk_key" {
  type      = string
  sensitive = true
  ephemeral = true
  default   = null
}

resource "shipd_sdk_key" "runtime" {
  id              = var.runtime_sdk_key_id
  organization_id = var.organization_id
  project_id      = var.project_id
  environment_id  = var.environment_id
  name            = "Runtime"
  key_type        = "server"
  scopes          = ["snapshot:read"]
  secret_version  = var.runtime_sdk_key_version
  secret_wo       = var.runtime_sdk_key
}
```

Use the same write-only pattern for `shipd_service_account_token`. Set `service_account_id` and `expires_at`, supply a scope map, and omit `key_type`. CI can load the secret from its store into `TF_VAR_runtime_sdk_key` with shell command tracing disabled. The secret is required when creating or replacing a credential. Refresh and destroy can run with the ephemeral variable set to null.

**Terraform state and saved plans.** These resources persist IDs, names, bindings, scopes, expiry, the secret-store version identifier, key type for SDK keys, and revocation status. They store no plaintext, lookup prefixes, or hashes, and expose no secret output. Terraform keeps the version identifier locally. The provider sends the prefix and SHA-256 digest to shipd for lookup and verification. `SHIPD_API_KEY` keeps the bootstrap token outside Terraform configuration. Terraform's `sensitive` marking only masks display output. Use an ephemeral input and write-only argument to keep a credential out of plans and state. An ordinary sensitive variable, output, or secret store resource elsewhere in your configuration may still persist its value.

### Recover an interrupted apply

If a request times out or an apply ends before writing state, rerun with the original UUID, original metadata, and same secret-store version. The API compares the UUID, lookup prefix, hash, and credential metadata before acknowledging the existing record. For SDK keys, it also retries edge publication. Concurrent or repeated registrations produce one credential and one creation audit event. Changing the secret or metadata under the same ID produces a conflict. The provider never replays a response containing a secret.

If the original secret-store version is gone, wait for any in-flight apply to settle, then revoke the old credential by UUID in shipd before registering a new UUID and secret. If the interrupted run never wrote state, use the dashboard or call `sdkKey/revoke` with `keyId` and `orgId`, or `serviceAccount/revokeToken` with `tokenId`, `serviceAccountId`, and `orgId`. You can apply the exact original configuration to recover ownership of a live Terraform registration. Importing credentials created through other workflows with `terraform import` is unsupported. Existing service account identities can still be imported.

### Rotate, retire, and replace

1. Create a second resource with a fresh UUID and secret. Apply while the old resource stays in configuration.
2. Switch the consumer to the new secret-store version and verify an authenticated request.
3. Remove the old resource and apply to revoke it, then retire its secret-store version.

Both credentials remain usable between the two applies, up to either credential's expiry. Choose and enforce the overlap in CI. shipd applies no automatic grace period. CI can revoke an SDK key by ID after its project is archived. SDK key revocation takes effect as it propagates to the edge. Open WebSocket connections revalidate at least every 60 seconds. Service account tokens fail control-plane authentication when revoked, expired, or attached to a disabled account. See [credential revocation behavior](https://docs.useshipd.com/concepts/keys.md#rotate-or-revoke-a-credential).

Changing the secret version or another immutable property requires a fresh UUID and secret. Keep the secret-store version immutable because Terraform cannot diff the write-only value. Replacing one resource address uses Terraform's default destroy-first ordering and can interrupt workloads. Use the two-resource sequence for overlap. Avoid forcing replacement with `-replace` on the same UUID, since revoked registrations cannot be reused. Refresh shows `revoked = true` for a credential revoked outside Terraform. Expiry and external revocation require an explicit rotation.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.