Closed mike-nagy closed 6 years ago
The resource for "ddcloud_server_anti_affinity" requires a rule for setting the dependency on the server objects being available before it can be referenced. Assuming the other portions work (e.g. spinning up a network domain, spinning up the VLAN and then building the servers) that's all you should need. Else, you will need to set the dependencies for the other items as well.
I'd recommend if you haven't already confirmed doing so ripping out each piece and ensuring things build out in order which should help you troubleshoot this all.
Hi - the trick is to use the *
character like so:
Essentially, putting .*.
in an expression evaluates as an array of values (which you then use the element
function to extract the required value from). The trick is to use the count
property on the ddcloud_server_anti_affinity
resource so that there is one for each ddcloud_server
and then use count.index
to match them up.
(sorry for the delayed reply - I'm at a conference today)
I use this in a different resource but ultimately iterates through each element the resource is based on and as above put the count in the resource
host = "${element(ddcloud_server.mysql_server.*.primary_network_adapter.0.ipv6, count.index)}"
All good comments there. =) So, you should be all set between setting the * as well as ensuring the object exists first so it can be referenced in the code as it will need that all handy before it can iterate through. Else, it'll be a blank value and error out.
It will help if you have logs also so if you can send those out if you still have problems that will help pinpoint where it fails.
Terraform should do that for you normally, it infers dependencies from expression references.
You must have .id on the end by the way to reference the resource itself this works on one of my environments
resource "ddcloud_server_anti_affinity" "mysql_anti_affinity_rule" {
#count = 2
server1 = "${ ddcloud_server.mysql_server.0.id }"
server2 = "${ ddcloud_server.mysql_server.1.id }"
}
Thats the piece that was missing for me, adjusting my reference from
server1 = "${ ddcloud_server.mysql_server.0 }"
to
server1 = "${ ddcloud_server.mysql_server.0.id }"
and now it works for me thank you all for the feedback.
@mike-nagy - I'm going to close this issue now, since it sounds like it's been resolved, but feel free to reopen if you still have further questions.
I am having a bit of trouble with the ddcloud_anti_affinity resource type. Please forgive me if my questions seem elementary but I am hoping you could point me in the right direction with my script. I have read through the documentation on GitHub and it is not clear to me how to reference the servers to include in the rule. Below is a sample of my code, would you be able to provide some advice on what I may be doing wrong. In my test I am creating 2 servers and then want to put them into an anti-affinity rule. Thank you in advance for any information you can provide