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:
-
Define the infrastructure in code — describe the necessary resources (virtual machines, networks, databases, etc.) in
.tffiles using HCL language. -
Initialize the project — run
terraform initto download the required providers and prepare the working directory. -
Plan the changes — use
terraform planto check what changes will be made to the infrastructure, to avoid unexpected consequences. -
Apply the changes — execute
terraform applyto create or update resources in the cloud or other environment. -
Manage state — use remote state storage (e.g., S3 for AWS) for collaboration and to preserve data about the current state of the infrastructure.
-
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.