Sobes.tech
Junior — Middle

Describe how you deployed infrastructure using Terraform at your previous workplace.

sobes.tech AI

Answer from AI

When deploying infrastructure with Terraform, I usually follow these steps:

  1. Define the infrastructure in code — describe the necessary resources (virtual machines, networks, databases, etc.) in .tf files using HCL language.

  2. Initialize the project — run terraform init to download the required providers and prepare the working directory.

  3. Plan the changes — use terraform plan to check what changes will be made to the infrastructure, to avoid unexpected consequences.

  4. Apply the changes — execute terraform apply to create or update resources in the cloud or other environment.

  5. Manage state — use remote state storage (e.g., S3 for AWS) for collaboration and to preserve data about the current state of the infrastructure.

  6. Modularity and reusability — create modules for reusable infrastructure components, which simplifies maintenance and scaling.

An example of a simple Terraform resource to create a virtual machine in AWS:

provider "aws" {
  region = "us-west-2"
}

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
}

Thus, Terraform allows describing infrastructure declaratively, automating its deployment, and managing changes.