This repository contains examples of Terraform configurations for various deployments.
Below is a description of each file in the terraform projects:
-
main.tf: This file contains the main set of configuration for your Terraform project. In our case, it specifies the AWS provider and contains the configuration to create an EC2 instance. -
variables.tf: This file is used for the declaration of variables that are used in themain.tffile. It contains the declarations for AWS region, access key, and secret key variables. -
terraform.tfvars: This file is used to set the values for the variables declared invariables.tf. This file should not be committed to version control if it contains sensitive information like AWS access keys. -
data.tf: This file contains the configuration to retrieve the latest Amazon Linux AMI ID for the specified AWS region. -
outputs.tf: This file is used to define the output variables for the Terraform project. This is what will be printed when the deployment is complete. -
.terraform.lock.hcl: This file is used by Terraform to track the provider versions used in the project. This is important to ensure that the project can be used consistently across different environments.
To use this project, follow these steps:
-
Clone the repository to your local machine and
cdin the relevent directory. -
Update the
terraform.tfvarsfile with your AWS credentials and desired region. -
Open a terminal and navigate to the directory containing the Terraform files.
-
Run
terraform initto initialize your Terraform workspace. -
Run
terraform planto see the changes that will be made. -
Run
terraform applyto apply the changes. You will be prompted to confirm that you want to make the changes. -
⚠️ ⚠️ ⚠️ When you're done with the resources, runterraform destroyto clean up.⚠️ ⚠️ ⚠️
Note: Always double-check the changes during the plan step to ensure you are making the changes you intend, and always clean up your resources when you're done to avoid unnecessary AWS charges.