hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.32k stars 1.72k forks source link

Provide explanation/link on the use of "%{random_suffix}" in a resource name. #14236

Closed kurtkanaskie closed 1 year ago

kurtkanaskie commented 1 year ago

Community Note

Terraform Version

$ terraform -v
Terraform v1.3.7
on darwin_amd64
+ provider registry.terraform.io/hashicorp/google v4.60.0
+ provider registry.terraform.io/hashicorp/random v3.4.3

Your version of Terraform is out of date! The latest version
is 1.4.4. You can update by downloading from https://www.terraform.io/downloads.html

Affected Resource(s)

Terraform Configuration Files

name                  = "instance-name-%{random_suffix}"

Debug Output

Panic Output

Expected Behavior

Actual Behavior

Error

╷
│ Error: Invalid template control keyword
│ 
│   on main.tf line 98, in resource "google_compute_region_network_endpoint_group" "tf_psc_neg_us_east1":
│   98:   name                  = "psc-neg-us-east1-%{random_suffix}"
│ 
│ "random_suffix" is not a valid template control keyword.

Steps to Reproduce

  1. Create a resource using %{random_suffix}
    resource "google_compute_region_network_endpoint_group" "tf_psc_neg_us_east1" {
    name                  = "psc-neg-us-east1-%{random_suffix}"
  2. terraform apply

Important Factoids

References

rileykarson commented 1 year ago

Configurations are reused between tests and examples. These are artifacts from folks copying what should be test-only configuration into the source sample- it's invalid Terraform code, and tests substitute a randomized suffix in its place. Seems like there are 78 cases across 34 files.

@edwardmedia this wouldn't be a bad idea for you to clean up if you have the cycles!

edwardmedia commented 1 year ago

I do see this in 78 cases in 34 doc files. Let me clean them up @rileykarson

kurtkanaskie commented 1 year ago

What I've done to achieve the same is to use:

resource "random_id" "random_suffix" {
  byte_length = 4
}

resource "google_compute_region_network_endpoint_group" "tf_psc_neg_us_east1" {
  name                  = "tf-psc-neg-us-east1-${lower(random_id.random_suffix.hex)}"
...
}
output "apigee_neg_name" {
  value = google_compute_region_network_endpoint_group.tf_psc_neg_us_east1.name
}

Which results in an output: apigee_neg_name = "tf-psc-neg-us-east1-d6f6243e"

github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.