Cloud Experte
Terraform — Fortgeschrittene Muster¶
TerraformIaCHCLState Management 5 min Lesezeit
Remote State, Locking, Moved Blocks, Import und CI/CD-Pipeline.
Remote State¶
terraform {
backend "s3" {
bucket = "mycompany-tf-state"
key = "prod/infra.tfstate"
region = "eu-west-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}
Import und Moved¶
# Import (TF 1.5+)
import {
to = aws_s3_bucket.main
id = "my-existing-bucket"
}
# Moved — Refactoring ohne Destroy
moved {
from = aws_instance.web
to = module.compute.aws_instance.web
}
CI/CD¶
name: Terraform
on: [pull_request, push]
jobs:
terraform:
steps:
- run: terraform init
- run: terraform fmt -check
- run: terraform plan -out=tfplan
- run: terraform apply -auto-approve tfplan
if: github.ref == 'refs/heads/main'
Zusammenfassung¶
Fortgeschrittenes TF = Remote State + CI/CD + Import für Brownfield + Moved für Refactoring.
Brauchen Sie Hilfe bei der Implementierung?¶
Unser Team hat Erfahrung mit dem Entwurf und der Implementierung moderner Architekturen. Wir helfen Ihnen gerne.