Skip to main content
Archiving environments requires the Admin role.
The preferred way to manage environments is via the , so your Kosli configuration is version-controlled alongside your infrastructure. You can also manage environments through the Kosli CLI or UI.
This page covers managing environments via Terraform. For creating environments via the CLI or UI, see Getting started: Environments.
Kosli has two environment types:
  • — each maps to a single runtime (e.g. a Kubernetes cluster or ECS service). Managed with the kosli_environment resource.
  • — aggregate one or more physical environments into a single view. Managed with the kosli_logical_environment resource.

Managing physical environments

Create a physical environment

resource "kosli_environment" "production" {
  name        = "production-k8s"
  description = "Production Kubernetes cluster"
  type        = "K8S"
}
Supported types: K8S, ECS, S3, docker, server, lambda.

Import an existing physical environment

If you have environments created via the UI or CLI, you can bring them under Terraform management by importing them into your .
  1. Find the environment name in the Kosli UI under Environments, or run:
kosli list environments
  1. Add a matching kosli_environment resource block to your configuration:
resource "kosli_environment" "my_environment" {
  name        = "production"
  description = "Production environment"
  type        = "K8S"  # must match the existing environment's type
}
  1. Run the import:
terraform import kosli_environment.my_environment production
  1. Verify with terraform plan — no changes should be planned if the import succeeded.
The type in your Terraform configuration must exactly match the type of the existing environment in Kosli. A mismatch will cause import errors or misconfiguration.

Managing logical environments

Logical environments group physical environments into a combined view — useful for representing a full production tier across multiple runtimes.

Create a logical environment

resource "kosli_logical_environment" "production_all" {
  name                  = "production-all"
  description           = "All production environments"
  included_environments = ["production-k8s", "production-ecs", "production-lambda"]
}
included_environments must reference the names of existing physical environments. Logical environments cannot include other logical environments.

Import an existing logical environment

  1. Find the logical environment name:
kosli list environments
  1. Add a matching kosli_logical_environment resource block:
resource "kosli_logical_environment" "production_all" {
  name                  = "production-all"
  included_environments = ["production-k8s", "production-ecs"]
}
  1. Run the import:
terraform import kosli_logical_environment.production_all production-all
  1. Verify with terraform plan — no changes should be planned if the import succeeded.

Reference

Last modified on March 11, 2026