Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ankitnewjobs/Terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Complete Hands-On Guides

Terraform Complete Hands-On Guides.

My Terraform Associate Certificate


Terraform

Terraform

Introduction

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.


Guide to a Well-Structured Terraform Project

  • Why care about Terraform project structure? Simple—it keeps things organized so you can scale up, work well with your team, and keep everything secure. No fuss, just a setup that works.

This setup follows a layered structure, separating resources by environment (development, staging, production, etc.) and using centralized modules for reusable components.

Modules are kept in a central repository, allowing environments to source specific versions for controlled updates and consistent configurations.

Environment Directory Structure:

Enviornment Directory Structure

Main.tf

Defines core resources for the environment by referencing modules from the central repository. Each module is tagged to ensure a specific version is used.

Example:

image

variables. tf

Declares input variables, making the configuration adaptable. For example, instance_type might vary between environments (e.g., t2.micro in dev, t3.large in prod).

Example:

image

provider. tf

Configures the cloud provider and backend for remote state storage, which tracks deployed resources. This setup is crucial for collaborative workflows.

Example:

image

outputs. tf

Defines output values, making it easy to retrieve information, like IP addresses or resource IDs, after deployment.

Example:

image

dev. tfvars (Environment-Specific Variables)

Contains values for variables declared in variables. tf, tailored to this environment. Each environment (dev, staging, prod) will have its own .tfvars file.

Example:

image

Centralized Modules Repository Breakdown

Modules are organized into folders by type (e.g., network, compute) within a separate repository. This structure allows consistent usage across environments by sourcing each module from a specific version tag in the central repository.

Modules Directory Structure:

Module Directory Structure


Getting Started & Documentation

Documentation is available on the Terraform website:

Introduction Documentation

If you're new to Terraform and want to get started creating infrastructure, please check out our Getting Started guides on HashiCorp's learning platform. There are also additional guides to continue your learning.

Show off your Terraform knowledge by passing a certification exam. Visit the certification page for information about exams and find study materials on HashiCorp's learning platform.


Points to consider while using modules:

  1. Use versioned module tags.

  2. Centralize module source in a remote repository.

  3. Refactor modules for reusability as the project scales.

  4. Avoid hardcoding values; use variables for flexibility.

  5. Keep module logic focused on a single responsibility.

  6. Define clear input and output variables for each module.

  7. Document module usage and parameters in a README.

  8. Test modules independently before applying them in environments.


Hit the Star! ⭐

If you're planning on using this Terraform repository for learning, please consider giving it a star⭐
Thank you!


For Doubts and Queries

Feel free to connect with me on LinkedIn through this profile: https://www.linkedin.com/in/ankit-ranjan05/


Original Repository: https://github.com/stacksimplify/hashicorp-certified-terraform-associate-on-azure


Project Maintainers & Contributors

1

Ankit Ranjan