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

Migrate tldredirect #69

Merged
merged 6 commits into from
Apr 4, 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
7 changes: 7 additions & 0 deletions modules/tld-redirect/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
fastly = {
source = "fastly/fastly"
}
}
}
14 changes: 14 additions & 0 deletions modules/tld-redirect/service.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "fastly_service_vcl" "service" {
name = "Production TLD Redirect"
comment = ""

domain {
name = "gov.uk"
}

vcl {
main = true
name = "main"
content = file("${path.module}/tldredirect.vcl")
}
}
58 changes: 58 additions & 0 deletions modules/tld-redirect/tldredirect.vcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
backend dummy {
.host = "127.0.0.1";
.port = "1";
.probe = {
.request = "invalid";
.initial = 0;
.interval = 365d;
}
}

sub vcl_recv {

# Force SSL.
if (!req.http.Fastly-SSL) {
error 801 "Force SSL";
} else {
error 802 "Redirect GOV.UK";
}

return(error);
}

sub vcl_fetch {
}

sub vcl_hit {
}

sub vcl_miss {
}

sub vcl_deliver {
}

sub vcl_error {
if (obj.status == 801) {
set obj.status = 301;
set obj.response = "Moved Permanently";
set obj.http.Location = "https://" req.http.host req.url;
set obj.http.Fastly-Backend-Name = "force_ssl";
}

if (obj.status == 802) {
set obj.status = 301;
set obj.response = "Moved Permanently";
set obj.http.Location = "https://www.gov.uk" req.url;
set obj.http.Strict-Transport-Security = "max-age=63072000; preload";
}

synthetic {""};
return (deliver);
}

sub vcl_pass {
}

sub vcl_hash {
}
3 changes: 3 additions & 0 deletions tld_redirect.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module "tldredirect-production" {
source = "./modules/tld-redirect"
}