Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Background

  • “The idea behind infrastructure as code (IAC) is that we write and execute code to define, deploy, and update our infrastructure. This represents an important shift in mindset where we treat all aspects of operations as software—even those aspects that represent hardware (e.g., setting up physical servers). In fact, a key insight of DevOps is that we can manage almost everything in code, including servers, databases, networks, log files, application configuration, documentation, automated tests, deployment processes, and so on.”

Project Structure and Organization

Possible Sub-pages/topics:

...

Infrastructure as Code (IaC) is the practice of configuring, provisioning, and managing infrastructure resources using code. It is an integral component of DevOps methodology, facilitating the seamless orchestration of applications and their underlying infrastructure such as servers, virtual machines, databases, and networks.

Project Structure and Organization

When handling projects, it's important to establish a well-organized directory structure to effectively manage your project and potential complexities. It's recommended to maintain distinct directories for various purposes and ensure a uniform format, style, and code structure.

Directory Structure

The recommended directory structure for any IaC project includes separating code, configuration, and documentation into organized folders. By following an organized directory structure, you make it easier for team members to locate and manage specific elements of your IaC project, maintain consistency, and collaborate effectively. It also facilitates version control and ensures that your project remains clear, maintainable, and scalable.

Info

Note: An IaC project typically undergoes multiple iterations to align with a company's specific project requirements, and its initial definition may not be entirely accurate.

  • Root Directory: The root directory of your IaC project typically contains high-level configuration files and important project-wide documentation. It may include files like "main.tf" (for Terraform) or "site.yml" (for Ansible) as the entry point for your IaC code.

  • Code Directory: This is where you store the actual IaC code. You should create subdirectories for different components or environments.

For example, you may have subdirectories like "networking," "servers," or "dev," "staging," and "production" if you're managing different environments.

  • Configuration Directory: This directory is meant for configuration files that are separate from the IaC code. These can include environment-specific configurations, application settings, or any other data that needs to be kept separate from the code logic.

Store configuration files that are separate from your IaC code in this directory.

  • Documentation Directory: It's a good practice to have a dedicated folder for documentation. This directory should contain files explaining the project's purpose, architecture, and usage, along with any user or developer guides.

  • Modules/Scripts Directory: If your IaC project is sufficiently complex, you may want to have a directory specifically for reusable modules, scripts, or functions. These can be shared and included in your code as needed.

  • Variables Directory: Store variable definitions in a dedicated directory. This can help keep variables separate from the code logic and make it easier to manage and change configurations.

  • Tests Directory: If your IaC project includes automated tests (highly recommended), place your test files or scripts in this directory. This helps ensure code reliability.

  • Infrastructure State Directory: Some IaC tools maintain state files that track the current state of deployed resources. Keep these files in a separate directory to prevent accidental modifications.

  • Secrets Directory (Optional): For security and separation of concerns, you may consider having a separate directory for managing secrets and sensitive data. Ensure strict access controls on this folder.

  • Logs and Reports Directory (Optional): If your IaC project generates logs or reports, you can have a directory for storing these files.

  • Bin or Scripts Directory (Optional): If you have utility scripts or binaries that assist in the IaC process, place them in this directory.

Naming Conventions

Repository Layout

...

Infrastructure Provisioning

...