Sunday, May 16, 2021

Terraform lifecycle

 If we are using terraform, terraform state file is the heart of all the infrastructure that we spin up using terraform templates. 

There are several ways to deploy the infrastructure using terraform:

1. Using CLI (setup terraform and then run terraform commands)

2. Automated Build (terraform scripts integrated as part of your jenkins pipeline)

No matter of the way we chose, we must make sure that we are using the same terraform state file, so that we are having a sync and proper checklists of the resources that we used. 


I would like to share the terraform commands that we do on a daily basis:

terraform init = the basic/starting command which initializes the terraform (make sure the proper provider is provided. In my case, I use AWS). 

terraform workspace select <workspace name> (creates a new workspace, useful in scenarios where we have different terraform modules - database, servers, logs, storage)

terraform state list = shows the list of terraform resources that are created (uses the state file)

terraform plan = creates a terraform plan and will give us a list of changes without actually deploying them (make sure you specify -out tfplan.plan if we need to store the output of this plan command)

terraform apply = to actually deploy based on the terraform plan

terraform destroy = to destroy the resources which we created




No comments:

Post a Comment