meshcloud / collie-hub

Curated hub with ready to use kit-modules for building landing zones with Collie CLI
https://collie.cloudfoundation.org
Apache License 2.0
30 stars 3 forks source link

Buildingblocks with collie-hub and collie-cli #141

Closed JohannesRudolph closed 1 month ago

JohannesRudolph commented 6 months ago

This issue collects various improvements for a simple and consistent workflow to deal with assembling tenants from buildingblocks using a pure IaC workflow using collie. Common examples of building blocks needed in a stage 2 (CFMM) cloudfoundation are a tenant building block (think subscription/account/project) that enforces tags + IAM role model, a budget alert (simple) and a hub+spoke vnet (complex).

The goals for the approach we want to support with collie are

Concept: Building Blocks

In terragrunt parlance, building blocks are "shared service modules"

A Terraform module that is designed to be standalone and applied directly. These modules are not root modules in that they are still missing the key blocks like backend and provider, but aside from that do not need any additional configuration or composition to deploy

Concept: Backplanes

Backplanes add what's necessary to successfully deploy a building block to a tenant in your landing zones. From the perspective of an application team, a building block provides some sort of capability to their application's cloud environment, e.g. an on-prem connected spoke VNet. This spoke VNet however is only the "tip of the iceberg". Application teams can't (and should not have to care about) all of the mechanics that make this spoke VNet work, like the hub network, WAN connection, IPAM and firewall rules.

We will call everything that makes the application-team visible part of the building block work the "backplane". The backplane always includes

Packaging Building Blocks in collie-hub

We will settle for the following structure for packaging building blocks in collie-hub

Deploying Building Blocks

Deploying building blocks to a cloud tenant becomes a simple terraform composition in a main.tf that invokes the building blocks as plain terraform modules like

module "subscription" {
  source = "github.com/likvid-bank/likvid-cloudfoundation/kit/azure/buildingblocks/subscription/buildingblock"
  subscription_name       = "glaskugel"
  parent_management_group = "likvid-corp"
}

module "connectivity" {
  source = "github.com/likvid-bank/likvid-cloudfoundation/kit/azure/buildingblocks/connectivity/buildingblock"

  providers = {
    azurerm.spoke = azurerm
    azurerm.hub   = azurerm.hub
  }

  location = "germanywestcentral"
  hub_rg   = "hub-vnet-rg"
  hub_vnet = "hub-vnet"

  name          = "glaskugel"
  address_space = ["10.1.0.0/24"]
}

Testing Building Blocks

Once we have deployed a building block backplane, it's very useful to ensure that this backplane can successfully deploy the building block in isolation. This can be achieved with terraform test and terragrunt like so

dependency "buildingblock" {
  config_path = "../budget-alert"
}

dependency "glaskugel" {
  config_path = "../../tenants/glaskugel"
}

generate "config" {
  path      = "config.tf"
  if_exists = "overwrite"
  contents  = dependency.buildingblock.outputs.config_tf
}

terraform {
  source = "${get_repo_root()}//kit/azure/buildingblocks/budget-alert/buildingblock"
}

inputs = {
  subscription_id = dependency.glaskugel.outputs.subscription_id
  contact_emails = "foo@example.com, bar@example.com"
}

open issues

Note: some of what's discussed in this issue here (especially the design principles) should end up on the collie documentation

JohannesRudolph commented 6 months ago

some BBs will have a very advanced backplane, e.g. the connectivity block requires the hub deployed from azure/kit/connectivity - should we go the trouble of always defining a dedicated backplane even if we could reuse the bootstraped SPN?

I'd say yes, we should always have dedicated backplanes. See https://github.com/meshcloud/collie-hub/issues/109 which would mean that the kit modules in collie-hub up to CFMM L2 don't come with an automation solution. Building Blocks are certainly an implementation of CFMM L3 Modular Landing Zones. We can therefore reasonably expect putting SPNs etc. on the learning curve for a CFT.

JohannesRudolph commented 6 months ago

Summary of an internal design session we've had with @florianow and @felixzieger

Decisions

  1. We assume shared backends are the norm for platform teams owning a set of building blocks. Backend authentication is orthogonal to provider authentication.
  2. We will pursue using terraform/opentofu test for "unit testing" building blocks. We may introduce a dedicated collie foundation test command to simplify this workflow
  3. Backplanes shared on collie-hub will not include backends and principals. The common interface is an input set of prinipal id's to grant permissions to. This allows both human-in-the-loop (e.g. platform engineers) and automation use cases.
  4. We will MVP this workflow in likvid-cloudfoundation and if that MVP is successful transplant this to collie-hub
JohannesRudolph commented 1 month ago

We have successfully landed a buildingblock design pattern in likvid-cloudfoundation that we are fairly happy with