Deploying the DevOps Stack to AKS

Prerequisites

  • Access to API keys allowing to create required resources in AWS,

  • Access to GitLab or GitHub (only supported CI/CD for now),

  • Knowledge of Terraform basics

Create your Terraform root module

Camptocamp’s DevOps stack is a Terraform composition module that has to be instantiated from the Terraform root module.

Here is a minimal working example:

# terraform/main.tf

locals {
  cluster_name = terraform.workspace
}
resource "azurerm_resource_group" "this" {
  name     = local.cluster_name
  location = "France Central"
}

module "network" {
  source  = "Azure/network/azurerm"
  version = "3.2.1"

  resource_group_name = azurerm_resource_group.this.name
  address_space       = "10.1.0.0/16"
  subnet_prefixes     = ["10.1.0.0/22"]
  vnet_name           = format("%s-network", local.cluster_name)
  subnet_names        = ["internal"]
  tags                = {}
}

module "cluster" {
 source = "git::https://github.com/camptocamp/camptocamp-devops-stack.git//modules/aks/azure?ref=v0.26.0"

  vnet_subnet_id      = module.network.vnet_subnets[0]
  resource_group_name = azurerm_resource_group.this.name
  base_domain         = "example.com"
  public_ssh_key      = "ssh-rsa ..."
  cluster_name        = local.cluster_name
}

Terraform Outputs

Define outputs:

# terraform/outputs.tf

output "argocd_auth_token" {
  sensitive = true
  value     = module.cluster.argocd_auth_token
}

output "kubeconfig" {
  sensitive = true
  value     = module.cluster.kubeconfig
}

output "repo_url" {
  value = module.cluster.repo_url
}

output "target_revision" {
  value = module.cluster.target_revision
}

output "app_of_apps_values" {
  sensitive = true
  value     = module.cluster.app_of_apps_values
}

Terraform Backend

If you wish to collaborate, define a backend to store your state:

# terraform/versions.tf

terraform {
  backend "remote" {
    organization = "example_corp"

    workspaces {
      name = "my-app-prod"
    }
  }
}

Deploying from your workstation

Even if one of the purpose of the DevOps Stack is to do everything in pipelines, you could deploy your cluster from your workstation using the Terraform CLI:

$ cd terraform
$ terraform init
$ terraform apply