From 8d749eacfe8ef66af0b3b09a03582d8033176c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Gr=C3=B8ndahl?= Date: Tue, 27 Jan 2026 12:36:44 +0100 Subject: [PATCH 1/3] docs: add admin guide for managing environments via Terraform --- .../managing_environments/_index.md | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 docs.kosli.com/content/administration/managing_environments/_index.md diff --git a/docs.kosli.com/content/administration/managing_environments/_index.md b/docs.kosli.com/content/administration/managing_environments/_index.md new file mode 100644 index 000000000..16917e423 --- /dev/null +++ b/docs.kosli.com/content/administration/managing_environments/_index.md @@ -0,0 +1,66 @@ +--- +title: Managing environments +bookCollapseSection: true +weight: 200 +summary: "Learn how to manage environments in Kosli, including creating, updating, and archiving environments." +--- + +# Managing environments +{{% required-roles roles="Admin" capability="archive Environments" %}} + +The following sections explain how to manage environments in Kosli, including creating, updating, and archiving environments. +The preferred way to manage environments is via Terraform to have your Kosli infrastructure as code. You can also use the Kosli CLI or the Kosli UI to manage environments. + +{{% hint info %}} +**Note**
+This guide focuses entirely on managing environments via Terraform. All documentation and examples are provided at the [Kosli Terraform provider](https://registry.terraform.io/providers/kosli-dev/kosli/latest/docs/). + +For information on creating environments via the CLI or UI, see [Part 8: Environments](/getting_started/environments/). +{{% /hint %}} + +## Importing existing environments + +If you have existing environments in Kosli that were created via the UI or CLI, you can import them into your Terraform state following these steps: + +### 1. Set up your Terraform configuration + +If you haven't already, set up the Kosli Terraform provider in your Terraform configuration. See the [Kosli Terraform provider documentation](https://registry.terraform.io/providers/kosli-dev/kosli/latest/docs) for details. + +Make sure you're using Terraform version 1.8 or later. See [Terraform installation guide](https://learn.hashicorp.com/tutorials/terraform/install-cli) for instructions. + +### 2. Identify the environment + +Identify the name of the environment you want to import. You can find this in the Kosli UI under `Environments` or by using the CLI command `kosli list environments`. + +### 3. Initialize Terraform + +Run `terraform init` to initialize your Terraform working directory if you haven't done so already. + +### 4. Create a Terraform resource block + +Create a Terraform resource block for the environment you want to import. This block should match the existing environment's configuration. + +```hcl +resource "kosli_environment" "my_environment" { + name = "production" + description = "Production environment" + type = "K(S)" # or other types that match your physical environment + # Add other attributes +} +``` + +### 5. Import the existing environment + +Run the following command to import the existing environment into your Terraform state. Replace `my_environment` with the name of your Terraform resource and `production` with the name of the environment in Kosli. + +```bash +terraform import kosli_environment.my_environment production +``` + +### 6. Verify the import + +Run `terraform plan` to verify that the environment has been imported correctly. The output should show no changes if the import was successful. From this point on, you can manage the Kosli environment using Terraform the same way as any other Terraform resource. + +## Reference + +Details on how to manage environments via Terraform can be found in the [Kosli Terraform provider documentation](https://registry.terraform.io/providers/kosli-dev/kosli/latest/docs/resources/environment). From 5c306f803ace3835cfe5d343a25c18035352b8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Gr=C3=B8ndahl?= Date: Tue, 27 Jan 2026 12:38:38 +0100 Subject: [PATCH 2/3] docs: let frontmatter summary be specific on Terraform management --- .../content/administration/managing_environments/_index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs.kosli.com/content/administration/managing_environments/_index.md b/docs.kosli.com/content/administration/managing_environments/_index.md index 16917e423..982f7b021 100644 --- a/docs.kosli.com/content/administration/managing_environments/_index.md +++ b/docs.kosli.com/content/administration/managing_environments/_index.md @@ -2,7 +2,7 @@ title: Managing environments bookCollapseSection: true weight: 200 -summary: "Learn how to manage environments in Kosli, including creating, updating, and archiving environments." +summary: "Learn how to manage environments in Kosli trough Terraform, including creating, updating, and archiving environments." --- # Managing environments From aa353e1704c9426fd163690eb573fcd52e903e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Gr=C3=B8ndahl?= Date: Tue, 27 Jan 2026 12:45:34 +0100 Subject: [PATCH 3/3] docs: clarify only physical environments are supported --- .../administration/managing_environments/_index.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs.kosli.com/content/administration/managing_environments/_index.md b/docs.kosli.com/content/administration/managing_environments/_index.md index 982f7b021..bc324acb9 100644 --- a/docs.kosli.com/content/administration/managing_environments/_index.md +++ b/docs.kosli.com/content/administration/managing_environments/_index.md @@ -13,14 +13,14 @@ The preferred way to manage environments is via Terraform to have your Kosli inf {{% hint info %}} **Note**
-This guide focuses entirely on managing environments via Terraform. All documentation and examples are provided at the [Kosli Terraform provider](https://registry.terraform.io/providers/kosli-dev/kosli/latest/docs/). +This guide focuses entirely on managing physical (non-logical) environments via Terraform.
All documentation and examples are provided at the [Kosli Terraform provider](https://registry.terraform.io/providers/kosli-dev/kosli/latest/docs/). For information on creating environments via the CLI or UI, see [Part 8: Environments](/getting_started/environments/). {{% /hint %}} ## Importing existing environments -If you have existing environments in Kosli that were created via the UI or CLI, you can import them into your Terraform state following these steps: +If you have existing physical environments in Kosli that were created via the UI or CLI, you can import them into your Terraform state following these steps: ### 1. Set up your Terraform configuration @@ -44,11 +44,18 @@ Create a Terraform resource block for the environment you want to import. This b resource "kosli_environment" "my_environment" { name = "production" description = "Production environment" - type = "K(S)" # or other types that match your physical environment + type = "K8S" # or other types that match your physical environment # Add other attributes } ``` +{{% hint warning %}} +**Warning**
+Make sure that the environment `type` in your Terraform configuration matches the type of the existing environment in Kosli. Mismatched types may lead to import errors or misconfigurations. + +Logical environment types is currently not supported for import. +{{% /hint %}} + ### 5. Import the existing environment Run the following command to import the existing environment into your Terraform state. Replace `my_environment` with the name of your Terraform resource and `production` with the name of the environment in Kosli. @@ -57,6 +64,7 @@ Run the following command to import the existing environment into your Terraform terraform import kosli_environment.my_environment production ``` + ### 6. Verify the import Run `terraform plan` to verify that the environment has been imported correctly. The output should show no changes if the import was successful. From this point on, you can manage the Kosli environment using Terraform the same way as any other Terraform resource.