🤖 AI Generated: This entire Terraform module (code, documentation, examples, and tests) was generated by GitHub Copilot AI to demonstrate best practices.
A simple, well-structured Terraform module demonstrating best practices for module development. This module showcases input variable handling, data processing, local values, conditional resources, and comprehensive outputs.
- 📝 Input Validation: Variables with validation rules and descriptive error messages
- 🔄 Data Processing: Combines and transforms input variables using local values
- 🏷️ Tag Management: Merges user-provided tags with automatically generated ones
- 🎯 Conditional Resources: Demonstrates conditional resource creation
- 📤 Comprehensive Outputs: Exposes processed data and metadata
- 🔍 Example Usage: Includes multiple usage examples
module "simple_example" {
source = "path/to/simple-tf-module"
project_name = "my-project"
environment = "dev"
}module "advanced_example" {
source = "path/to/simple-tf-module"
project_name = "advanced-project"
environment = "production"
string_list = ["database", "cache", "queue", "storage"]
default_tags = {
Owner = "devops-team"
CostCenter = "engineering"
Compliance = "required"
}
enable_random_pet = true
pet_length = 3
pet_separator = "_"
}| Name | Version |
|---|---|
| terraform | >= 1.0 |
| random | ~> 3.1 |
| Name | Version |
|---|---|
| random | ~> 3.1 |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| project_name | Name of the project. Used for resource naming and tagging. | string |
"CASE NIGHTMARE GREEN" | no |
| environment | Environment name (e.g., dev, staging, prod). Used for resource naming and tagging. | string |
n/a | yes |
| string_list | List of strings to be processed and combined in outputs. | list(string) |
["item1", "item2", "item3"] |
no |
| default_tags | Default tags to apply to all resources. Will be merged with automatically generated tags. | map(string) |
{ "Terraform": "true", "Module": "simple-tf-module" } |
no |
| enable_random_pet | Whether to create a random pet resource. Demonstrates conditional resource creation. | bool |
true |
no |
| pet_length | Number of words in the random pet name when enabled. | number |
2 |
no |
| pet_separator | Separator to use between words in the random pet name. | string |
"-" |
no |
| prefix | Prefix for resource naming. Should be lowercase and hyphenated. | string |
n/a | yes |
| resource_group_name | The name of the resource group where resources will be created. | string |
"default-resource-group" |
no |
| Name | Description |
|---|---|
| full_name | Combined project name and environment |
| resource_prefix | Standardized prefix for resource naming (lowercase, hyphenated) |
| common_tags | Merged tags combining user inputs with automatically generated tags |
| processed_items | String list processed and combined into a comma-separated uppercase string |
| random_id | Generated random ID (hex format) |
| random_pet | Generated random pet name (only available when enabled) |
| pet_based_resource_name | Example resource name combining project prefix with random pet |
| pet_with_timestamp | Random pet name with timestamp for unique identification |
| pet_uppercase | Random pet name converted to uppercase for naming conventions |
| pet_metadata | Detailed information about the random pet resource |
| module_info | Information about this module instance |
| prefix | The prefix used for resource naming. |
| resource_group_name | The name of the resource group where resources will be created. |
| Name | Type |
|---|---|
| random_id.example | resource |
| random_pet.conditional | resource |
See the examples/ directory for comprehensive usage examples including:
- Basic usage with minimal configuration
- Advanced usage with custom tags and settings
- Minimal configuration with disabled features
- Variable Validation: All input variables include validation rules
- Descriptive Documentation: Comprehensive descriptions for all components
- Consistent Naming: Standardized resource naming conventions
- Tag Management: Automatic tag generation and merging
- Conditional Logic: Conditional resource creation based on input
- Local Values: Data processing and transformation using locals
- Version Constraints: Explicit Terraform and provider version requirements
- Output Organization: Well-structured outputs with clear descriptions
To test this module locally:
- Clone the repository
- Navigate to the examples directory:
cd examples - Run
terraform initto initialize the module - Run
terraform planto see the planned changes - Run
terraform applyto create the resources
Alternatively, you can reference the module from your own Terraform configuration by pointing to the root directory.
This module includes comprehensive test suites using Terraform's native testing framework:
# Run all tests
terraform test
# Run specific test file
terraform test -filter=tests/basic_module_test.tftest.hcl
# Run with verbose output
terraform test -verboseSee the tests/ directory for detailed test documentation and test cases covering input validation, output verification, and various configuration scenarios.
- Follow the existing code structure and naming conventions
- Add validation rules for new variables
- Update documentation for any changes
- Include examples for new features
This project is licensed under the terms specified in the LICENSE file.