Manages a Kosli environment. Environments represent deployment targets where artifacts are deployed. Supports physical environment types: K8S, ECS, S3, docker, server, and lambda.
This resource manages the environment configuration only. Environment tags are managed through a separate Kosli API. Environment policies will be available in a future release. For querying environment metadata such as last_modified_at, last_reported_at, and archived status, use the kosli_environment data source.
Kosli environments track deployments and provide visibility into what’s running in your infrastructure. Physical environments represent actual runtime locations such as:
- 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
Environment tags are managed through a separate Kosli API and are not included in this Terraform resource.
Environment policies will be available in a future release as a separate resource (kosli_environment_policy).
Example usage
terraform {
required_providers {
kosli = {
source = "kosli-dev/kosli"
}
}
}
# Basic K8S environment
resource "kosli_environment" "production_k8s" {
name = "production-k8s"
type = "K8S"
description = "Production Kubernetes cluster"
}
# ECS environment with scaling
resource "kosli_environment" "staging_ecs" {
name = "staging-ecs"
type = "ECS"
description = "Staging ECS cluster"
include_scaling = true
}
# S3 environment
resource "kosli_environment" "data_lake" {
name = "data-lake-s3"
type = "S3"
description = "Data lake S3 bucket environment"
}
# Docker environment
resource "kosli_environment" "local_docker" {
name = "local-docker"
type = "docker"
}
# Server environment
resource "kosli_environment" "production_servers" {
name = "production-servers"
type = "server"
description = "Production bare-metal servers"
include_scaling = false
}
# Lambda environment
resource "kosli_environment" "serverless_functions" {
name = "serverless-lambda"
type = "lambda"
description = "AWS Lambda functions"
}
Environment types
The type attribute must be one of the following physical environment types:
K8S - Kubernetes clusters
ECS - Amazon Elastic Container Service
S3 - Amazon S3 buckets
docker - Docker containers
server - Bare-metal or VM servers
lambda - AWS Lambda functions
Configuration options
Include scaling
The include_scaling attribute (default: false) determines whether scaling events in the environment should be tracked. This is useful for environments with auto-scaling where you want to monitor scale-up and scale-down events.
Import
Environments can be imported using their name:
#!/bin/bash
# Import an existing environment by name
terraform import kosli_environment.production_k8s production-k8s
# Import multiple environments
terraform import kosli_environment.staging_ecs staging-ecs
terraform import kosli_environment.data_lake data-lake-s3
Monitoring environments
For querying environment metadata such as last_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 will force recreation of the resource.
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.
include_scaling (Boolean) Whether to include scaling information when reporting environment snapshots. Defaults to false.