Skip to main content
Fetches details of an existing Kosli environment. Use this data source to reference environments and access metadata like last modified and last reported timestamps. Environments represent runtime locations where artifacts are deployed and tracked for compliance monitoring. Use this data source to:
  • Reference existing environment configurations in other resources
  • Monitor environment activity (last modified, last reported timestamps)
  • Create conditional logic based on environment state
  • Build alerts and notifications based on environment metadata

Example usage

terraform {
  required_providers {
    kosli = {
      source = "kosli-dev/kosli"
    }
  }
}

# Query an existing environment
data "kosli_environment" "production" {
  name = "production-k8s"
}

# Use the data source to create a similar environment
resource "kosli_environment" "staging" {
  name        = "staging-k8s"
  type        = data.kosli_environment.production.type
  description = "Staging environment similar to ${data.kosli_environment.production.name}"
}

# Reference environment metadata for monitoring
output "production_last_modified" {
  description = "Timestamp of when production environment was last modified"
  value       = data.kosli_environment.production.last_modified_at
}

output "production_last_reported" {
  description = "Timestamp of when production environment last reported a snapshot"
  value       = data.kosli_environment.production.last_reported_at
}

output "production_type" {
  description = "Type of the production environment"
  value       = data.kosli_environment.production.type
}

output "production_includes_scaling" {
  description = "Whether production environment includes scaling events"
  value       = data.kosli_environment.production.include_scaling
}

# Conditional logic based on environment metadata
locals {
  # Check if environment has never reported a snapshot
  needs_attention = data.kosli_environment.production.last_reported_at == null
}

output "production_needs_attention" {
  description = "Whether production environment needs attention (never reported)"
  value       = local.needs_attention
}

Monitoring with data sources

The data source exposes timestamp fields that are useful for monitoring:
  • last_modified_at: Unix timestamp of when the environment configuration was last changed
  • last_reported_at: Unix timestamp of when the environment last reported a snapshot (can be null if never reported)
These timestamps enable you to:
  • Create alerts for environments that haven’t reported in a certain time period
  • Track configuration changes across your infrastructure
  • Build dashboards showing environment activity
  • Implement conditional deployment logic based on environment state

Read-only access

Data sources provide read-only access to environment metadata. To modify environment configurations, use the kosli_environment resource.

Schema

Required

  • name (String) The name of the environment to query.

Read-only

  • description (String) The description of the environment.
  • include_scaling (Boolean) Whether the environment includes scaling events in snapshots.
  • last_modified_at (Number) Unix timestamp (with fractional seconds) of when the environment was last modified.
  • last_reported_at (Number) Unix timestamp (with fractional seconds) of when the environment was last reported. May be null if never reported.
  • type (String) The environment type (e.g., K8S, ECS, S3, docker, server, lambda).
Last modified on March 16, 2026