Menu

Terraform File Structures
πŸ–ΌοΈ

Terraform File Structures

DEV CommunityΒ·Brian MengoΒ·6 months ago
#CgvsufiZ
#beginners#devops#terraform#tutorial#files
Reading 0:00
15s threshold

Introduction

Today we focus on file structure and organising Terraform projects. Initially all resources were placed in a single main.tf file to simplify the learning process. What we are doing now is to improve the project structure by splitting resources and configurations into multiple files for better readability, collaboration and maintainablity.

The root directory of a Terraform project is called the root module.

Terraform File Loading

There is no strict mandatory naming convention for Terraform files.recommendations come from HashiCorp best practices but are flexible.

How Terraform loads files;

Terraform loads all .tf files in the current directory

Files are loaded in lexicographical order (alphabetical)

All .tf files are merged into a single configuration

Recommended File Structure and Best Practices

project-root/ β”œβ”€β”€ backend.tf # Backend configuration β”œβ”€β”€ provider.tf # Provider configurations β”œβ”€β”€ variables.tf # Input variable definitions β”œβ”€β”€ locals.tf # Local value definitions β”œβ”€β”€ main.tf…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.