Comment créer une infrastructure dans différents environnements à l'aide de Terraform

Terraform est un outil IaC (infrastructure as code) open source qui fournit un flux de travail cohérent dans la CLI pour gérer des centaines de services cloud. Terraform convertit les API cloud en fichiers de configuration déclaratifs.







, , , . Terraform, , .







image







. .









. . — . Terraform .







Terraform — IaC, , .

.









Terraform, .







— 1



terraform.tfvars. , .







. , . outputs.tf, providers.tf, variables.tf . . terraform : init, plan, apply



.







image

( 1)







:







  • ,
  • .


:







  • ;
  • , .


— 2



, terraform.tfvars. , .







main.tf variables.tf , terraform . , , :







// Dev Environment
terraform plan --var-file="tfvars/environment/dev.tfvars"
// QA Environment
terraform plan --var-file="tfvars/environment/qa.tfvars"
// Prod Environment
terraform plan --var-file="tfvars/environment/prod.tfvars"
      
      





image

( 2)







:







  • ;
  • , .


:







  • ;
  • , .




Terraform default. , , , . , , default.

terraform workspace



. . , terraform workspace new



.









— , . Terraform — root-. Root- , .tf .







, . , . , .







. , .







image







Terragrunt



Terragrunt — , DRY , Terraform .







.









  • Terraform — - IaC, CLI .
  • , , , .
  • Terraform.
  • — . .
  • Terraform default. , , , .
  • — , . , .
  • Terragrunt — , DRY , Terraform .


, Terraform. . .








All Articles