Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage win.rustup.rs in Terragrunt #422

Merged
merged 8 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions terragrunt/accounts/legacy/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"regions": [
{
"region": "us-west-1"
},
{
"region": "us-east-1",
"alias": "us-east-1"
}
]
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions terragrunt/accounts/legacy/rustup-dev/win-rustup-rs/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
source = "../../../../..//terragrunt/modules/win-rustup-rs"
}

include {
path = find_in_parent_folders()
merge_strategy = "deep"
}

inputs = {
domain_name = "dev-win.rustup.rs"
static_bucket = "dev-static-rust-lang-org"
}
1 change: 1 addition & 0 deletions terragrunt/accounts/legacy/rustup-prod/deployed-ref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
72f17a0c5537a8aa23271c5836fe50673e95018c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
source = "git::../../../../..//terragrunt/modules/win-rustup-rs?ref=${trimspace(file("../deployed-ref"))}"
}

include {
path = find_in_parent_folders()
merge_strategy = "deep"
}

inputs = {
domain_name = "win.rustup.rs"
static_bucket = "static-rust-lang-org"
}
6 changes: 6 additions & 0 deletions terragrunt/modules/win-rustup-rs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# win.rustup.rs

`win.rustup.rs` is a CloudFront distribution that provides convenient, short
URLs for downloading the Rustup installer on Windows. It features a path for
each supported architecture, which serves the latest version of the respective
installer.
11 changes: 11 additions & 0 deletions terragrunt/modules/win-rustup-rs/_terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
required_version = "~> 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.20"
}
}
}

13 changes: 13 additions & 0 deletions terragrunt/modules/win-rustup-rs/certificate.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module "certificate" {
source = "../acm-certificate"

providers = {
aws = aws.us-east-1
}

domains = [
var.domain_name,
]

legacy = true
}
12 changes: 12 additions & 0 deletions terragrunt/modules/win-rustup-rs/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
data "aws_iam_role" "cloudfront_lambda" {
name = "cloudfront-lambda"
}

data "aws_route53_zone" "rustup" {
// Convert {dev-win,win}.rustup.rs into rustup.rs
name = join(".", reverse(slice(reverse(split(".", var.domain_name)), 0, 2)))
}

data "aws_s3_bucket" "static" {
bucket = var.static_bucket
}
7 changes: 7 additions & 0 deletions terragrunt/modules/win-rustup-rs/dns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "aws_route53_record" "record" {
zone_id = data.aws_route53_zone.rustup.id
name = var.domain_name
type = "CNAME"
ttl = 300
records = [aws_cloudfront_distribution.distribution.domain_name]
}
15 changes: 15 additions & 0 deletions terragrunt/modules/win-rustup-rs/lambdas/viewer-request/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function handler(event) {
var request = event.request;

if (request.uri === '/') {
request.uri = '/i686-pc-windows-msvc/rustup-init.exe';
} else if (request.uri === '/i686') {
request.uri = '/i686-pc-windows-msvc/rustup-init.exe';
} else if (request.uri === '/x86_64') {
request.uri = '/x86_64-pc-windows-msvc/rustup-init.exe';
} else if (request.uri === '/aarch64') {
request.uri = '/aarch64-pc-windows-msvc/rustup-init.exe';
}

return request;
}
76 changes: 76 additions & 0 deletions terragrunt/modules/win-rustup-rs/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
locals {
human_readable_name = replace(var.domain_name, ".", "-")
}

resource "aws_cloudfront_function" "viewer_request" {
name = "${local.human_readable_name}--viewer-request"
runtime = "cloudfront-js-1.0"
code = file("${path.module}/lambdas/viewer-request/index.js")
}

resource "aws_cloudfront_response_headers_policy" "content_disposition" {
name = local.human_readable_name
comment = "Set the Content-Disposition header for ${var.domain_name}"

custom_headers_config {
items {
header = "Content-Disposition"
value = "attachment; filename=\"rustup-init.exe\""
override = true
}
}
}

resource "aws_cloudfront_distribution" "distribution" {
comment = var.domain_name

enabled = true
wait_for_deployment = false
is_ipv6_enabled = true
price_class = "PriceClass_All"

aliases = [
var.domain_name,
]

viewer_certificate {
acm_certificate_arn = module.certificate.arn
ssl_support_method = "sni-only"
minimum_protocol_version = "TLSv1.1_2016"
}

default_cache_behavior {
target_origin_id = "main"
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
compress = true
viewer_protocol_policy = "redirect-to-https"

response_headers_policy_id = aws_cloudfront_response_headers_policy.content_disposition.id

forwarded_values {
query_string = false

cookies {
forward = "none"
}
}

function_association {
event_type = "viewer-request"
function_arn = aws_cloudfront_function.viewer_request.arn
}
}

origin {
origin_id = "main"
domain_name = data.aws_s3_bucket.static.bucket_regional_domain_name
origin_path = "/rustup/dist"
}

restrictions {
geo_restriction {
restriction_type = "none"
}
}
}
9 changes: 9 additions & 0 deletions terragrunt/modules/win-rustup-rs/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "domain_name" {
description = "The domain name for the CloudFront distribution"
type = string
}

variable "static_bucket" {
description = "Name of the bucket that stores the Rustup releases"
type = string
}
Loading