~ / cursos / terraform
22 set 2026cursoMódulo 3 de 4

Terraform 3 — State remoto e workspaces

Backend remoto, locks e isolamento por ambiente.

Backend S3 + DynamoDB

terraform {
  backend "s3" {
    bucket         = "meu-tf-state"
    key            = "prod/app.tfstate"
    region         = "sa-east-1"
    dynamodb_table = "tf-locks"
    encrypt        = true
  }
}
terraform init -migrate-state

Workspaces (opcional)

terraform workspace new staging
terraform workspace select prod

Em projetos maiores, prefira pastas/envs separados ou Terragrunt em vez de muitos workspaces.