random_pet in Terraform: Error: Cycle:

by Rick McClatchie   Last Updated August 14, 2019 10:01 AM - source

I am trying to generate random hostnames for a couple of servers. However when running terraform apply I get an error message "Error: Cycle: random_pet.swm01_managers, hcloud_server.swm01_managers"

This is what I am trying to do:

variable "swm01_managers_count" {
  default = 5
}

# ─── CREATE RANDOM SERVER HOSTNAMES ─────────────────────────────────────────────

resource "random_pet" "swm01_managers" {
  count = "${var.swm01_managers_count}"
  keepers = {
    id = "${hcloud_server.swm01_managers[count.index].id}"
  }
}

# ─── CREATE DOCKER SWARM MANAGER NODES ──────────────────────────────────────────

resource "hcloud_server" "swm01_managers" {
  count = "${var.swm01_managers_count}"

  name = "${random_pet.swm01_managers[count.index]}"
  image = "ubuntu-18.04"
  server_type = "cx11"
  ssh_keys = "${var.ssh_keys}"
  labels = {
    "env" = "prd"
    "docker_swarm_role" = "manager"
  }

}

Ans here's the error I get:

terraform apply --var-file=prd/prd.tfvars

Error: Cycle: random_pet.swm01_managers, hcloud_server.swm01_managers


Related Questions


Simplify Terraform Configuration

Updated August 14, 2019 08:01 AM

how to install terraform on linux

Updated July 04, 2018 18:01 PM

Install issue with Terraform on centos 7

Updated August 29, 2019 20:01 PM


Terraform AWS Security Group Ingress Rules

Updated October 12, 2018 16:01 PM