-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmain.tf
38 lines (30 loc) · 1.09 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
resource "random_id" "default" {
byte_length = 8
}
data "archive_file" "default" {
type = "zip"
source_dir = dirname(var.playbook)
output_path = "${path.module}/${random_id.default.hex}.zip"
}
resource "null_resource" "provisioner" {
count = signum(length(var.playbook)) == 1 ? 1 : 0
depends_on = [data.archive_file.default]
triggers = {
signature = data.archive_file.default.output_md5
command = "ansible-playbook ${var.dry_run ? "--check --diff" : ""} ${join(" ", compact(var.arguments))} ${length(compact(var.envs)) > 0 ? "-e" : ""} ${join(" -e ", compact(var.envs))} ${var.playbook}"
}
provisioner "local-exec" {
command = "ansible-playbook ${var.dry_run ? "--check --diff" : ""} ${join(" ", compact(var.arguments))} ${length(compact(var.envs)) > 0 ? "-e" : ""} ${join(" -e ", compact(var.envs))} ${var.playbook}"
}
lifecycle {
create_before_destroy = true
}
}
resource "null_resource" "cleanup" {
triggers = {
default = random_id.default.hex
}
provisioner "local-exec" {
command = "rm -f ${data.archive_file.default.output_path}"
}
}