Expression evaluating to 'true' if a resource has changed during that run

Suppose I have some aws_s3_object resource, and during the run its content may or may not change.

Suppose I then have some dependent aws_ecs_service resource, whose force_new_deployment attribute should be true if the S3 object content changed.

Can I detect this during the run somehow? Perhaps some kind of resource_changed() function? I could find nothing relevant

Hi @occasionallydavid,

Terraform is a desired state system rather than an imperative system, so there is no way to directly program with actions. Instead, Terraform decides the actions based on how providers respond to the changes you make to the desired state.

I’m not sure about your exact problem here because I’m not super familiar with ECS, but I would expect to solve problems of that kind by including something in the ECS configuration which refers to the S3 object, which means that the ECS configuration would naturally change each time the S3 object does. If you can say a little more about the underlying problem here, and show some code examples, I can hopefully be more specific.

Hi Martin! Thanks for this, you hit the nail on the head. So obvious… :slight_smile:

I simply need to include a hash of the S3 object as an (unused) variable in the task definition, and all will happen automatically.

Thanks a ton!

Great! I’m glad to hear you got something working.

A variant I’ve seen of what you described is to use a versioned S3 bucket and then refer to specific versions of the object when using it elsewhere, which achieves essentially the same effect but allows for retaining old versions of the object in case you need to roll back, assuming your system is designed to support rolling back.

That’s just some different details of the same general idea though, and indeed using the checksum seems like a reasonable variant if you don’t need to preserve historical artifacts.