* Cycle: clc_server.node[1], clc_server.node[0]

Hi Team,
When I am executing my terraform i am getting below error.
Kindly he me.

I am want to create multiple servers using below instructions.But i am getting below error.

Error: clc_server.node: 1 error(s) occurred:

  • Cycle: clc_server.node[1], clc_server.node[0]
provider "clc" {
  username = "${var.user_name}"
  password = "${var.password}"
  account  = "${var.account}"  # optional
}

resource "clc_server" "node" {
  name_template    = "${var.name_template}"
  source_server_id = "${var.source_server_id}"
  group_id         = "${var.group_id}"
  cpu              = "${var.cpu}"
  memory_mb        = "${var.memory}"
  password         = "${var.node_password}"
  count		   = 2

resource "null_resource" "configure-ips" {
  count = 2
provisioner "file" {
    source = "/tmp/apache.sh"
    destination = "/usr/local/apache.sh"
}
provisioner "remote-exec" {
    inline = [
       " sh /usr/local/apache.sh"
    ]
}

 connection {
     	host = "${element(clc_server.node.*.private_ip_address, count.index)}"
	user     = "root"
      	password = "${clc_server.node.password}"
}
}
}

resource "null_resource" "examplerr6" {
  provisioner "local-exec" {
  command = "echo  ${clc_server.node.id} ansible_host=${clc_server.node.private_ip_address} > private_ips.txt"
 }
}

Hi @sharathmankala!

Could you please edit your post and put “code block fences” ``` (three backticks) before and after each of your code examples, so that the forum will render them in a readable way? Currently the forum is misunderstanding parts of your example as TeX math syntax, which makes it hard to understand what your source code really looks like.

2 Likes

modified.
Kindly advise me what is the exact issue?

just a thought … is the self.ATTRIBUTE syntax still there in v 0.12 and if it might help here.

ref: https://www.terraform.io/docs/configuration-0-11/interpolation.html

Hi @shantanugadgil @apparentlymart
I have followed documentation already.
But i am unable to found the issue.
if i have do for one server(count = 1) working as expected.
When i have changing count value i am getting same error.
Kindly suggest me what exact issue.

Error: clc_server.node: 1 error(s) occurred:

  • Cycle: clc_server.node[1], clc_server.node[0]
provider "clc" {
  username = "${var.user_name}"
  password = "${var.password}"
  account  = "${var.account}"  # optional
}

resource "clc_server" "node" {
  name_template    = "${var.name_template}"
  source_server_id = "${var.source_server_id}"
  group_id         = "${var.group_id}"
  cpu              = "${var.cpu}"
  memory_mb        = "${var.memory}"
  password         = "${var.node_password}"
  count		   = 2

resource "null_resource" "configure-ips" {
  count = 2
provisioner "file" {
    source = "/tmp/apache.sh"
    destination = "/usr/local/apache.sh"
}
provisioner "remote-exec" {
    inline = [
       " sh /usr/local/apache.sh"
    ]
}

 connection {
     	host = "${element(clc_server.node.*.private_ip_address, count.index)}"
	user     = "root"
      	password = "${clc_server.node.password}"
}
}
}

resource "null_resource" "examplerr6" {
  provisioner "local-exec" {
  command = "echo  ${clc_server.node.id} ansible_host=${clc_server.node.private_ip_address} > private_ips.txt"
 }
}

Hi @sharathmankala,

There seems to be a syntax error in the configuration block you are sharing: the resource "clc_server" "node" block has no closing brace. Is there more to this configuration than what you are sharing here?

The usual cause of this error is referring to a resource from inside its own block, so it’s important to know what is nested inside what to understand what’s happening. The indentation of your configuration is inconsistent, so it’s hard to read and understand exactly how it’s nested. If you run terraform fmt then it should be able to fix that for you so you (and we) can more clearly see how the blocks are nested.

1 Like

Hi @apparentlymart ,
Thanks Martin.
It is syntax issue.
Now its working As expected.
Thanks a lot.
I am sharing updated terraform.

provider "clc" {
  username = "${var.user_name}"
  password = "${var.password}"
  account  = "${var.account}"   # optional
}

resource "clc_server" "node" {
  name_template    = "${var.name_template}"
  source_server_id = "${var.source_server_id}"
  group_id         = "${var.group_id}"
  cpu              = "${var.cpu}"
  memory_mb        = "${var.memory}"
  password         = "${var.node_password}"
  count            = "${var.count}"
}

resource "null_resource" "configure-ips" {
  count = "${var.count}"


  connection {
    type        = "ssh"
    host        = "${element(clc_server.node.*.private_ip_address, count.index)}"
    user        = "root"
    private_key = "${file("~/.ssh/id_rsa")}"
  }

  provisioner "file" {
    source      = "/tmp/apache.sh"
    destination = "/usr/local/apache.sh"
  }

  provisioner "remote-exec" {
    inline = [
      " sh /usr/local/apache.sh",
    ]
  }
}
  resource "null_resource" "examplerr6" {
    provisioner "local-exec" {
      command = "echo  ${element(clc_server.node.*.id, count.index)} ansible_host=${element(clc_server.node.*.private_ip_address, count.index)} >> private_ips.txt"
    }
  }