Skip to content

Commit 5cef628

Browse files
authored
fix: move spartan-script tf to spartan, use file in bucket (#10395)
1 parent 6cbd375 commit 5cef628

File tree

3 files changed

+144
-61
lines changed

3 files changed

+144
-61
lines changed

aztec-up/terraform/main.tf

-12
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,6 @@ resource "null_resource" "upload_public_directory" {
108108
}
109109
}
110110

111-
# resource "aws_route53_record" "subdomain_record" {
112-
# zone_id = data.terraform_remote_state.aztec2_iac.outputs.aws_route53_zone_id
113-
# name = "install.aztec.network"
114-
# type = "A"
115-
116-
# alias {
117-
# name = aws_s3_bucket_website_configuration.website_bucket.website_domain
118-
# zone_id = aws_s3_bucket.install_bucket.hosted_zone_id
119-
# evaluate_target_health = true
120-
# }
121-
# }
122-
123111
resource "aws_cloudfront_distribution" "install" {
124112
origin {
125113
domain_name = aws_s3_bucket.install_bucket.website_endpoint

iac/main.tf

-49
Original file line numberDiff line numberDiff line change
@@ -125,52 +125,3 @@ resource "aws_route53_record" "static" {
125125
evaluate_target_health = true
126126
}
127127
}
128-
129-
resource "aws_s3_bucket" "sp_testnet_redirect" {
130-
bucket = "sp-testnet.aztec.network"
131-
132-
website {
133-
redirect_all_requests_to {
134-
host_name = "github.com"
135-
protocol = "https"
136-
path = "/AztecProtocol/aztec-packages/refs/heads/master/spartan/releases/create-spartan.sh"
137-
}
138-
}
139-
}
140-
141-
resource "aws_s3_bucket_public_access_block" "sp_testnet_public_access" {
142-
bucket = aws_s3_bucket.sp_testnet_redirect.id
143-
144-
block_public_acls = false
145-
block_public_policy = false
146-
ignore_public_acls = false
147-
restrict_public_buckets = false
148-
}
149-
150-
resource "aws_s3_bucket_policy" "sp_testnet_policy" {
151-
bucket = aws_s3_bucket.sp_testnet_redirect.id
152-
153-
policy = jsonencode({
154-
Version = "2012-10-17"
155-
Statement = [
156-
{
157-
Effect = "Allow"
158-
Principal = "*"
159-
Action = "s3:GetObject"
160-
Resource = "arn:aws:s3:::${aws_s3_bucket.sp_testnet_redirect.id}/*"
161-
}
162-
]
163-
})
164-
}
165-
166-
resource "aws_route53_record" "sp_testnet" {
167-
zone_id = data.terraform_remote_state.aztec2_iac.outputs.aws_route53_zone_id
168-
name = "sp-testnet.aztec.network"
169-
type = "A"
170-
171-
alias {
172-
name = aws_s3_bucket.sp_testnet_redirect.website_domain
173-
zone_id = aws_s3_bucket.sp_testnet_redirect.hosted_zone_id
174-
evaluate_target_health = true
175-
}
176-
}

spartan/terraform/user-script/main.tf

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
terraform {
2+
backend "s3" {
3+
bucket = "aztec-terraform"
4+
key = "spartan-script"
5+
region = "eu-west-2"
6+
}
7+
required_providers {
8+
aws = {
9+
source = "hashicorp/aws"
10+
version = "5.29.0"
11+
}
12+
}
13+
}
14+
15+
provider "aws" {
16+
region = "eu-west-2"
17+
}
18+
19+
data "terraform_remote_state" "aztec2_iac" {
20+
backend = "s3"
21+
config = {
22+
bucket = "aztec-terraform"
23+
key = "aztec2/iac"
24+
region = "eu-west-2"
25+
}
26+
}
27+
28+
resource "aws_s3_bucket" "sp_testnet_script" {
29+
bucket = "sp-testnet.aztec.network"
30+
}
31+
32+
resource "aws_s3_bucket_website_configuration" "sp_testnet_script" {
33+
bucket = aws_s3_bucket.sp_testnet_script.id
34+
35+
index_document {
36+
suffix = "create-spartan.sh"
37+
}
38+
}
39+
40+
resource "aws_s3_bucket_public_access_block" "sp_testnet_public_access" {
41+
bucket = aws_s3_bucket.sp_testnet_script.id
42+
43+
block_public_acls = false
44+
block_public_policy = false
45+
ignore_public_acls = false
46+
restrict_public_buckets = false
47+
}
48+
49+
resource "aws_s3_bucket_policy" "sp_testnet_policy" {
50+
bucket = aws_s3_bucket.sp_testnet_script.id
51+
52+
policy = jsonencode({
53+
Version = "2012-10-17"
54+
Statement = [
55+
{
56+
Effect = "Allow"
57+
Principal = "*"
58+
Action = "s3:GetObject"
59+
Resource = "arn:aws:s3:::${aws_s3_bucket.sp_testnet_script.id}/*"
60+
}
61+
]
62+
})
63+
}
64+
65+
# Upload files to s3 bucket
66+
resource "null_resource" "upload_script" {
67+
triggers = {
68+
always_run = "${timestamp()}"
69+
}
70+
71+
provisioner "local-exec" {
72+
interpreter = ["/bin/bash", "-c"]
73+
command = <<EOT
74+
aws s3 cp ../../releases/create-spartan.sh s3://${aws_s3_bucket.sp_testnet_script.id}/
75+
EOT
76+
}
77+
}
78+
79+
resource "aws_cloudfront_distribution" "sp_testnet" {
80+
origin {
81+
domain_name = aws_s3_bucket.sp_testnet_script.website_endpoint
82+
origin_id = "S3-sp-testnet-aztec-network"
83+
84+
custom_origin_config {
85+
http_port = 80
86+
https_port = 443
87+
origin_protocol_policy = "http-only"
88+
origin_ssl_protocols = ["TLSv1.2"]
89+
}
90+
}
91+
92+
enabled = true
93+
is_ipv6_enabled = true
94+
default_root_object = ""
95+
96+
aliases = ["sp-testnet.aztec.network"]
97+
98+
default_cache_behavior {
99+
allowed_methods = ["GET", "HEAD"]
100+
cached_methods = ["GET", "HEAD"]
101+
target_origin_id = "S3-sp-testnet-aztec-network"
102+
103+
forwarded_values {
104+
query_string = false
105+
106+
cookies {
107+
forward = "none"
108+
}
109+
}
110+
111+
# TODO: Once new aztec-up script (almost certainly within days of this change), switch to redirect-to-https.
112+
# viewer_protocol_policy = "redirect-to-https"
113+
viewer_protocol_policy = "allow-all"
114+
min_ttl = 0
115+
default_ttl = 3600
116+
max_ttl = 86400
117+
}
118+
119+
price_class = "PriceClass_All"
120+
121+
viewer_certificate {
122+
acm_certificate_arn = data.terraform_remote_state.aztec2_iac.outputs.aws_acm_certificate_aztec_network_arn
123+
ssl_support_method = "sni-only"
124+
minimum_protocol_version = "TLSv1.2_2019"
125+
}
126+
127+
restrictions {
128+
geo_restriction {
129+
restriction_type = "none"
130+
}
131+
}
132+
}
133+
134+
resource "aws_route53_record" "sp_testnet" {
135+
zone_id = data.terraform_remote_state.aztec2_iac.outputs.aws_route53_zone_id
136+
name = "sp-testnet.aztec.network"
137+
type = "A"
138+
139+
alias {
140+
name = aws_cloudfront_distribution.sp_testnet.domain_name
141+
zone_id = aws_cloudfront_distribution.sp_testnet.hosted_zone_id
142+
evaluate_target_health = false
143+
}
144+
}

0 commit comments

Comments
 (0)