This repository serves as a template for creating Terraform modules. It provides a structured approach to organizing and maintaining Terraform code, along with examples and best practices.
Before you begin, ensure you have met the following requirements:
- install terraform
- install pre-commit
- configure pre-commit:
pre-commit install
- install required tools
To use this template, clone the repository and customize it according to your module's requirements. Below is a quick start guide:
-
Clone the repository:
git clone https://github.com/your-username/terraform-module-template.git cd terraform-module-template
-
Customize the module:
- Update
main.tf
,variables.tf
,outputs.tf
, andversions.tf
files as needed. - Add your own resources and logic.
- Update
-
Run Terraform commands:
terraform init terraform plan terraform apply
This repository includes example configurations to help you understand how to use the module:
-
Complete Example: Located in
examples/complete
- Demonstrates a full-featured usage of the module.
cd examples/complete terraform init terraform apply
-
Minimal Example: Located in
examples/minimal
- Shows a minimal configuration for using the module.
cd examples/minimal terraform init terraform apply
The repository is organized as follows:
.
├── .editorconfig
├── examples
│ ├── complete
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── provider.tf
│ │ ├── README.md
│ │ ├── variables.tf
│ │ └── versions.tf
│ └── minimal
│ ├── main.tf
│ ├── outputs.tf
│ ├── provider.tf
│ ├── README.md
│ ├── variables.tf
│ └── versions.tf
├── .github
│ └── workflows
│ ├── documentation.yaml
│ ├── pre-commit.yaml
│ └── pr-title.yaml
├── .gitignore
├── main.tf
├── modules
│ └── sample-resource
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── version.tf
├── outputs.tf
├── .pre-commit-config.yaml
├── README.md
├── .terraform-docs.yml
├── tests
│ ├── examples_minimal.tftest.hcl
│ └── unit_tests.tftest.hcl
├── .tflint.hcl
├── variables.tf
└── versions.tf
Reference Getoutline Document for Conventions to follow in your module
Name | Version |
---|---|
terraform | >= 1.8.4 |
aws | >= 5.51.0 |
Name | Version |
---|---|
aws | >= 5.51.0 |
No modules.
Name | Type |
---|---|
aws_iam_openid_connect_provider.github_oidc | resource |
aws_iam_role.github_action | resource |
aws_iam_role_policy_attachment.admin | resource |
aws_iam_policy_document.assume_role | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
aws_account_id | The AWS Account ID | string |
n/a | yes |
github_username | The name of the GitHub user or organization that owns the repository(ies) the role will use | string |
n/a | yes |
repository_names | List of names of the GitHub repository that will be allowed to assume the role | list(string) |
n/a | yes |
role_name | The name of the IAM Role to be created | string |
"GithubActionsRole" |
no |
Name | Description |
---|---|
github_action_iam_role_arn | The ARN of the IAM role |