Repository for learning Terraform
Steps to get started:
-
Run
terraform init
- This command initializes terraform in the current directory and downloads the providers needed in the terraform code. -
Run
terraform apply
- This will read the terraform code file and show the changes that will be made once the change is applied. In our case, this will be the S3 bucket creation details. This command will automatically generate the plan and make changes. -
Run
terraform plan
- This command will compare the current state of the system and the changes that will happen if you apply the code change. This is great for verifying the changes that will be applied due to current changes in code. -
Run
terraform plan -out=sample.plan
- This command generates a plan file which can be used to apply. This will also make sure that you only apply the changes that were part of a, This avoids mistakes due to unintended changes in the script after generating the plan.
- The plan file (sample.plan) can only be viewed by runningterraform show sample.plan
since its a binary file. -
Run
terraform apply "sample.plan"
- This command applies changes from a specific plan. -
Run
terraform plan -destroy -out destroy.plan
- Generate the planterraform apply destroy.plan
- Execute the planGood to clean up resources after ending a development session.
-
State define the current state of the resource or local representation of the state file.
-
The state file can be inspected for the most recent execution by running
vi terraform.tfstate
-
Only running
terraform plan
, terraform refreshes the local state file based on the remote changes. -
Remote storage for states is used for colloborative development.
-
Useful commands:
terraform state list
- Display the resources that have been provisioned.terraform state show <resource name>
- Provides a detailed view about a provisioned resource.terraform show
- Displays a full list of resources in details.