This is a template child module to create a random pet resource. It can be easily copied and updated for other use-cases.
The repository/directory name should follow this pattern:
[terraform-]<PROVIDER>-<NAME>
Here’s what this means:
- [If it's a separate repository] The repository should start with
terraform-
if your module should be published to and discovered on the Registry. Even if you don’t intend to publish the module, following this pattern is a good practice that helps differentiate your Terraform child modules from other code in your projects. - Include the provider name: Specify the primary provider your module is for, such as aws, google, datadog, etc.
- Use descriptive name: Follow the provider name with a clear and concise identifier that describes the module’s purpose.
- Use hyphens to separate words.
Also:
- Keep name short and focused: While it should be descriptive, avoid overly long names. The goal is to convey the module’s purpose concisely:
- Good:
terraform-aws-internal-lb
. - Not so good:
terraform-aws-internal-misc-module
. - Too long:
terraform-aws-internal-application-load-balancer-with-extra-rules
.
- Good:
- Module names should reflect their purpose rather than environment-specific details.
To use this module, reference it from your main configuration and provide the necessary input variables. For example:
module "sandbox_pet" {
source = "masterpointio/random/pet"
# We recommend to pin the specific version
# version = "X.X.X"
# Input variables
length = 2
prefix = "sandbox"
}
Once applied, the random resource will produce a random name such as sandbox-lively-parrot
(the exact name will vary). This name can be referenced via:
output "pet_name" {
value = module.sandbox_pet.random_pet_name
}
Name | Version |
---|---|
terraform | >= 1.0 |
random | >= 3.0 |
Name | Version |
---|---|
random | >= 3.0 |
No modules.
Name | Type |
---|---|
random_pet.template | resource |
Name | Description | Type | Default | Required |
---|---|---|---|---|
length | The length of the random name. | number |
2 |
no |
prefix | A string to prefix the name with. | string |
null |
no |
Name | Description |
---|---|
random_pet_name | The generated random pet name |