0

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
New contributor
Rick McClatchie is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Rick McClatchie is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.