--- title: "Create an environment" canonical: "https://admiral.io/docs/api/projects/EnvironmentAPI_CreateEnvironment" --- # Create an environment `POST https://api.admiral.io/v1/projects/{project}/environments` - NOT_FOUND when the project does not exist. - ALREADY_EXISTS when the project already has an environment with that name. Scope: `env:write` ### Path parameters - `project` (string, required): The project id. ### Query parameters - `request_id` (string (uuid)): (OPTIONAL) A UUID the client generates once per create and sends again on every retry. A repeat within 24 hours returns the first result and creates nothing. The same id with a different request is refused with INVALID_ARGUMENT. Without one, every call creates. request_id.not_zero // request_id may not be the zero UUID ### Request body - `uid` (string): `env-` and twelve base36 characters. Never changes and is never reused, so it is what a reference to the environment holds. Pattern `^env-[0-9a-z]+$`. Read-only. - `name` (string, required): (IMMUTABLE) The name, such as `dev`. Unique among the project's environments, so two projects may each have a `prod`. Set on create and changed only by RenameEnvironment. Lowercase letters, digits and hyphens, starting with a letter and ending with a letter or digit, 1 to 63 characters. It may not have the shape of a uid (`env-` and twelve characters). name.not_uid // an environment name may not have the shape of a uid Pattern `^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`. Length 1 to 63. - `display_name` (string): A label for people, such as "Production". Optional; clients show the name when it is unset. Length at most 128. - `resource_name` (string): (IDENTIFIER) The resource name, `projects/{project}/environments/{environment}`, such as `projects/payments-api/environments/dev`. Built from the names of the environment and its project, so it changes when either is renamed; refer to an environment by `uid` to keep a reference stable. Identifies the environment on update. Pattern `^projects/([a-z]([a-z0-9-]{0,61}[a-z0-9])?|-)/environments/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`. - `description` (string): Optional longer-form description of the environment's purpose (e.g., "US East production serving live traffic" or "Shared staging for QA validation before prod promotion"). Length at most 1024. - `project_id` (string): The project's uid, which survives a rename of the project. Pattern `^prj-[0-9a-z]+$`. Read-only. - `labels` (map of string to string): Arbitrary key-value labels for organizing and filtering environments (e.g., `{"region": "us-east-1", "tier": "production"}`). - `agents` (array of AgentAssignment): The agents this environment deploys through, each with how this environment uses it. Several of one kind are allowed: an IAM agent beside an ordinary one, say. A component runs on the assignment its settings name, or on the only one of its kind. Two environments can share an agent and differ in settings, such as dev and staging in one cluster under different namespaces. - `agent_id` (string, required): The agent. Its owner must have granted it to the organization, a team, this project or this environment. Pattern `^agt-[0-9a-z]+$`. - `id` (string): `asg-` and twelve base36 characters, what a component's settings name to run on this assignment. Empty on an assignment being added, which gets one; send it back unchanged when updating the list, or the assignment is treated as new and components placed on the old one are refused. Pattern `^asg-[0-9a-z]+$`. - `kubernetes` (KubernetesSettings): KubernetesSettings is how an environment uses a Kubernetes agent. - `default_namespace` (string): The namespace a component renders into unless it names its own. Set to `-` when the environment is created if left empty; at most 63 characters. Pattern `^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)?$`. Length at most 63. - `create_namespaces` (boolean): Whether a missing namespace is created at apply. The agent's own setting and its RBAC can still refuse. Defaults to true on create. - `prune` (boolean): Whether an apply deletes objects a component no longer renders, and the objects of a component it removes. Off, they are orphaned: left in the cluster and no longer managed. An object annotated `admiral.io/prune: "false"` is orphaned either way. Defaults to true on create. - `approval` (ApprovalRule): What an apply here needs before it runs. Unset needs nothing. - `required_approvals` (integer (int32)): Distinct people who must approve the planned revision, from anyone allowed to. 0 needs none. Value at least 0. - `groups` (array of GroupApproval): Groups that must each approve, all of them. One person's approval counts for every group they belong to; to need two people, also set required_approvals to 2. approval_rule.unique_groups // a group appears at most once Items at most 16. - `group_id` (string, required): Pattern `^grp-[0-9a-z]+$`. - `approvals` (integer (int32)): Value at least 1. - `infra_backend` (InfraBackend): Where its Terraform components' state lives. Admiral writes it into every run at a location it derives per component, and a component may replace it. Absent means hosted state. Fixed once a Terraform component in the environment has applied. - `type` (string): The backend type as Terraform names it: `gcs`, `s3`, `azurerm`, `http`. Never `local`, which would leave state on the agent's disk. Not `local`. Pattern `^[a-z][a-z0-9_]*$`. Length at most 32. - `config` (map of string to Value): The backend's arguments, as the backend block takes them. On an environment, the bucket and its settings, without the key or prefix; Admiral derives the location per component. Admiral refuses credential arguments. - `infra_engine` (InfraEngineVersion): The engine and exact version its Terraform components run. A component whose `required_version` is exact runs this engine at that version instead, and does not block a change here. Setting it is refused when a component's range refuses it, when it is below a version a component last applied with, or when a placed agent cannot run it; the refusal names every such component. Each component moves to it at its next plan. - `engine` (Engine): enum.defined_only = true One of `TERRAFORM`, `OPENTOFU`. - `version` (string): Exact, e.g. `1.10.6`. Pattern `^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$`. Length at most 64. - `tracking` (Tracking): How the environment takes newly published versions of the components it runs. Unset, the environment is pinned: a publish changes nothing here, and it moves only by a change set someone writes. - `kind` (Kind, required): enum.defined_only = true One of `BRANCH`, `TAG`, `RANGE`. - `pattern` (string, required): Length 1 to 128. - `after_merge` (AfterMerge): enum.defined_only = true One of `AFTER_MERGE_UNSPECIFIED`, `APPLY`, `WAIT`. - `generation` (string (int64)): Moves each time an apply changes the environment. A change set records the generation it was cut from. Read-only. - `hold` (Hold): Set while a partial apply holds the environment. Nothing else applies until the holding change set is reverted or accepted. Read-only. - `change_set_id` (string): The change set whose partial apply holds the environment. Pattern `^cs-[0-9a-z]+$`. - `held_at` (Timestamp): When the partial apply finished. - `run_id` (string): The run whose apply left the hold. Pattern `^run-[0-9a-z]+$`. - `last_apply` (LastApply): The apply that produced the current generation. Absent until the first apply changes the environment. Read-only. - `change_set_id` (string): The change set that was applied. Pattern `^cs-[0-9a-z]+$`. - `revision_id` (string): The change set revision that was applied. Pattern `^rev-[0-9a-z]+$`. - `applied_at` (Timestamp): When the apply finished. - `run_id` (string): The run whose apply this was. Pattern `^run-[0-9a-z]+$`. - `etag` (string): Changes whenever the environment does. Send it back on update, rename or delete to refuse the change if someone else changed the environment first. Read-only. - `created_by` (ActorRef): The user or agent who created this environment. Read-only. - `id` (string): The actor's typed id: a `usr-` user id or an `sa-` service account id. - `display_name` (string): Human-readable name (e.g., "John Smith", "deploy-bot"). - `email` (string): Email address (empty for non-human actors). - `created_at` (Timestamp): When the environment was created. Read-only. - `updated_at` (Timestamp): When the environment was last updated. Read-only. ### Response 200 Success - `environment` (Environment): The created environment. - `uid` (string): `env-` and twelve base36 characters. Never changes and is never reused, so it is what a reference to the environment holds. Pattern `^env-[0-9a-z]+$`. Read-only. - `name` (string, required): (IMMUTABLE) The name, such as `dev`. Unique among the project's environments, so two projects may each have a `prod`. Set on create and changed only by RenameEnvironment. Lowercase letters, digits and hyphens, starting with a letter and ending with a letter or digit, 1 to 63 characters. It may not have the shape of a uid (`env-` and twelve characters). name.not_uid // an environment name may not have the shape of a uid Pattern `^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`. Length 1 to 63. - `display_name` (string): A label for people, such as "Production". Optional; clients show the name when it is unset. Length at most 128. - `resource_name` (string): (IDENTIFIER) The resource name, `projects/{project}/environments/{environment}`, such as `projects/payments-api/environments/dev`. Built from the names of the environment and its project, so it changes when either is renamed; refer to an environment by `uid` to keep a reference stable. Identifies the environment on update. Pattern `^projects/([a-z]([a-z0-9-]{0,61}[a-z0-9])?|-)/environments/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`. - `description` (string): Optional longer-form description of the environment's purpose (e.g., "US East production serving live traffic" or "Shared staging for QA validation before prod promotion"). Length at most 1024. - `project_id` (string): The project's uid, which survives a rename of the project. Pattern `^prj-[0-9a-z]+$`. Read-only. - `labels` (map of string to string): Arbitrary key-value labels for organizing and filtering environments (e.g., `{"region": "us-east-1", "tier": "production"}`). - `agents` (array of AgentAssignment): The agents this environment deploys through, each with how this environment uses it. Several of one kind are allowed: an IAM agent beside an ordinary one, say. A component runs on the assignment its settings name, or on the only one of its kind. Two environments can share an agent and differ in settings, such as dev and staging in one cluster under different namespaces. - `agent_id` (string, required): The agent. Its owner must have granted it to the organization, a team, this project or this environment. Pattern `^agt-[0-9a-z]+$`. - `id` (string): `asg-` and twelve base36 characters, what a component's settings name to run on this assignment. Empty on an assignment being added, which gets one; send it back unchanged when updating the list, or the assignment is treated as new and components placed on the old one are refused. Pattern `^asg-[0-9a-z]+$`. - `kubernetes` (KubernetesSettings): KubernetesSettings is how an environment uses a Kubernetes agent. - `default_namespace` (string): The namespace a component renders into unless it names its own. Set to `-` when the environment is created if left empty; at most 63 characters. Pattern `^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)?$`. Length at most 63. - `create_namespaces` (boolean): Whether a missing namespace is created at apply. The agent's own setting and its RBAC can still refuse. Defaults to true on create. - `prune` (boolean): Whether an apply deletes objects a component no longer renders, and the objects of a component it removes. Off, they are orphaned: left in the cluster and no longer managed. An object annotated `admiral.io/prune: "false"` is orphaned either way. Defaults to true on create. - `approval` (ApprovalRule): What an apply here needs before it runs. Unset needs nothing. - `required_approvals` (integer (int32)): Distinct people who must approve the planned revision, from anyone allowed to. 0 needs none. Value at least 0. - `groups` (array of GroupApproval): Groups that must each approve, all of them. One person's approval counts for every group they belong to; to need two people, also set required_approvals to 2. approval_rule.unique_groups // a group appears at most once Items at most 16. - `group_id` (string, required): Pattern `^grp-[0-9a-z]+$`. - `approvals` (integer (int32)): Value at least 1. - `infra_backend` (InfraBackend): Where its Terraform components' state lives. Admiral writes it into every run at a location it derives per component, and a component may replace it. Absent means hosted state. Fixed once a Terraform component in the environment has applied. - `type` (string): The backend type as Terraform names it: `gcs`, `s3`, `azurerm`, `http`. Never `local`, which would leave state on the agent's disk. Not `local`. Pattern `^[a-z][a-z0-9_]*$`. Length at most 32. - `config` (map of string to Value): The backend's arguments, as the backend block takes them. On an environment, the bucket and its settings, without the key or prefix; Admiral derives the location per component. Admiral refuses credential arguments. - `infra_engine` (InfraEngineVersion): The engine and exact version its Terraform components run. A component whose `required_version` is exact runs this engine at that version instead, and does not block a change here. Setting it is refused when a component's range refuses it, when it is below a version a component last applied with, or when a placed agent cannot run it; the refusal names every such component. Each component moves to it at its next plan. - `engine` (Engine): enum.defined_only = true One of `TERRAFORM`, `OPENTOFU`. - `version` (string): Exact, e.g. `1.10.6`. Pattern `^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$`. Length at most 64. - `tracking` (Tracking): How the environment takes newly published versions of the components it runs. Unset, the environment is pinned: a publish changes nothing here, and it moves only by a change set someone writes. - `kind` (Kind, required): enum.defined_only = true One of `BRANCH`, `TAG`, `RANGE`. - `pattern` (string, required): Length 1 to 128. - `after_merge` (AfterMerge): enum.defined_only = true One of `AFTER_MERGE_UNSPECIFIED`, `APPLY`, `WAIT`. - `generation` (string (int64)): Moves each time an apply changes the environment. A change set records the generation it was cut from. Read-only. - `hold` (Hold): Set while a partial apply holds the environment. Nothing else applies until the holding change set is reverted or accepted. Read-only. - `change_set_id` (string): The change set whose partial apply holds the environment. Pattern `^cs-[0-9a-z]+$`. - `held_at` (Timestamp): When the partial apply finished. - `run_id` (string): The run whose apply left the hold. Pattern `^run-[0-9a-z]+$`. - `last_apply` (LastApply): The apply that produced the current generation. Absent until the first apply changes the environment. Read-only. - `change_set_id` (string): The change set that was applied. Pattern `^cs-[0-9a-z]+$`. - `revision_id` (string): The change set revision that was applied. Pattern `^rev-[0-9a-z]+$`. - `applied_at` (Timestamp): When the apply finished. - `run_id` (string): The run whose apply this was. Pattern `^run-[0-9a-z]+$`. - `etag` (string): Changes whenever the environment does. Send it back on update, rename or delete to refuse the change if someone else changed the environment first. Read-only. - `created_by` (ActorRef): The user or agent who created this environment. Read-only. - `id` (string): The actor's typed id: a `usr-` user id or an `sa-` service account id. - `display_name` (string): Human-readable name (e.g., "John Smith", "deploy-bot"). - `email` (string): Email address (empty for non-human actors). - `created_at` (Timestamp): When the environment was created. Read-only. - `updated_at` (Timestamp): When the environment was last updated. Read-only.