I’m newbies with terraform. I have specific use-case that i want to have resource that always runs last. For example slack notification. No matter how many resources can be before - it always must runs last.
How can i do that? I saw docs about depends_on, but it requires to specify resources by hand.
Terraform will try to do maximum parallelization, honoring the dependencies.
Scheduling “last” is a construct I have seen in SALT (a configuration management system).
if you must do it this way, can you not separate the resource creation from two separate directories?
I can’t separate, and yes, i saw this in salt to. It useful to notify via email,slack etc only if all steps are successful.
Hi @vtolstov,
This use-case of notification about the result is commonly implemented by wrapping Terraform in another program that captures its output and notifies the system in question, rather than within Terraform itself. When using Terraform in a collaborative environment it’s best to run it in a systematic way via some sort of automation, such as a CI system, in which case that automation wrapper can often handle the notification concerns too.
The guide Running Terraform in Automation has some guidance on how to wrap Terraform in some different variants of automation.
If you use Terraform Cloud then there is a Notifications feature built in. Terraform Cloud is, at its core, a pre-made automation wrapper around Terraform that already follows the guidance of the guide I linked above.
I don’t think that wrapping terraform via some script is right way. Notification is used only as example to last action. For example i want to send email only when full set of resources are created, or create another resource only after all other resources are created.