skip to content
wihan.dev
view as markdown
browse the dokploy docs

dokploy_environment (Resource)

An environment inside a Dokploy project. Services such as dokploy_application and dokploy_postgres belong to an environment, not directly to a project. Dokploy creates a production environment with each project, and the API cannot delete that environment. See is_default.

Example Usage

terraform
resource "dokploy_project" "example" {
  name = "example"
}

# Dokploy creates a "production" environment with each project. This adds a
# second environment beside it.
resource "dokploy_environment" "staging" {
  project_id  = dokploy_project.example.id
  name        = "staging"
  description = "Pre-production environment"

  # Each service in this environment shares these variables.
  env = <<-EOT
    LOG_LEVEL=debug
    FEATURE_FLAGS=beta
  EOT
}

Schema

Required

  • name (String) Environment name. Dokploy does not enforce uniqueness within a project, so two environments can share a name.
  • project_id (String) Id of the project that owns this environment. A change replaces the environment: Dokploy has no endpoint that moves an environment between projects.

Optional

  • description (String) Free-form description. Dokploy stores a cleared description as an empty string, not as null. The provider reports both as null.
  • env (String) Variables that each service in this environment shares, as KEY=value lines. The Dokploy create endpoint ignores this field, so a value on a new environment costs one more API call. An omitted value and "" both read back as null. Omit the attribute to clear it.

Read-Only

  • id (String) Environment id.
  • is_default (Boolean) True for the production environment that Dokploy creates with each project. Dokploy refuses to delete that environment, so a destroy of a resource with is_default = true fails with an error that explains this.

Import

Import is supported using the following syntax:

In Terraform v1.5.0 and later, the import block can be used with the id attribute, for example:

terraform
# Environments are imported by their environment id.
import {
  to = dokploy_environment.staging
  id = "Ux7kFq2mNp4RtWvYzAbCd"
}

The terraform import command can be used, for example:

shell
terraform import dokploy_environment.staging Ux7kFq2mNp4RtWvYzAbCd