Basic Terrafom usage Flashcards
**
What is the purpose of the terraform init command?
The terraform init command initializes a Terraform project, downloading necessary plugins and setting up the backend for storing the state file.
What does the terraform plan command do?
The terraform plan command compares the desired state defined in the Terraform configuration with the current state of the infrastructure. It generates an execution plan, outlining the actions needed to achieve the desired state.
What is the purpose of the terraform apply command?
The terraform apply command executes the actions specified in the plan generated by Terraform. It makes the necessary changes to provision or modify the infrastructure based on the desired state.
How does the terraform destroy command work?
The terraform destroy command removes all the resources provisioned by Terraform, effectively tearing down the infrastructure defined in the Terraform configuration.
What is the state file in Terraform?
The state file is Terraform’s representation of the current state of the infrastructure. It contains information about every resource and data object managed by Terraform and serves as the source of truth for tracking the infrastructure state.
What are the differences between local and remote backend for the Terraform state file?
Local Backend: The state file is stored locally on the machine where Terraform is executed. It offers easy setup and accessibility but lacks collaboration features and can be prone to loss or corruption.
Remote Backend: The state file is stored remotely, enabling enhanced collaboration, version control, and auditability. It requires setup and configuration but offers benefits like better integrity and scalability.
What does the terraform plan command do?
The terraform plan command compares the desired state defined in the Terraform configuration with the current state of the infrastructure. It generates an execution plan, outlining the actions needed to reach the desired state.
What does the terraform apply command do?
The terraform apply command executes the actions specified in the plan generated by Terraform. It makes the necessary changes to provision or modify the infrastructure based on the desired state.
How does Terraform utilize AWS for remote backend?
Terraform can store the state file in an AWS S3 bucket and use DynamoDB for state locking. This provides durability, availability, and locking mechanisms for managing the Terraform state in a collaborative environment.
Why is the state file important in Terraform?
The state file is important because it serves as Terraform’s source of truth for tracking the current state of the infrastructure. It contains information about provisioned resources, dependencies, and attributes.
What are the benefits of using a remote backend for the Terraform state file?
Enhanced collaboration: A remote backend allows multiple team members to access and manage the state file concurrently.
Version control: The state file can be versioned and stored in a version control system for tracking changes over time.
Improved security: A remote backend can provide secure storage for sensitive information, such as database passwords.
Scalability: Remote backends typically offer scalable storage solutions suitable for larger infrastructure deployments.
Can multiple Terraform runs modify the state file simultaneously with a remote backend?
No, a remote backend typically uses a locking mechanism to ensure that only one Terraform run can modify the state file at a time. This prevents conflicts and data corruption in collaborative environments.
What is Terraform Cloud?
Terraform Cloud is a remote backend and collaboration platform provided by HashiCorp. It offers features such as remote state storage, version control integration, and workspace management for managing Terraform deployments.
How does Terraform integrate with AWS for the remote backend?
Terraform can use an S3 bucket in AWS for storing the state file. This provides durability and availability for the state file. Additionally, DynamoDB can be utilized for state locking to ensure exclusive access during Terraform runs.
What are some common challenges when managing the state file locally?
Lack of collaboration: It can be difficult for multiple team members to access and manage the state file simultaneously.
Risk of loss or corruption: If the local machine or storage becomes inaccessible or corrupted, the state file may be lost, leading to potential inconsistencies in infrastructure management.