Managing the Kion Application Stack with Terraform

Last updated: December 3, 2026

Kion ships its AWS deployment as CloudFormation templates. If your organization manages infrastructure with Terraform, you can still bring your Kion application stack under Terraform without rewriting or forking our templates. Terraform owns the stack, and CloudFormation continues to deploy Kion from the template we publish for each release.

This article covers bringing an existing kion-app stack under Terraform, upgrading Kion by changing a single version variable, and the caveats to know before you start.

Note: Terraform does not replace the CloudFormation update process; it drives it. Everything in Updating AWS Deployments still applies, including taking a manual RDS snapshot before every update.

How It Works

The HashiCorp AWS provider includes the aws_cloudformation_stack resource. It manages a CloudFormation stack as a single Terraform resource:

  • template_url points to Kion's published template for the version you want to run.

  • parameters holds the same values you would enter on the CloudFormation Parameters page.

  • When you change either one and run terraform apply, Terraform performs a CloudFormation stack update. CloudFormation then creates, updates, and rolls back resources exactly as it does when you update the stack in the console.

Kion's release templates are published at:

  • EC2 deployment: https://kion-release.s3.amazonaws.com/[VERSION]/kion-app.yml

  • ECS deployment: https://kion-release.s3.amazonaws.com/[VERSION]/kion-app-ecs.yml

Replace [VERSION] with the release number, for example 3.15.16. You must use template_url, not template_body, because Kion's templates are larger than the 51,200 byte limit for an inline template body.

Prerequisites

  • Terraform 1.5 or later (for import blocks) and the hashicorp/aws provider.

  • AWS credentials for the account and region that host Kion, with permission to update the stack and the IAM, EC2 or ECS, load balancer, and other resources it manages. The credentials must stay valid for the full length of an update. A session that expires partway through can fail the update, just as a console session timeout can.

  • A remote Terraform state backend with encryption and restricted access. Stack parameters, including database settings, are stored in Terraform state.

  • The AWS CLI and jq, to export your current stack settings.

  • A current, manual RDS snapshot of your Kion database before you apply any change.

We recommend storing your database and Redis passwords in SSM Parameter Store (SecureString) or Secrets Manager and setting DB Password Type and RedisCredentialType accordingly. Your Terraform configuration then holds only the parameter name or secret ARN, not the password itself. See Secret Encryption and Storage.

Step 1: Record Your Current Stack Settings

When CloudFormation updates a stack, any parameter you do not supply is reset to the template's default value. Terraform does not supply previous values automatically, so your configuration must include every parameter the stack uses today. Do not rely on terraform plan to tell you which ones are missing.

Export the current parameter values:

aws cloudformation describe-stacks --stack-name kion-app \
  --query 'Stacks[0].Parameters' --output json \
  | jq 'map({(.ParameterKey): .ParameterValue}) | add' > kion-app-parameters.json

Then record the other stack settings Terraform will manage:

aws cloudformation describe-stacks --stack-name kion-app \
  --query 'Stacks[0].{Description:Description,Capabilities:Capabilities,Tags:Tags,RoleARN:RoleARN,TimeoutInMinutes:TimeoutInMinutes,NotificationARNs:NotificationARNs}'
  • Description shows the Kion version the stack is running, for example Deploys Kion 3.15.16. Use this version in Step 2.

  • Tags, RoleARN, and NotificationARNs must be copied into your configuration if they are set. Otherwise Terraform will try to remove them.

  • TimeoutInMinutes must be copied to timeout_in_minutes if it is set. A change to this setting forces Terraform to replace the stack.

Review kion-app-parameters.json before you use it:

  • Parameters that CloudFormation masks appear as ****. These are DatabasePassword and RedisPassword, plus RegistryToken for ECS deployments. Replace each with the real value (the SSM parameter name or secret ARN if you followed the recommendation above).

  • Keep list parameters such as PrivateSubnets as comma-separated strings, exactly as exported.

Step 2: Write the Configuration

The example below is for an EC2 deployment. For ECS, change local.kion_template to kion-app-ecs.yml.

terraform {
  required_version = ">= 1.5"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 5.0"
    }
  }
}

variable "kion_version" {
  description = "Kion release to run, for example 3.15.16"
  type        = string
}

locals {
  # EC2 deployments use kion-app.yml. ECS deployments use kion-app-ecs.yml.
  kion_template = "kion-app.yml"
}

