Skip to main content
Use the Replicas provider 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:
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, without the outer environment wrapper. Declared settings become read-only in the app; settings outside the declaration remain editable.
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:
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 for schema and import details, and the provider repository for source and release information.