Welcome to the Terraform Examples repository! This repository serves as a collection of Infrastructure as Code (IaC) templates, modules, and best practices using HashiCorp Terraform. It is designed to help developers and DevOps engineers quickly deploy and manage cloud infrastructure.
This repository contains a variety of Terraform configurations ranging from basic setups to more advanced architectures. Whether you are looking to provision a simple virtual machine, set up a managed Kubernetes cluster, or design a highly available multi-tier network, you'll find reference code here.
Goals:
- Provide ready-to-use infrastructure templates.
- Demonstrate Terraform best practices (state management, modules, variables).
- Serve as a learning resource for infrastructure automation.
-
Clone the repository:
git clone [https://github.com/sinfallas/terraform-examples.git](https://github.com/sinfallas/terraform-examples.git) cd terraform-examples -
Navigate to your desired example:
cd aws/ec2-instance -
Configure Variables: Most examples include a
variables.tffile. Create aterraform.tfvarsfile to pass your specific values (e.g., region, instance types):aws_region = "us-east-1" instance_type = "t3.micro"
Standard Terraform workflow applies to all examples:
- Initialize the working directory (downloads providers and modules):
terraform init
- Review the execution plan (shows what will be created/modified):
terraform plan
- Apply the configuration (provisions the infrastructure):
(Type
terraform apply
yeswhen prompted to confirm) - Destroy the infrastructure (cleans up resources to avoid unexpected charges):
terraform destroy
When using or adapting these examples for production, please consider the following:
- Remote State: Always configure a remote backend (like AWS S3 + DynamoDB, Azure Storage, or Terraform Cloud) to store your
.tfstatefiles securely. - Least Privilege: Ensure the credentials used to run Terraform only have the permissions necessary to create the required resources.
- Version Pinning: Pin your Terraform provider versions to avoid breaking changes in future updates.
Contributions, issues, and feature requests are welcome!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.