resource "aws_cloudformation_stack" "kion_app" {
  name         = "kion-app"
  template_url = "https://kion-release.s3.amazonaws.com/${var.kion_version}/${local.kion_template}"

  # The template creates IAM roles and policies (CAPABILITY_IAM). It also
  # gives them custom names when CustomEC2RolePrefix (EC2) or
  # CustomRolePrefix (ECS) is set, which requires CAPABILITY_NAMED_IAM.
  capabilities = ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]

  # Every parameter from Step 1, with masked values replaced.
  parameters = jsondecode(file("${path.module}/kion-app-parameters.json"))

  # Copy these from Step 1 if they are set on your stack.
  # tags               = { ... }
  # iam_role_arn       = "arn:aws:iam::123456789012:role/..."
  # notification_arns  = ["arn:aws:sns:..."]
  # timeout_in_minutes = 60

  timeouts {
    create = "90m"
    update = "90m"
    delete = "90m"
  }

  lifecycle {
    prevent_destroy = true
  }
}

import {
  to = aws_cloudformation_stack.kion_app
  id = "kion-app"
}

Set kion_version in a .tfvars file to the version from Step 1. If your stack has a name other than kion-app (for example, an older cloudtamer-app stack), use that name in both name and the import block.

The timeouts values give Terraform enough time to wait for CloudFormation. The provider default is 30 minutes, which a Kion update can exceed. Adjust them to match how long your updates usually take.

Step 3: Import the Existing Stack

Run:

terraform init
terraform plan -var-file=kion.tfvars

On the first plan after import, Terraform reports an in-place update to aws_cloudformation_stack.kion_app. This is expected: Terraform does not read template_url or your parameter values back during import, so it shows them as being added. Before applying, confirm all of the following:

  • The plan says update in-place, never must be replaced or destroy.

  • template_url points to the version the stack runs today.

  • Every parameter value matches what you exported in Step 1.

  • Tags, iam_role_arn, and notification_arns are not being removed.

When the plan looks right, take a manual RDS snapshot and run:

terraform apply -var-file=kion.tfvars

Because the template and values are the same as what is deployed, CloudFormation reports that no updates are needed and the stack is unchanged. Terraform now manages the stack. You can remove the import block after this apply.

Upgrading Kion

Follow the preparation steps in Updating AWS Deployments and review the Release Notes for your target version. Then:

  1. Take a manual RDS snapshot.

  2. Change kion_version to the target version.

  3. If the release notes call out new parameters that you need to set to something other than their default, add them to kion-app-parameters.json.

  4. Run terraform plan. The only change should be template_url (plus any parameters you deliberately added).

  5. Run terraform apply. Terraform waits while CloudFormation updates the stack.

  6. If the stack update fails and CloudFormation rolls back, terraform apply reports an error. Set kion_version back to the version you were running so your configuration matches the stack, then follow the troubleshooting guidance in Updating AWS Deployments and send the Events tab to Kion Support.

Make one change per apply, just as you would in the console. For example, upgrade the version in one apply and change network or AMI parameters in a separate apply.

Rolling Back After a Successful Upgrade

To roll back to a previous version after a successful upgrade, follow Rolling Back After a Successful Upgrade in Updating AWS Deployments, with one difference: make the application stack changes in Terraform instead of the console. Set kion_version to the previous version, update the database endpoint and security group parameters to point at your restored database, and run terraform apply.

Caveats

  • Make all stack changes through Terraform. If someone updates the stack in the console, the next terraform apply can undo their change. If a console change is unavoidable, update your Terraform configuration to match before the next apply.

  • Terraform does not detect every kind of drift. It compares parameter values, tags, and stack settings. It does not notice if the stack's template was replaced outside Terraform, and it does not see resources changed outside CloudFormation. Use CloudFormation drift detection for the latter.

  • Masked parameters may always show as changing. CloudFormation returns **** for DatabasePassword, RedisPassword, and RegistryToken, so terraform plan may show them changing on every run. When those are the only changes, applying sends the same values and the stack does not change.

  • Never accept a replacement. A plan that replaces or destroys aws_cloudformation_stack.kion_app would delete and recreate your Kion application stack. Keep prevent_destroy = true. Note that some resources in the template are retained when the stack is deleted.

  • Partitions without access to the release bucket. If CloudFormation in your region or partition cannot read kion-release.s3.amazonaws.com (for example AWS GovCloud (US) or an air-gapped environment), copy the template into an S3 bucket in your own account and point template_url at that copy. For EC2 deployments without internet access, the release archive must also be in your deploy bucket, as described in Updating AWS Deployments.

  • Database and Redis stacks. The same approach works for the kion-db and kion-redis stacks, but the database stack carries extra risk. In particular, a changed or removed DB Snapshot ARN value can cause CloudFormation to create a new, empty database. We recommend starting with the application stack and contacting Kion Support before managing the database stack with Terraform.

New Deployments

You can also use the same resource to create a new kion-app stack. Leave out the import block and supply the parameters described in AWS EC2 Deployment: Standard Deployment or AWS ECS Deployment: Standard Deployment.

Related Articles