Skip to main content
Manages a Kosli logical environment. Logical environments aggregate multiple physical environments for organizational purposes.
Logical environments can ONLY contain physical environments (K8S, ECS, S3, docker, server, lambda), not other logical environments. Attempting to include a logical environment will result in an error from the Kosli API.
This resource manages logical environment configuration and tags. For querying environment metadata such as last_modified_at and archived status, use the kosli_logical_environment data source.
Destroying this resource archives the logical environment in Kosli. Archiving requires an API token with the Admin role. A Member token can create and update logical environments, but terraform destroy fails with 403 Forbidden.
Changing name renames the logical environment in place, the same as kosli rename environment. The logical environment keeps its identity and history. The old name keeps resolving to the renamed environment until another environment is created with, or renamed to, that name. See Renaming logical environments.
Logical environments in Kosli aggregate multiple physical environments for organizational purposes, providing:
  • Unified visibility: View compliance status across multiple environments at once
  • Flexible grouping: Organize environments by region, service type, tier, or team
  • Simplified reporting: Generate compliance reports for logical groupings
  • Team organization: Allow different teams to focus on specific environment groups

Physical environments only

Logical environments can ONLY contain physical environments (K8S, ECS, S3, docker, server, lambda), not other logical environments. Attempting to include a logical environment will result in an API error.

Example usage

Complete example

For a comprehensive example showing logical environments aggregating physical environments by region, service type, and tier, see the complete logical environments example.

Common use cases

By environment tier

Aggregate all production or staging environments for unified compliance reporting:

By geographic region

Group environments by region for regional compliance or disaster recovery:

By service type

Organize environments by technology stack or service type:

Empty logical environments

Logical environments can be created with empty included_environments lists and populated later:

Import

Logical environments can be imported using their name:

Renaming logical environments

Changing name renames the logical environment in place, the same as kosli rename environment. The logical environment keeps its identity, snapshot history, included environments and tags, and the plan shows an update rather than a replacement. After a rename, the old name still resolves to the renamed logical environment for both reads and writes. The old name stops resolving once another environment is created with, or renamed to, that name. Terraform has no ordering between two resources that are both renamed in one plan. If one resource takes the name another is giving up, such as a to b together with b to c, or a swap, the rename that runs first can hit a name that still exists. Apply chained renames in separate steps.

Destroying logical environments

Kosli never hard-deletes environments. When you run terraform destroy or remove a kosli_logical_environment from your configuration, the provider archives the logical environment. The physical environments it included are not affected.
Archiving an environment requires a Kosli API token with the Admin role. A token with the Member role can create and update logical environments but cannot archive them. In that case, terraform destroy fails with 403 Forbidden and the resource stays in state. If you cannot use an Admin token and only want Terraform to stop managing the logical environment, run terraform state rm kosli_logical_environment.<name> instead. The logical environment then remains active in Kosli. See required permissions for how to set up a service account with the right permissions.

Querying metadata

Schema

Required

  • included_environments (List of String) List of physical environment names to aggregate. Only physical environments are allowed (K8S, ECS, S3, docker, server, lambda). Can be empty.
  • name (String) Name of the logical environment. Must be unique within the organization. Changing this renames the logical environment in place, keeping its snapshot history. The old name keeps resolving to the renamed environment until another environment is created with, or renamed to, that name.

Optional

  • description (String) Description of the logical environment. Explains the purpose and aggregation strategy.
  • tags (Map of String) Key-value pairs to tag the logical environment. Tags are applied via a diff — only changed tags are sent to the API. An empty map (tags = {}) removes all tags.

Read-only

  • type (String) Type of the environment. Always set to logical (computed by provider, not user-configurable).
Last modified on November 6, 2026