# dokploy_application (Resource)

An application service in a Dokploy environment: its source, build settings, and environment variables managed as a single resource.

~> **Terraform owns the whole application.** Applying this resource rewrites the application's source, build and environment configuration wholesale, so any of those settings changed in the Dokploy UI is replaced on the next apply. Manage an application either in Terraform or in the UI, not both.

## Example Usage

```terraform
resource "dokploy_application" "example" {
  name           = "web"
  environment_id = [for e in dokploy_project.example.environments : e.id if e.name == "production"][0]

  docker = {
    image = "traefik/whoami:v1.10"
  }

  env = <<-EOT
    PORT=80
  EOT

  # Attach to extra Docker networks. Applied on the next deploy. A bare id
  # would not apply for other users, so this stays commented out - replace
  # it with a real network id from your own instance before you uncomment it.
  # network_ids = ["<dokploy-network-id>"]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `environment_id` (String) Id of the environment this application lives in (see `dokploy_project.environments`).
- `name` (String) Display name of the application.

### Optional

- `app_name` (String) Dokploy-internal app name; generated by the server when omitted.
- `args` (List of String) Arguments passed to the container command.
- `auto_deploy` (Boolean) Redeploy automatically when Dokploy receives a webhook for the configured branch or tag.
- `build` (Attributes) Build settings; server default is nixpacks. (see [below for nested schema](#nestedatt--build))
- `build_args` (String) Build-time arguments in the same multiline format.
- `build_secrets` (String, Sensitive) Build-time secrets in the same multiline `KEY=value` format, mounted during the build and not baked into the image. Omitting it clears any value set in the Dokploy UI; omission and `""` are indistinguishable on read, so use omission to clear.
- `command` (String) Override the container entrypoint command.
- `cpu_limit` (String) Hard CPU limit, Docker-style (e.g. `"0.5"`). A string, not a number.
- `cpu_reservation` (String) Reserved CPU, Docker-style (e.g. `"0.25"`).
- `create_env_file` (Boolean) Write the environment variables to a `.env` file in the build context. Defaults to `true`, matching Dokploy's own default for a new application.
- `deploy_on_change` (Boolean) Deploy after create and after changes to deploy-triggering attributes. Defaults to `true`.
- `deployment_timeout` (String) How long to wait for a triggered deployment to reach a terminal status, as a Go duration string. Defaults to `"15m"`. On timeout the apply fails but the server-side deployment keeps running.
- `description` (String) Free-form description.
- `detach_dokploy_network` (Boolean) Detach the shared `dokploy-network` from this application. Defaults to `false`. Only meaningful together with `network_ids`; applied on the next deploy.
- `docker` (Attributes) Docker image source. (see [below for nested schema](#nestedatt--docker))
- `enable_submodules` (Boolean) Check out git submodules when cloning. Applies to the `github` and `git` sources; ignored for `docker`.
- `env` (String) Environment variables in Dokploy's native multiline `KEY=value` format. Use Terraform sensitive variables for secret values. Setting this also clears the application's **build secrets** in Dokploy, which this resource does not expose.
- `git` (Attributes) Custom git source (any reachable repo over https/ssh). Exactly one of `github`, `git`, or `docker` must be set. (see [below for nested schema](#nestedatt--git))
- `github` (Attributes) GitHub App source. Exactly one of `github`, `git`, or `docker` must be set. The GitHub provider (`github_id`) is configured in Dokploy (Git > GitHub) — a documented manual prerequisite. (see [below for nested schema](#nestedatt--github))
- `memory_limit` (String) Hard memory limit, Docker-style (e.g. `"512m"`).
- `memory_reservation` (String) Reserved memory, Docker-style (e.g. `"256m"`).
- `network_ids` (Set of String) Ids of Docker networks (Dokploy network records) to attach this application to. Applied on the next deploy. Omit to keep only the default `dokploy-network`. An empty set is not valid - omit the attribute instead.
- `registry_id` (String) Id of a Dokploy registry to push built images to. This provider has no registry resource yet; supply the id as a literal.
- `replicas` (Number) Number of container replicas to run. Dokploy's schema has no null variant for this field, so it always has a concrete value.
- `server_id` (String) Remote server to run the application on. Defaults to the Dokploy host.
- `watch_paths` (List of String) Glob paths that trigger an auto-deploy when changed. Applies to the `github` and `git` sources; ignored for `docker`. Omitting it clears any value set in the Dokploy UI.

### Read-Only

- `created_at` (String) Creation timestamp (server-side).
- `id` (String) Application id.
- `status` (String) Application status reported by Dokploy.

<a id="nestedatt--build"></a>
### Nested Schema for `build`

Required:

- `type` (String) Build type: one of `nixpacks`, `dockerfile`, `heroku_buildpacks`, `paketo_buildpacks`, `static`, `railpack`. Note that `heroku_buildpacks` and `railpack` take a builder version in Dokploy which this provider does not expose; it is always sent unset, so those two build types always use the server's default builder version and any version chosen in the Dokploy UI is reset on apply.

Optional:

- `build_stage` (String) Target stage for multi-stage builds.
- `context_path` (String) Docker build context path.
- `dockerfile` (String) Dockerfile path (build type `dockerfile`).
- `heroku_version` (String) Builder version for build type `heroku_buildpacks`. Omit to use the server's default.
- `is_static_spa` (Boolean) Serve the build output as a single-page application, rewriting unknown paths to the index document.
- `publish_directory` (String) Publish directory (build type `static`).
- `railpack_version` (String) Builder version for build type `railpack`. Omit to use the server's default.


<a id="nestedatt--docker"></a>
### Nested Schema for `docker`

Required:

- `image` (String) Image reference, e.g. `nginx:1.27`.

Optional:

- `password` (String, Sensitive) Registry password for private images.
- `registry_url` (String) Registry URL for private registries.
- `username` (String) Registry username for private images.


<a id="nestedatt--git"></a>
### Nested Schema for `git`

Required:

- `branch` (String) Branch to deploy.
- `url` (String) Clone URL.

Optional:

- `build_path` (String) Path inside the repo to build from.
- `ssh_key_id` (String) Id of a Dokploy SSH key for private repos.


<a id="nestedatt--github"></a>
### Nested Schema for `github`

Required:

- `branch` (String) Branch to deploy.
- `github_id` (String) Id of the GitHub provider configured in Dokploy.
- `owner` (String) Repository owner (user or org).
- `repository` (String) Repository name.

Optional:

- `build_path` (String) Path inside the repo to build from.
- `trigger_type` (String) What triggers an auto-deploy: `push` or `tag`. Dokploy writes this field on every source save whether or not the request carries it, so it always has a concrete value; it cannot be left unmanaged.

## Import

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
terraform import dokploy_application.example <applicationId>
```