Hi Guys,
I am trying to create a situation that when some EC2 instances in AWS are rebuilt using Terraform, a Null resource is ran which packages up some cookbooks and puts them into S3. I am doing this because the Null resource doesn’t always get ran when the infrastructure is rebuilt, so we get old cookbooks being used.
I have the following resource:
resource "null_resource" "cookbooks" {
triggers {
machine1_instance_ids = "${join(",", aws_instance.machine1.*.id)}"
machine2_instance_ids = "${join(",", aws_instance.machine2.*.id)}"
}
provisioner "local-exec" {
command = "berks package cookbooks.tar.gz"
}
}
resource "aws_s3_bucket_object" "cookbooks" {
depends_on = ["null_resource.cookbooks"]
bucket = "${aws_s3_bucket.cookbooks.id}"
key = "cookbooks.tar.gz"
source = "cookbooks.tar.gz"
}
resource "aws_instance" "machine1" {
[…]
depends_on = ["aws_s3_bucket_object.cookbooks"]
}
When I run this I get a cycle error between the 3 resources, if I remove the trigger from the Null resource everything goes through ok, but the cookbooks aren’t re-packaged if they get updated which is what I want.
Any suggestions, or am I doing this wrong?
Best,
Andrew.