|
| 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