Triggers on Null resources

1,618 views
Skip to first unread message

Andrew Hodgson

unread,
Jul 22, 2016, 5:41:36 PM7/22/16
to terrafo...@googlegroups.com

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.

Asier Gomez

unread,
Mar 10, 2017, 6:56:14 AM3/10/17
to Terraform
Hello!

I use the next trigger and it works for me:

triggers = {
  filename = "test-${uuid()}"
}


The uuid() always you run terraform change so always will be throw.
Reply all
Reply to author
Forward
0 new messages