Přeskočit na obsah
_CORE
AI & Agentic Systems Core Informační Systémy Cloud & Platform Engineering Data Platforma & Integrace Security & Compliance QA, Testing & Observability IoT, Automatizace & Robotika Mobile & Digital Banky & Finance Pojišťovnictví Veřejná správa Obrana & Bezpečnost Zdravotnictví Energetika & Utility Telco & Média Průmysl & Výroba Logistika & E-commerce Retail & Loyalty
Reference Technologie Blog Know-how
Nástroje O nás Spolupráce Kariéra
Pojďme to probrat

Infrastructure as Code — Pokročilé Patterns

11. 07. 2022 1 min čtení intermediate

DevOps Pokročilý

Infrastructure as Code — Pokročilé Patterns

IaCTerraformInfrastructureDevOps 5 min čtení

IaC best practices. Terraform modules, state management, testing a drift detection.

Module Design

# modules/k8s-cluster/main.tf
variable "cluster_name" { type = string }
variable "node_count" { type = number; default = 3 }
variable "node_size" { type = string; default = "Standard_D4s_v3" }

resource "azurerm_kubernetes_cluster" "main" {
  name                = var.cluster_name
  location            = var.location
  resource_group_name = var.resource_group

  default_node_pool {
    name       = "default"
    node_count = var.node_count
    vm_size    = var.node_size
  }
}

output "kube_config" {
  value     = azurerm_kubernetes_cluster.main.kube_config_raw
  sensitive = true
}

# Použití
module "prod_cluster" {
  source       = "./modules/k8s-cluster"
  cluster_name = "prod-eu"
  node_count   = 5
  node_size    = "Standard_D8s_v3"
}

State Management

  • Remote state: vždy (S3, Azure Blob, GCS)
  • State locking: DynamoDB / Azure Blob lease
  • State per environment: oddělte dev/staging/prod
  • Sensitive outputs: sensitive = true
  • Import: terraform import pro existující zdroje

Testing

# Terratest (Go)
func TestKubernetesCluster(t *testing.T) {
  terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
    TerraformDir: "../modules/k8s-cluster",
    Vars: map[string]interface{}{
      "cluster_name": "test-cluster",
      "node_count":   1,
    },
  })
  defer terraform.Destroy(t, terraformOptions)
  terraform.InitAndApply(t, terraformOptions)

  kubeConfig := terraform.Output(t, terraformOptions, "kube_config")
  assert.NotEmpty(t, kubeConfig)
}

Shrnutí

IaC vyžaduje stejnou disciplínu jako aplikační kód: moduly, testy, code review a CI/CD. Remote state a locking jsou základ.

Potřebujete pomoct s implementací?

Náš tým má zkušenosti s návrhem a implementací moderních architektur. Rádi vám pomůžeme.

Nezávazná konzultace

Sdílet:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.