Skip to main content
Skip to main content

it-ae-tfmod-kion-account

Audience: Platform Engineers and Infrastructure Developers.

Purpose: Create Kion-specific resources for new accounts.


Overview

This Terraform module creates Kion-specific resources after AWS resources are provisioned. It is called by it-cloud-account-hub and is not intended as a standalone module.


Resources Created

Kion User Group

Creates a user group and associates it with the Azure AD group:

resource "kion_user_group" "account_group" {
name = var.account_name
description = "User group for ${var.account_name}"

idms_id = var.azure_ad_idms_id

saml_assertion_name = "http://schemas.microsoft.com/ws/2008/06/identity/claims/groups"
saml_assertion_regex = var.ad_group_id
}

Kion Project

Creates a project with budget allocation:

resource "kion_project" "new_project" {
name = var.account_name
description = "Project for ${var.account_name}"
ou_id = var.kion_ou_id

budget {
amount = var.expenditure
data = local.monthly_budget_breakdown
}
}

Budget Breakdown

The expenditure input is divided into monthly segments using an external Python script for budget planning.


Account Linking (API Call)

Terraform's Kion provider doesn't support account management as resources. A null_resource with local-exec makes an API call:

resource "null_resource" "link_aws_account_to_project" {
count = var.is_aws == true ? 1 : 0
depends_on = [kion_project.new_project]

provisioner "local-exec" {
command = <<EOT
curl -X 'POST' \
'https://kion.cloud.tamu.edu/api/v3/payer/1/link-project-account' \
-H "Authorization: Bearer $KION_APIKEY" \
-H 'Content-Type: application/json' \
-d '{
"account_email": "${var.account_email}",
"account_name": "${var.account_name}",
"account_number": "${var.account_number}",
"account_type_id": 1,
"project_id": ${kion_project.new_project.id}
}'
EOT
}
}

Cloud Access Role (CAR)

Creates a CAR for accessing the AWS account through Kion:

resource "kion_cloud_access_role" "admin_car" {
name = "${var.account_name}-admin"
aws_iam_role_name = "OrganizationAccountAccessRole"
project_id = kion_project.new_project.id

aws_iam_policies {
id = data.kion_aws_iam_policy.admin.id
}

user_groups {
id = kion_user_group.account_group.id
}
}

Resource Flow


Input Variables

VariableTypeDescription
is_awsboolFilter for AWS-only resources
account_namestringAccount name
account_numberstringAWS account ID
account_emailstringAccount root email
expenditurenumberBudget amount
ad_group_idstringAzure AD group object ID

Outputs

OutputDescription
project_idKion project ID
user_group_idKion user group ID
car_idCloud Access Role ID