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

# Terraform

> Create and manage Replicas environments with the Terraform provider.

Use the [Replicas provider](https://registry.terraform.io/providers/replicas-group/replicas/latest) to manage environments from Terraform. You need an organization API key and Terraform 1.5 or later.

## Configure the provider

Set `REPLICAS_API_KEY` securely in your shell or CI secret store. Use a key for the organization where you want to manage environments. You do not need an HCP Terraform account to use the provider locally.

Save `main.tf`:

```hcl theme={null}
terraform {
  required_providers {
    replicas = {
      source  = "replicas-group/replicas"
      version = "~> 0.1.0"
    }
  }
}

provider "replicas" {}

resource "replicas_environment" "development" {
  name = "Development"

  configuration = jsonencode({
    variables = { APP_MODE = "development" }
    startHook = "echo Workspace ready"
  })
}
```

```bash theme={null}
terraform init
terraform plan
terraform apply
```

Confirm the plan before applying. Run `terraform plan` again afterward to check for no changes.

## Configuration and secrets

`configuration` uses the same keys as the [YAML/JSON environment block](https://docs.replicas.dev/features/environment-configuration.md#supported-fields), without the outer `environment` wrapper. Declared settings become read-only in the app; settings outside the declaration remain editable.

> [!WARNING]
>
> Literal configuration values are stored in Terraform state. Store secret values separately in Replicas and reference their names with `requiredSecrets`. For a new environment, inherit required secrets from a parent or provision the environment and its secrets before importing it.

Changing `source_environment_id` replaces an environment. `terraform destroy` deletes environments managed by the configuration. Review the plan before either operation.

## Adopt an existing environment

Disconnect any Git configuration source before adopting the environment. Use one Terraform state to manage an environment.

To generate configuration, add an import block without a resource block for that address:

```hcl theme={null}
import {
  to = replicas_environment.existing
  id = "ENVIRONMENT_ID"
}
```

```bash theme={null}
terraform plan -generate-config-out=generated.tf
```

Review the generated file for sensitive values before committing or applying it. Initial adoption can include reconciliation changes as exported settings become managed. Import is not guaranteed to be a no-change operation.

See the [resource reference](https://registry.terraform.io/providers/replicas-group/replicas/latest/docs/resources/environment) for schema and import details, and the [provider repository](https://github.com/replicas-group/terraform-provider-replicas) for source and release information.


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