-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run null_resource always or updates to triggers #8266
Comments
Hi @mlushpenko! If I'm understanding your question correctly (please excuse my unfamiliarity with Ansible) you're looking for a way to trigger the null-resource provisioner when any file changes in your I'm afraid I don't have a full answer to your question, since Terraform doesn't yet have a way to hash the contents of a directory, but we can hash the contents of individual files: triggers = {
instance_count = "${var.aws_instances_count}"
some_ansible_file = "${sha1(file("${path.module}/ansible/some-ansible-file"))}"
} If you are able to list out each of the files in your |
Hi @apparentlymart, thanks for the proposal. It definitely helps in my situation, but would be nice to see some better solution in the future, although I understand that tracking changes on local machine (like file or folders in this case) is not an intended functionality in terraform. |
One drawback to this proposal as it seems to me - the provisioner won't work if tracked file is changed during the |
One more use case for having |
Hi again @mlushpenko. I apologize that on my first read I didn't notice that you generated that Although your original question was about making However, getting back to your specific problem: since your inventory file is produced entirely from data that Terraform knows, you should be able to put similar data inside triggers = {
instance_count = "${var.aws_instances_count}"
inventory_groups = "${join(" ", aws_instance.web.*.tags.group)}"
inventory_ip_addresses = "${join(" ", aws_instance.web.*.private_ip)}"
} |
Hi @apparentlymart! thanks for sharing this - that's basically what I was looking for: to see that more people share the same pain and the work is going on in that direction. And just in case of misunderstanding - I wasn't blaming you in any way about the "wrong" proposal, just thinking out loud whether it solves the issue in the right way. Glad to see live community, I will try t share more thoughts on improving terraform. |
not sure if this will answer any ones q's but recently I had an issue where I wanted secrets.tf to be generated (git ignored of course) i.e database password etc. I came up with
May help someone else one day |
Another cool tip, if you want it to apply if a file was changed, for example: resource "null_resource" "foo" {
provisioner "local-exec" {
command = "do something with ${path.module}/files/foo.config"
}
triggers = {
md5 = "${filemd5("${path.module}/files/foo.config")}"
}
} |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
Affected Resource(s)
References
Issue #745
The issue for me is to rerun null_resources on changes. For instance, I have a step to add EC2 instance IPs to the group in inventory file:
So, whenever I change the number of instances, my inventory will be updated. Now I need to copy this new inventory to the ansible "master" host, so I use null_resource again:
but it doesn't appear during the plan phase. One solution I found is to monitor number of instances by adding trigger to null_resource:
But I also have ansible files themselves, that are not related to the infrastructure changes, I mean role definitions. Do you have an idea on how to track local files changes, how do I trigger null_resource if I updated my role or how do I make the resource run always?
Considering this case - do you think it would make sense to add something like "tainted: always" option to null_resources? I am new to Terraform, but I feel like the connection between Terraform and configuration management tooling is missing a bit.
Another option is maybe to update trigger functionality to track changes in folder or files, like via hash calculation or so.
The text was updated successfully, but these errors were encountered: