Skip to main content

IaaS Terraform deploy

Instead of creating resources on AWS manually or through AWS CLI it was decided to use Terraform. It helps to define every resource via code, and made changes easily trackable through git history, allow not to think which resources you need to create on new ENV. You just need to run a batch of commands and that's it.

General info:

  • Infrastructure configuration contained in infrastructure/terrafrom folder
  • Resources split on modules, each module contain next files
    • main.tf - main description of the module
    • output.tf - information about created resources, that can be used in other modules (created ARN of resource, name, id ...)
    • variables.tf - define variables which are used in main.tf , they can describe different parameters such as: names, stage,
  • Root folder contains next files:
    • XXX.tfvars - env files, with sensitive information for creating resources (currently there is specified vpc info (it's better to create VPC in file, but since it's already created I keep the old one instead of creating new one ) and stage). XXX is prod or dev
    • main.tf - terraform's entry point, describe terraform required version, terraform state and providers. It assembling all created modules and providing them with required variables.
    • variables.tf - required variables to run app (these variables go to main function from XXX.tfvars file)
    • README.md - contain usefull command

First run

  • Install terrafrom >v1.3.3
  • run terraform init - install dependencies and get remote state
  • terraform workspace select ENV -- switched to required enviroment prod or dev
  • run terraform plan -var-file=XXX.tfvars show resources that will created
  • run terraform apply -var-file=XXX.tfvars deploy resources

**If you have 403 Forbidden error -> use VPN, because Terraform doesn't work in some countries (Belarus, Russia etc)