Repository navigation
Expand file tree
/
Copy pathartifacts.tf
More file actions
81 lines (77 loc) · 3.29 KB
/
Copy pathartifacts.tf
File metadata and controls
81 lines (77 loc) · 3.29 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
locals {
artifacts = var.artifact_manifest == null ? {} : jsondecode(file(var.artifact_manifest))
controls = toset(["index.sh", "installer/latest", "installer/installer_data.json"])
}
# Files are streamed by the provider's multipart uploader, including >5 GiB ZIPs.
# No binary contents go into state. Hashes detect changes and verify local inputs.
resource "aws_s3_object" "payload" {
for_each = { for key, artifact in local.artifacts : key => artifact if !contains(local.controls, key) }
bucket = aws_s3_bucket.artifacts.id
key = each.key
source = each.value.source
source_hash = each.value.sha256
content_type = each.value.content_type
cache_control = each.key == "os/boot.bin" ? "public, max-age=60" : "public, max-age=31536000, immutable"
metadata = { sha256 = each.value.sha256 }
depends_on = [aws_s3_bucket_versioning.artifacts, aws_s3_bucket_server_side_encryption_configuration.artifacts, terraform_data.activate_pro]
lifecycle {
# Keep historical versioned payloads; removing one from the manifest must
# never silently remove a release still referenced by an older installer.
prevent_destroy = true
precondition {
condition = filesha256(each.value.source) == each.value.sha256
error_message = "Artifact changed since manifest creation; regenerate and review the manifest."
}
}
}
resource "aws_s3_object" "installer_data" {
for_each = { for key, artifact in local.artifacts : key => artifact if key == "installer/installer_data.json" }
bucket = aws_s3_bucket.artifacts.id
key = each.key
source = each.value.source
source_hash = each.value.sha256
content_type = "application/json"
cache_control = "public, max-age=60"
metadata = { sha256 = each.value.sha256 }
depends_on = [aws_s3_object.payload]
lifecycle {
precondition {
condition = filesha256(each.value.source) == each.value.sha256
error_message = "Installer metadata changed since manifest creation."
}
}
}
resource "aws_s3_object" "latest" {
for_each = { for key, artifact in local.artifacts : key => artifact if key == "installer/latest" }
bucket = aws_s3_bucket.artifacts.id
key = each.key
source = each.value.source
source_hash = each.value.sha256
content_type = "text/plain; charset=utf-8"
cache_control = "public, max-age=60"
metadata = { sha256 = each.value.sha256 }
depends_on = [aws_s3_object.installer_data]
lifecycle {
precondition {
condition = filesha256(each.value.source) == each.value.sha256
error_message = "Latest pointer changed since manifest creation."
}
}
}
resource "aws_s3_object" "bootstrap" {
for_each = { for key, artifact in local.artifacts : key => artifact if key == "index.sh" }
bucket = aws_s3_bucket.artifacts.id
key = each.key
source = each.value.source
source_hash = each.value.sha256
content_type = "text/plain; charset=utf-8"
cache_control = "public, max-age=60"
metadata = { sha256 = each.value.sha256 }
depends_on = [aws_s3_object.latest]
lifecycle {
precondition {
condition = filesha256(each.value.source) == each.value.sha256
error_message = "Bootstrap changed since manifest creation."
}
}
}