This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
49 lines (38 loc) · 1.54 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
39
40
41
42
43
44
45
46
47
48
locals {
lbrace = "{"
}
data "null_data_source" "elements" {
count = length(var.terraform_output)
inputs = {
key = var.terraform_output[count.index]["key"]
string = "\"${var.terraform_output[count.index]["value"]}\""
array = var.terraform_output[count.index]["value"]
map = replace(var.terraform_output[count.index]["value"], ":", "=")
is_array = substr(var.terraform_output[count.index]["value"], 0, 1) == "["
is_map = substr(var.terraform_output[count.index]["value"], 0, 1) == local.lbrace
is_string = substr(var.terraform_output[count.index]["value"], 0, 1) != "[" && substr(var.terraform_output[count.index]["value"], 0, 1) != local.lbrace
}
}
data "template_file" "outputs" {
count = length(var.terraform_output)
template = <<TEMPLATE
output "$${key}" {
value = $${value}
}
TEMPLATE
vars = {
key = data.null_data_source.elements[count.index].outputs["key"]
value = data.null_data_source.elements[count.index].outputs["is_string"] ? data.null_data_source.elements[count.index].outputs["string"] : (data.null_data_source.elements[count.index].outputs["is_array"] ? data.null_data_source.elements[count.index].outputs["array"] : data.null_data_source.elements[count.index].outputs["map"])
}
}
locals {
rendered = join("\n", data.template_file.outputs.*.rendered)
}
resource "aws_s3_bucket_object" "output" {
bucket = var.bucket
key = var.key
content = local.rendered
content_language = "en-US"
etag = md5(local.rendered)
tags = var.tags
}