> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://help.sigmacomputing.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://help.sigmacomputing.com/_mcp/server.

# Use the Sigma Terraform provider

> Write Terraform configurations for Sigma, import existing resources, protect sensitive state, and troubleshoot the Sigma Terraform provider.

After you [install and configure the Sigma Terraform provider](/docs/install-and-configure-the-sigma-terraform-provider), you can define Sigma resources in Terraform, preview changes, and apply them.

This document explains how to write your first configuration, import existing Sigma objects, understand resource behavior, protect sensitive values in state, and troubleshoot errors.

> **Info**
>
> Each resource and data source maps to Sigma REST API endpoints. For the full list of arguments and attributes, see the [provider documentation](https://registry.terraform.io/providers/sigmacomputing/sigma/latest/docs) in the Terraform Registry. The [examples directory](https://github.com/sigmacomputing/terraform-provider-sigma/tree/main/examples) on GitHub has one configuration for each resource and data source.

## Create resources with Terraform

You use a Terraform configuration to declare the [resources](https://developer.hashicorp.com/terraform/language/resources/syntax), and the Sigma Terraform provider uses the Sigma REST API to update your Sigma organization.

The following example creates an Analytics team and a user named Jane Doe, then adds the user to the team.

```hcl
# Create a team.
resource "sigma_team" "analytics" {
  name = "Analytics"
}

# Create a user. Sigma stores the account type as "build".
resource "sigma_member" "jane" {
  email       = "jane@example.com"
  first_name  = "Jane"
  last_name   = "Doe"
  member_type = "build"
}

# Add the user to the team.
resource "sigma_team_membership" "jane_analytics" {
  team_id   = sigma_team.analytics.id
  member_id = sigma_member.jane.id
}

# Read existing workspaces without managing them.
data "sigma_workspaces" "all" {}
```

The provider calls the following Sigma REST API endpoints for the objects in this example:

| Terraform object               | Sigma REST API endpoint                               |
| ------------------------------ | ----------------------------------------------------- |
| `sigma_team`                   | [Create a team](/reference/create-team)               |
| `sigma_member`                 | [Create a member](/reference/create-member)           |
| `sigma_team_membership`        | [Update team members](/reference/update-team-members) |
| `sigma_workspaces` data source | [List workspaces](/reference/list-workspaces)         |

> **Info**
>
> By default, creating a `sigma_member` sends an email invitation to the user. To create members without sending an invitation, for example if your identity provider manages user onboarding, set `send_invite = false` on the resource.

To preview and apply the changes, use the [`terraform plan`](https://developer.hashicorp.com/terraform/cli/commands/plan) and [`terraform apply`](https://developer.hashicorp.com/terraform/cli/commands/apply) commands:

```shell
# Preview the changes Terraform will make.
terraform plan

# Create the resources in Sigma.
terraform apply
```

To remove the resources that a configuration manages, run [`terraform destroy`](https://developer.hashicorp.com/terraform/cli/commands/destroy). Before you destroy a resource, review [Understand resource behavior](#understand-resource-behavior).

## Import existing resources

To manage an object that already exists in Sigma, import it into Terraform [state](https://developer.hashicorp.com/terraform/language/state).

Each resource page in the [provider documentation](https://registry.terraform.io/providers/sigmacomputing/sigma/latest/docs) has an **Import** section with the ID format.

For example, to import an existing team:

1. In your configuration, add a `resource` block for the object, for example:

   ```hcl
   resource "sigma_team" "analytics" {
     name = "Analytics"
   }
   ```

2. To import the object, run the following [`terraform import`](https://developer.hashicorp.com/terraform/cli/commands/import) command with the ID of the object in Sigma:

   ```shell
   terraform import sigma_team.analytics <team_id>
   ```

   Some resources use a composite ID. For example, a team membership uses `<team_id>:<member_id>`.

3. To confirm that your configuration matches the imported object, run `terraform plan`.

For more information about how importing works, see [Import resources](https://developer.hashicorp.com/terraform/language/import) in the Terraform documentation.

## Understand resource behavior

Some resources behave in ways that aren't obvious from their configuration, such as deleting content when you destroy a resource or requiring extra arguments after an import. The following table lists these behaviors. Review them before you apply changes to a production organization or when you troubleshoot unexpected plan output:

| Resource                | Behavior                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sigma_member`          | Destroying a user deactivates the user in Sigma. The email address stays reserved and can't be used for a new user without an admin restoring the user in Sigma.                                                                                                                                                                                                                                                                                                           |
| `sigma_workspace`       | Destroying a workspace permanently deletes the workspace and the documents in it. Sigma can't recover a deleted workspace.                                                                                                                                                                                                                                                                                                                                                 |
| `sigma_workspace_grant` | The `permission` argument uses the API value. `view` is **Can view**, `explore` is **Can explore**, `organize` is **Can contribute**, and `edit` is **Can manage**.                                                                                                                                                                                                                                                                                                        |
| `sigma_folder`          | Destroying a folder archives it. You can restore the content from Sigma.                                                                                                                                                                                                                                                                                                                                                                                                   |
| `sigma_connection`      | When you create the connection, Sigma validates the credentials in `details_json`. Sigma doesn't return the `details_json` attribute. After an import, the next plan proposes an update unless you add [`lifecycle { ignore_changes = [details_json] }`](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle). Destroying a connection breaks content that uses it.                                                                                |
| `sigma_account_type`    | Changing `permissions` updates the account type. Changing `name` creates a new account type with a new ID, moves the users to it, and deletes the old one, unless you set `migrate_on_rename = false`. Settings that reference the old account type, such as SSO or SCIM role mappings, aren't updated. Changing only `description` replaces the account type, and Sigma reassigns the users of the old account type to the account type in `reassign_to_account_type_id`. |
| `sigma_api_credential`  | Sigma returns `client_secret` only when it creates the credential. Destroying the resource immediately revokes the credential and any tool that uses it starts receiving authentication errors.                                                                                                                                                                                                                                                                            |
| `sigma_tenant`          | Changing `cloud_provider` replaces the tenant organization. For more information, see [Create and manage tenant organizations](/docs/create-and-manage-tenant-organizations).                                                                                                                                                                                                                                                                                              |

## Protect sensitive values in state

Terraform stores resource attributes in a [state](https://developer.hashicorp.com/terraform/language/state) file. The following resources store sensitive values there, because Sigma doesn't return them after creation:

* `sigma_api_credential.client_secret`
* `sigma_connection.details_json`, which contains the data platform credentials that you provide for a connection
* `sigma_api_connector_credential.credential_json`
* `sigma_smtp_settings.password`
* User attribute values, which might hold tenant IDs or other values used for row-level security

To protect these values, do the following:

* Store state in an encrypted remote [backend](https://developer.hashicorp.com/terraform/language/backend) with restricted access, such as Amazon S3 with encryption, HCP Terraform, Azure Blob Storage, or Google Cloud Storage with customer-managed keys. Don't use local state files for configurations that handle real credentials.
* Create a dedicated API credential for Terraform and rotate it regularly.
* Treat `TF_LOG` output as sensitive, even though the provider masks known secret fields. For more guidance, see [Manage sensitive data in your configuration](https://developer.hashicorp.com/terraform/language/state/sensitive-data).

The provider reads configuration and metadata for the objects you manage or look up, such as user names and emails, teams, connection settings, and grants. It doesn't read data in your workbooks, data models, or connected warehouses.

## Troubleshoot the provider

The following sections describe how to log provider requests and resolve common errors.

### Enable debug logging

To see the HTTP requests that the provider sends, set the `TF_LOG` environment variable. For more information about log levels and options such as `TF_LOG_PATH`, see [Enable Terraform logs](https://developer.hashicorp.com/terraform/internals/debugging). Request and response bodies appear at the `TRACE` level in the `sigma_http` subsystem. The provider masks values such as client secrets, access tokens, warehouse credentials, and user attribute values.

```shell
# Log provider requests.
TF_LOG=DEBUG terraform plan

# Include request and response bodies.
TF_LOG=TRACE terraform plan
```

### Resolve common errors

| Symptom                                                         | Likely cause and resolution                                                                                                                                                                                                                                                       |
| --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authentication errors, such as `401`                            | The client ID or secret is incorrect or revoked, or the credentials belong to a different Sigma organization. Verify the values, and check the credential with the `sigma_whoami` data source.                                                                                    |
| Requests fail to connect, or return `404`                       | The `base_url` doesn't match your organization's cloud and region. In Sigma, go to **Administration** > **Integrations** > **Developer Access** to confirm the **API base URL**.                                                                                                  |
| `403` or permission errors when you create or change a resource | The credentials are assigned to a user without the **Admin** account type. Generate new credentials assigned to a user with the **Admin** account type.                                                                                                                           |
| `429` rate limit errors                                         | The provider retries automatically and honors the `Retry-After` header for up to one minute. To reduce load, run `terraform apply` with a lower [`-parallelism`](https://developer.hashicorp.com/terraform/cli/commands/apply#parallelism-n) value, for example `-parallelism=2`. |
| A connection plan shows changes after an import                 | Sigma doesn't return `details_json`. Add `lifecycle { ignore_changes = [details_json] }` to the resource.                                                                                                                                                                         |

## Related resources

* [Install and configure the Sigma Terraform provider](/docs/install-and-configure-the-sigma-terraform-provider)
* [Generate Sigma API client credentials](/reference/generate-client-credentials)
* [Get started with the Sigma REST API](/reference/get-started-sigma-api)
* [Sigma Tenants](/docs/multitenancy-at-sigma)
* [Create and manage tenant organizations](/docs/create-and-manage-tenant-organizations)

For more information about using Terraform itself, see the following in the HashiCorp documentation:

* [Provider requirements](https://developer.hashicorp.com/terraform/language/providers/requirements)
* [Input variables](https://developer.hashicorp.com/terraform/language/values/variables)
* [State](https://developer.hashicorp.com/terraform/language/state)
* [Import resources](https://developer.hashicorp.com/terraform/language/import)
* [The terraform plan command](https://developer.hashicorp.com/terraform/cli/commands/plan)