Random_shuffle help

Trying to pretty much replicate the TF example for random_shuffle to randomly return value from a list. Usecase is the same where I want to have a difference gcp zone returned for a compute instance.

Error from TF Plan:

Error: Unsupported attribute
on main.tf line 23, in resource "google_compute_instance" "vm_instance":
23:   zone          = "${random_shuffle.gcp-zones.result}"
| random_shuffle.gcp-zones is tuple with 3 elements

This value does not have any attributes.

Seems like it is not processing the result_count option in the random_shuffle resource:

        resource "random_shuffle" "gcp-zones" {
          input         = ["northamerica-northeast1-a", "northamerica-northeast1-b", "northamerica-northeast1-c"]
          result_count  = 1


Can you share what version of terraform and terraform-provider-random you are using? It is also useful to put the result in an output block so you can exactly what terraform sees:

resource "random_shuffle" "gcp-zones" {
  input        = ["northamerica-northeast1-a", "northamerica-northeast1-b", "northamerica-northeast1-c"]
  result_count = 1

// I used result [0] because the result was a list with a single element
output "result" {
  value = random_shuffle.gcp-zones.result[0]



result = northamerica-northeast1-a
1 Like