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

Fastly config for mobile backend #104

Merged
merged 3 commits into from
Sep 9, 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
24 changes: 24 additions & 0 deletions mobile-backend/.terraform.lock.hcl

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

17 changes: 17 additions & 0 deletions mobile-backend/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
terraform {
cloud {
organization = "govuk"
workspaces {
tags = ["fastly", "mobile-backend"]
}
}
required_version = "~> 1.7"
required_providers {
fastly = {
source = "fastly/fastly"
version = "5.11.0"
}
}
}

provider "fastly" {}
Empty file added mobile-backend/outputs.tf
Empty file.
78 changes: 78 additions & 0 deletions mobile-backend/service.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
locals {
secrets = yamldecode(var.secrets)
hostname = local.secrets["hostname"]
origin_hostname = local.secrets["origin_hostname"]

strip_headers = [
"x-amz-id-2",
"x-amz-meta-server-side-encryption",
"x-amz-request-id",
"x-amz-version-id",
"x-amz-server-side-encryption"
]
# headers to add
ttl = "300s" # 5 minutes
cache_control = "max-age=300, public, immutable"
access_control_allow_origin = "*"
}

resource "fastly_service_vcl" "mobile_backend_service" {
name = "GOV.UK App mobile backend - ${title(var.environment)}"
http3 = true

domain {
name = local.hostname
}

backend {
name = "Mobile backend config bucket - ${var.environment}"
address = local.origin_hostname
port = 443

connect_timeout = 1000
first_byte_timeout = 15000
max_conn = 200
between_bytes_timeout = 10000

ssl_check_cert = true
ssl_ciphers = "ECDHE-RSA-AES256-GCM-SHA384"
ssl_cert_hostname = local.origin_hostname
ssl_sni_hostname = local.origin_hostname
min_tls_version = "1.2"
}

dynamic "header" {
for_each = local.strip_headers
content {
destination = "http.${header.value}"
name = "Remove ${header.value}"
action = "delete"
type = "cache"
}
}

header {
destination = "ttl"
name = "Add ttl header"
action = "set"
type = "response"
source = local.ttl
}

header {
destination = "http.Cache-Control"
name = "Add Cache-Control header"
action = "set"
type = "response"
source = local.cache_control
}

header {
destination = "http.Access-Control-Allow-Origin"
name = "Add Access-Control-Allow-Origin header"
action = "set"
type = "response"
source = local.access_control_allow_origin
}

}
7 changes: 7 additions & 0 deletions mobile-backend/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "environment" {
type = string
}

variable "secrets" {
type = string
}
Loading