-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.tf
29 lines (25 loc) · 1.11 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
data "external" "curl" {
count = module.this.enabled ? 1 : 0
program = concat(["curl"], var.curl_arguments, ["--write-out", "{\"success\": \"true\", \"filename_effective\": \"%%{filename_effective}\"}", "-o", local.output_file, local.url])
depends_on = [data.external.git]
}
data "external" "git" {
count = module.this.enabled && var.git_ref == "" ? 1 : 0
program = ["git", "-C", var.module_path, "log", "-n", "1", "--pretty=format:{\"ref\": \"%H\"}"]
}
locals {
external_curl_filename_effective = join("", data.external.curl.*.result.filename_effective)
external_git_ref = join("", data.external.git.*.result.ref)
git_ref = var.git_ref == "" ? local.external_git_ref : var.git_ref
output_file = join("/", [var.module_path, var.filename])
url = join("", data.template_file.url.*.rendered)
}
data "template_file" "url" {
count = module.this.enabled ? 1 : 0
template = replace(var.url, "$$", "$")
vars = {
filename = var.filename
git_ref = local.git_ref
module_name = var.module_name
}
}