Search code examples
amazon-web-servicesautomationchef-infraconsulorchestration

Cluster based config using Chef


I am working around setting up the consul 3 node cluster using cloudformation templates. I was able to automate the cluser installation using chef-solo but unable to find a way to update the server.json file with cluster ip's since these are dynamically created. Did anyone came across this scenario ?

After launching the 3 nodes across 3 AZ's, userdata will invoke chef-solo to install consul until here i was able to automate.

I am looking for ideas where i can automate the /etc/consul.d/server/json file:

"retry_join": [ "10.x.x.x:8301",  "10.x.x.x:8301", "10.x.x.x:8301" ]

Currently i have hardcoded the ip's but how to extract IP's dynamically when the aws stack is launched ?


Solution

  • The usual AWS-y way to do this would be to query the EC2 API from each node to find all the other nodes, usually using tags but other metadata could work too. You can use an IAM instance profile to securely grant the machine limited API access.