Destroying this resource archives the environment in Kosli. Archiving requires an API token with the Admin role. A Member token can create and update environments, but
terraform destroy fails with 403 Forbidden.Changing
name renames the environment in place, the same as kosli rename environment. The 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 environments.- K8S: Kubernetes clusters
- ECS: Amazon Elastic Container Service clusters
- S3: Amazon S3 buckets
- docker: Docker containers
- server: Bare-metal or VM servers
- lambda: AWS Lambda functions
For aggregating multiple physical environments into logical groups, use the
kosli_logical_environment resource.To attach compliance policies to environments, use the
kosli_policy_attachment resource.Example usage
Environment types
Thetype attribute must be one of the following physical environment types:
K8S- Kubernetes clustersECS- Amazon Elastic Container ServiceS3- Amazon S3 bucketsdocker- Docker containersserver- Bare-metal or VM serverslambda- AWS Lambda functions
Import
Environments can be imported using their name:Renaming environments
Changingname renames the environment in place, the same as kosli rename environment. The environment keeps its identity, snapshot history and tags, and the plan shows an update rather than a replacement.
After a rename, the old name still resolves to the renamed environment for both reads and writes. kosli snapshot commands that still use the old name report into the renamed environment. 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.
You can’t change
type in Kosli. A plan that changes type still replaces the environment, even when name changes in the same plan.Destroying environments
Kosli never hard-deletes environments. When you runterraform destroy or remove a kosli_environment from your configuration, the provider archives the environment. The environment disappears from the environment list in Kosli, but Kosli keeps its snapshot history.
Archiving an environment requires a Kosli API token with the Admin role. A token with the Member role can create and update 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 environment, run terraform state rm kosli_environment.<name> instead. The environment then remains active in Kosli. See required permissions for how to set up a service account with the right permissions.Monitoring environments
For querying environment metadata such aslast_modified_at and last_reported_at timestamps, use the kosli_environment data source. This is useful for monitoring and creating conditional logic based on environment state.
Schema
Required
name(String) Name of the environment. Must be unique within the organization. Changing this renames the 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.type(String) Type of the environment. Valid values:K8S,ECS,S3,docker,server,lambda. Changing this will force recreation of the resource.
Optional
description(String) Description of the environment. Explains the purpose and characteristics of this deployment target.tags(Map of String) Key-value pairs to tag the environment. Tags are applied via a diff — only changed tags are sent to the API. An empty map (tags = {}) removes all tags.