-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.tf
36 lines (28 loc) · 1.1 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
locals {
node_resolve_script = <<-EOF
console.log(
JSON.stringify({
path: require.resolve("${var.module_name}/${var.path_to_file}")
})
);
EOF
cdn_module_version = length(var.module_version) > 0 ? "@${var.module_version}" : ""
cdn_module_url = "${var.cdn_provider_url}${var.module_name}${local.cdn_module_version}/${var.path_to_file}"
cdn_download_dest = "${path.module}/download/${var.module_name}/${var.path_to_file}"
file_path = var.use_local ? data.external.this[0].result.path : data.external.download[0].result.path
}
#######################################
# Find file locally via Node.js resolve
#######################################
data "external" "this" {
count = var.use_local ? 1 : 0
program = ["node", "-e", local.node_resolve_script]
working_dir = var.local_cwd == null ? path.cwd : var.local_cwd
}
############################
# Download the file from CDN
############################
data "external" "download" {
count = var.use_local ? 0 : 1
program = ["bash", "${path.module}/download.sh", local.cdn_module_url, local.cdn_download_dest]
}