Skip to content

Commit d565253

Browse files
committed
feat: cleanup before split
1 parent df5aa00 commit d565253

17 files changed

+164
-120
lines changed

infra/.terraform.lock.hcl

Lines changed: 0 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
.PHONY: fmt
3+
fmt:
4+
@tf fmt ../**/*.tf
5+
@tf fmt ../**/*.tfvars
6+
@tf fmt ../**/*.tftest.hcl
7+
8+
.PHONY: check
9+
check:
10+
@tf validate
11+
12+
.PHONY: yolo
13+
yolo:
14+
@echo "Wise, you are not..."
15+
@tf apply -auto-approve

infra/Makefile

Lines changed: 0 additions & 15 deletions
This file was deleted.

infra/cdn/main.tf

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
variable "name" { type = string }
2-
variable "domain" { type = string }
3-
variable "extra_domains" { type = list(string) }
4-
variable "backend_address" { type = string }
5-
variable "default_ttl" { type = number }
6-
variable "stale_if_error" { type = bool }
7-
variable "stale_if_error_ttl" { type = number }
8-
variable "aws_access_key_id" { type = string }
9-
variable "aws_secret_access_key" { type = string }
10-
variable "datadog_api_key" { type = string }
11-
variable "fastly_header_token" { type = string }
12-
131
resource "fastly_service_vcl" "python_org" {
142
name = var.name
153
default_ttl = var.default_ttl
@@ -194,7 +182,7 @@ resource "fastly_service_vcl" "python_org" {
194182
destination = "http.Fastly-Token"
195183
name = "Fastly Token"
196184
priority = 10
197-
source = "\"${var.FASTLY_HEADER_TOKEN}\""
185+
source = "\"${var.fastly_header_token}\""
198186
type = "request"
199187
}
200188
header {
@@ -259,7 +247,7 @@ resource "fastly_service_vcl" "python_org" {
259247

260248
logging_datadog {
261249
name = "ratelimit-debug"
262-
token = var.DATADOG_API_KEY
250+
token = var.datadog_key
263251
region = "US"
264252
}
265253

@@ -275,8 +263,8 @@ resource "fastly_service_vcl" "python_org" {
275263
redundancy = "standard"
276264
format_version = 2
277265
message_type = "classic"
278-
s3_access_key = var.s3_logging_keys
279-
s3_secret_key = var.s3_logging_keys
266+
s3_access_key = var.fastly_s3_logging["access_key"]
267+
s3_secret_key = var.fastly_s3_logging["secret_key"]
280268
}
281269

282270
logging_syslog {
@@ -355,4 +343,4 @@ resource "fastly_service_vcl" "python_org" {
355343
}
356344

357345
force_destroy = true
358-
}
346+
}

infra/cdn/variables.tf

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
1-
variable "FASTLY_API_KEY" {
1+
variable "fastly_key" {
22
type = string
33
description = "API key for the Fastly VCL edge configuration."
44
}
5-
variable "FASTLY_HEADER_TOKEN" {
6-
description = "Fastly Token for authentication"
5+
variable "fastly_header_token" {
6+
description = "Fastly header token ensure we only allow Fastly to access the service"
77
type = string
88
sensitive = true
99
}
10-
variable "DATADOG_API_KEY" {
10+
variable "datadog_key" {
1111
type = string
1212
description = "API key for Datadog logging"
1313
sensitive = true
14+
}
15+
variable "fastly_s3_logging" {
16+
type = string
17+
description = "S3 bucket keys for Fastly logging"
18+
sensitive = true
19+
}
20+
variable "name" {
21+
type = string
22+
description = "The name of the Fastly service."
23+
}
24+
variable "domain" {
25+
type = string
26+
description = "The domain name of the service."
27+
}
28+
variable "extra_domains" {
29+
type = list(string)
30+
description = "Extra domains to add to the service."
31+
}
32+
variable "backend_address" {
33+
type = string
34+
description = "The hostname of the backend service."
35+
}
36+
variable "default_ttl" {
37+
type = number
38+
description = "The default TTL for the service."
1439
}

infra/dns/main.tf

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@
55
# Retrieve the current AWS account data (based on secrets provided in .tfvars or TF Cloud)
66
data "aws_caller_identity" "current" {}
77

8-
# Input variables passed in from `$root/infra/main.tf`
9-
variable "tags" { type = map(any) }
10-
variable "primary_domain" { type = string }
11-
variable "user_content_domain" { type = string }
12-
variable "apex_txt" { type = list(any) }
13-
variable "name" { type = string }
14-
variable "zone_id" { type = string }
15-
variable "domain" { type = string }
16-
variable "fastly_endpoints" { type = map(any) }
17-
variable "domain_map" { type = map(any) }
8+
189

1910
# see if we're dealing with an apex domain or subdomain by splitting the domain name and counting the parts
2011
locals {

infra/dns/providers.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
provider "aws" {
22
alias = "dns"
33
region = "us-east-2"
4-
access_key = var.AWS_ACCESS_KEY_ID
5-
secret_key = var.AWS_SECRET_ACCESS_KEY
4+
access_key = var.aws_access_key
5+
secret_key = var.aws_secret_key
66
}

infra/dns/variables.tf

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
variable "AWS_ACCESS_KEY_ID" {
1+
variable "aws_access_key" {
22
type = string
33
description = "Access key for the AWS account."
44
sensitive = true
55
}
66

7-
variable "AWS_SECRET_ACCESS_KEY" {
7+
variable "aws_secret_key" {
88
type = string
99
description = "Secret access key for the AWS account."
1010
sensitive = true
@@ -27,3 +27,40 @@ variable "route53_record_ttl" {
2727
description = "The TTL for the CNAME record"
2828
default = 60
2929
}
30+
31+
variable "tags" {
32+
type = map(any)
33+
description = "Tags to apply to all resources"
34+
}
35+
variable "primary_domain" {
36+
type = string
37+
description = "The primary domain name"
38+
}
39+
variable "user_content_domain" {
40+
type = string
41+
description = "The user content (sub)domain name"
42+
}
43+
variable "apex_txt" {
44+
type = list(any)
45+
description = "The TXT record for the apex domain"
46+
}
47+
variable "name" {
48+
type = string
49+
description = "The name of the Fastly service"
50+
}
51+
variable "zone_id" {
52+
type = string
53+
description = "The Route 53 hosted zone ID"
54+
}
55+
variable "domain" {
56+
type = string
57+
description = "The domain name of the service"
58+
}
59+
variable "fastly_endpoints" {
60+
type = map(any)
61+
description = "The Fastly endpoints"
62+
}
63+
variable "domain_map" {
64+
type = map(any)
65+
description = "The domain map"
66+
}

infra/main.tf

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
variable "fastly_s3_logging" { type = map(any) }
2-
31
locals {
42
tags = {
53
Application = "Python.org"
@@ -20,47 +18,52 @@ locals {
2018
}
2119

2220
module "dns" {
21+
# TODO: this doesn't accommodate for DNS management splits between environments
2322
source = "./dns"
2423
tags = local.tags
2524
primary_domain = "python.org"
25+
zone_id = module.dns.primary_zone_id
26+
fastly_endpoints = local.fastly_endpoints
27+
domain_map = local.domain_map
28+
29+
aws_access_key = var.AWS_ACCESS_KEY_ID
30+
aws_secret_key = var.AWS_SECRET_ACCESS_KEY
31+
32+
# TODO: the below needs to be parameterized or fixed
33+
apex_txt = []
34+
domain = ""
35+
name = ""
36+
user_content_domain = ""
2637
}
2738

28-
module "pythondotorg_production" {
39+
module "fastly_production" {
2940
source = "./cdn"
3041

3142
name = "Python.org"
3243
domain = "python.org"
3344
extra_domains = ["www.python.org"]
3445
backend_address = "pythondotorg.ingress.us-east-2.psfhosted.computer"
3546
default_ttl = 3600
36-
stale_if_error = false
37-
stale_if_error_ttl = 43200
38-
39-
zone_id = module.dns.primary_zone_id
40-
backend = "pythondotorg.ingress.us-east-2.psfhosted.computer"
41-
s3_logging_keys = var.fastly_s3_logging
4247

43-
fastly_endpoints = local.fastly_endpoints
44-
domain_map = local.domain_map
48+
datadog_key = var.DATADOG_API_KEY
49+
fastly_key = var.FASTLY_API_KEY
50+
fastly_header_token = var.FASTLY_HEADER_TOKEN
51+
fastly_s3_logging = var.fastly_s3_logging
4552
}
4653

47-
module "pythondotorg_staging" {
54+
module "fastly_staging" {
4855
source = "./cdn"
4956

5057
name = "test.Python.org"
5158
domain = "test.python.org"
5259
extra_domains = []
5360
backend_address = "test-pythondotorg.ingress.us-east-2.psfhosted.computer"
5461
default_ttl = 3600
55-
stale_if_error = false
56-
stale_if_error_ttl = 43200
5762

58-
zone_id = module.dns.primary_zone_id
59-
backend = "test-pythondotorg.ingress.us-east-2.psfhosted.computer"
60-
s3_logging_keys = var.fastly_s3_logging
61-
62-
fastly_endpoints = local.fastly_endpoints
63-
domain_map = local.domain_map
63+
datadog_key = var.DATADOG_API_KEY
64+
fastly_key = var.FASTLY_API_KEY
65+
fastly_header_token = var.FASTLY_HEADER_TOKEN
66+
fastly_s3_logging = var.fastly_s3_logging
6467
}
6568

6669

0 commit comments

Comments
 (0)