Sobes.tech
Junior — Middle

What steps are involved in deploying a new resource or object into the infrastructure using Terraform?

sobes.tech AI

Answer from AI

The process of deploying a new resource or object into infrastructure using Terraform typically involves the following steps:

  1. Defining the resource in the configuration — a new resource with the necessary parameters is described in a .tf file.

  2. Initializing Terraform — the command terraform init downloads the required providers and modules.

  3. Checking the plan of changesterraform plan shows what changes will be made to the infrastructure.

  4. Applying the changesterraform apply creates or modifies resources according to the configuration.

  5. Checking the state — Terraform updates the state file reflecting the current infrastructure.

Example of adding a new AWS EC2 resource:

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

After adding this block, run terraform init, then terraform plan, and terraform apply.