Skip to content

Latest commit

 

History

History
55 lines (41 loc) · 1.99 KB

File metadata and controls

55 lines (41 loc) · 1.99 KB
page_title subcategory description
random_pet Resource - terraform-provider-random
The resource random_pet generates random pet names that are intended to be used as unique identifiers for other resources. This resource can be used in conjunction with resources that have the create_before_destroy lifecycle flag set, to avoid conflicts with unique names during the brief period where both the old and new resources exist concurrently.

random_pet (Resource)

The resource random_pet generates random pet names that are intended to be used as unique identifiers for other resources.

This resource can be used in conjunction with resources that have the create_before_destroy lifecycle flag set, to avoid conflicts with unique names during the brief period where both the old and new resources exist concurrently.

Example Usage

# The following example shows how to generate a unique pet name
# for an AWS EC2 instance that changes each time a new AMI id is
# selected.

resource "random_pet" "server" {
  keepers = {
    # Generate a new pet name each time we switch to a new AMI id
    ami_id = var.ami_id
  }
}

resource "aws_instance" "server" {
  tags = {
    Name = "web-server-${random_pet.server.id}"
  }

  # Read the AMI id "through" the random_pet resource to ensure that
  # both will change together.
  ami = random_pet.server.keepers.ami_id

  # ... (other aws_instance arguments) ...
}

Schema

Optional

  • keepers (Map of String) Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
  • length (Number) The length (in words) of the pet name. Defaults to 2
  • prefix (String) A string to prefix the name with.
  • separator (String) The character to separate words in the pet name. Defaults to "-"

Read-Only

  • id (String) The random pet name.