QA Module Structure
When QA validates a module, it is crucial to follow a consistent structure to ensure that the module adheres to best practices and is easy to understand. Below is the structure to be followed when creating a Terraform AWS module.
Directory.github/
DirectoryISSUE_TEMPLATE/
- 1_bug_report.yml
- 2_feature_request.yml
- 3_docs_request.yml
- config.yml
Directoryworkflows/
- documentation.yml
- pr-title.yml
- pre-commit.yml
- release.yml
- dependabot.yml
- PULL_REQUEST_TEMPLATE.md
- stale.yml
Directory.vscode/
- extensions.json
- settings.json
DirectoryLOGS/
- .gitkeep
Directorysrc/
Directorymodule-example-1/
Directoryexamples/
Directorycomplete/
- main.tf
- outputs.tf
- README.md
- provider.tf
- versions.tf
- .gitkeep
Directorymodel/
- main.tf
- outputs.tf
- README.md
- variables.tf
- versions.tf
- main.tf
- outputs.tf
- README.md
- variables.tf
- versions.tf
- .gitkeep
- .editorconfig
- .gitignore
- .pre-commit-config.yaml
- .releaserc.json
- README.md
Structure Explanation
-
.github/: Contains GitHub Actions workflows and issue templates. The
documentation.ymlworkflow generates documentation for the module. Ensure that all directories are included in the documentation generation by checking theworking-dirdirectory..github/workflows/documentation.yml 15 collapsed lines1name: Generate Terraform Docs2on:3- pull_request45jobs:6docs:7runs-on: ubuntu-latest8steps:9- uses: actions/checkout@v410with:11ref: ${{ github.event.pull_request.head.ref }}1213- name: Render Terraform docs in README.md and push changes back to PR branch14uses: terraform-docs/gh-actions@v1.1.015with:16working-dir: ./src/module-example-1,./src/module-example-1/model,./src/module-example-1/wrapper,./src/module-example-1/examples/complete3 collapsed lines17output-file: README.md18output-method: inject19git-push: "true" -
src/: Contains the module code. Each module should have its own directory named after the module. The module directory should contain the following files:
- /module-example-1/: Rename this directory to the module name.
- examples/complete/: Contains an example of how to use the module, including all resources that the module creates.
-
main.tf: Main Terraform configuration file with the module’s resources.
-
outputs.tf: Outputs of the module.
-
README.md: Documentation for the example.
./src/module-example-1/examples/complete/README.md 1# Terraform AWS Modules Example/Complete Blueprint23## Description45<!-- INFO: A brief description of the example -->67## How to Use89<!-- INFO: Steps to run the complete example successfully -->1011## Notes1213> [!NOTE]14> Important information for users.1516> [!TIP]17> Tips for successful usage.1819> [!IMPORTANT]20> Crucial information for users.2122> [!WARNING]23> Critical information for immediate attention.2425> [!CAUTION]26> Potential negative consequences.2728<!-- BEGIN_TF_DOCS -->26 collapsed lines29## Requirements3031| Name | Version |32|------|---------|33| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.0 |34| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.24.0 |3536## Providers3738No providers.3940## Modules4142No modules.4344## Resources4546No resources.4748## Inputs4950No inputs.5152## Outputs5354No outputs.55<!-- END_TF_DOCS --> -
provider.tf: Provider configuration.
./src/module-example-1/examples/complete/provider.tf 1provider "aws" {2region = "eu-west-1"3shared_credentials_files = [pathexpand("~/.aws/credentials")]4profile = "TF_TEST_PROFILE"5} -
versions.tf: Terraform provider versions.
./src/module-example-1/examples/complete/versions.tf 1terraform {2required_providers {3aws = {4source = "hashicorp/aws"5version = ">= 5.24.0"6}7}8}
-
- model/: Contains the module code.
- main.tf: Main Terraform configuration file with the module’s resources.
- outputs.tf: Outputs of the module.
- README.md: Documentation for the module, generated by the
documentation.ymlworkflow. - variables.tf: Input variables for the module.
- versions.tf: Terraform provider versions.
- main.tf: Will be deleted and replaced with specific resources like
codeartifact_repository.tf,codeartifact_domain.tf, etc. - outputs.tf: Contains all outputs of the module.
- variables.tf: Contains all input variables of the module.
- README.md: Documentation for the module, generated by the
documentation.ymlworkflow.
- examples/complete/: Contains an example of how to use the module, including all resources that the module creates.
- /module-example-1/: Rename this directory to the module name.
-
README.md: Main documentation for the module. This file should contain the following sections:
README.md 1# Terraform AWS Modules Blueprint23## Description45<!-- INFO: A brief description of the blueprint -->67This repository serves as a blueprint for creating new Terraform modules tailored for AWS. It is designed to provide a structured and consistent foundation for developing modular infrastructure stacks.89## Modules List1011<!-- INFO: A list of available modules -->1213- **`module-example-1`:**14- [Module Example 1](src/module-example-1/)15- [Module Example 1 Model](src/module-example-1/model)16- [Module Example 1 Wrapper](src/module-example-1/wrapper)1718## Examples1920### Examples List2122<!-- INFO: A list of available examples -->2324- **`module-example-1`:**25- [Module Example 1 Complete](src/module-example-1/examples/complete/)2627## Documentation2829<!-- INFO: Additional information about the blueprint -->3031Explore detailed documentation to enhance your understanding:3233- [Documentation](https://www.tf-docs.cirrusgo.com/docs/)3435## Terraform Registry Version3637<!-- INFO: The Terraform Registry version of the blueprint -->3839- [Terraform Registry](https://registry.terraform.io/providers/hashicorp/aws/5.49.0/docs)- Title: Rename the title
Terraform AWS Modules Blueprintto the module name. - Description: Add a brief description of the module.
- Modules List: List all available modules in the repository.
- Examples List: List all available examples in the repository.
- Documentation: Add any additional information about the module.
- Terraform Registry Version: Add the Terraform Registry version of the module.
- Title: Rename the title
Conclusion
By following this structure, you can ensure that the module is consistent, easy to understand, and follows best practices. This will help QA validate the module more efficiently and effectively.