Skip to content

Commit 88f1c42

Browse files
authored
Merge pull request #725 from NixOS/fix-deprecations
Fix most deprecation warnings in terraform workspace
2 parents aa43b31 + 3f7bfbb commit 88f1c42

File tree

10 files changed

+189
-25
lines changed

10 files changed

+189
-25
lines changed

terraform/cache-bucket/main.tf

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,30 @@ variable "bucket_name" {
55
resource "aws_s3_bucket" "cache" {
66
provider = aws
77
bucket = var.bucket_name
8+
}
9+
10+
resource "aws_s3_bucket_lifecycle_configuration" "cache" {
11+
provider = aws
12+
bucket = aws_s3_bucket.cache.id
13+
14+
rule {
15+
id = "Infrequent Access"
16+
status = "Enabled"
817

9-
lifecycle_rule {
10-
enabled = true
18+
filter {
19+
prefix = ""
20+
}
1121

1222
transition {
1323
days = 365
1424
storage_class = "STANDARD_IA"
1525
}
1626
}
27+
}
28+
29+
resource "aws_s3_bucket_cors_configuration" "cache" {
30+
provider = aws
31+
bucket = aws_s3_bucket.cache.bucket
1732

1833
cors_rule {
1934
allowed_headers = ["Authorization"]
@@ -23,6 +38,7 @@ resource "aws_s3_bucket" "cache" {
2338
}
2439
}
2540

41+
2642
resource "aws_s3_bucket_public_access_block" "cache" {
2743
bucket = aws_s3_bucket.cache.bucket
2844

terraform/cache-staging.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ module "cache-staging-202010" {
1111
}
1212
}
1313

14+
import {
15+
to = module.cache-staging-202010.aws_s3_bucket_lifecycle_configuration.cache
16+
id = "nix-cache-staging"
17+
}
18+
19+
import {
20+
to = module.cache-staging-202010.aws_s3_bucket_cors_configuration.cache
21+
id = "nix-cache-staging"
22+
}
23+
24+
1425
# This is the new bucket we want to use in future.
1526
module "cache-staging-202410" {
1627
source = "./cache-bucket"
@@ -21,6 +32,16 @@ module "cache-staging-202410" {
2132
}
2233
}
2334

35+
import {
36+
to = module.cache-staging-202410.aws_s3_bucket_lifecycle_configuration.cache
37+
id = "nix-cache-staging-202410"
38+
}
39+
40+
import {
41+
to = module.cache-staging-202410.aws_s3_bucket_cors_configuration.cache
42+
id = "nix-cache-staging-202410"
43+
}
44+
2445
# The fastly configuration below will first try the new bucket and than the old bucket.
2546
# As demonstation we have two files in the buckets:
2647
# $ curl https://cache-staging.nixos.org/new-cache │

terraform/cache.tf

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,37 @@ locals {
55
resource "aws_s3_bucket" "cache" {
66
provider = aws.us
77
bucket = "nix-cache"
8+
}
9+
10+
resource "aws_s3_bucket_lifecycle_configuration" "cache" {
11+
provider = aws.us
12+
bucket = aws_s3_bucket.cache.id
813

9-
lifecycle_rule {
10-
enabled = true
14+
transition_default_minimum_object_size = "varies_by_storage_class"
15+
16+
rule {
17+
id = "Infrequent Access"
18+
status = "Enabled"
19+
20+
filter {
21+
prefix = ""
22+
}
1123

1224
transition {
1325
days = 365
1426
storage_class = "STANDARD_IA"
1527
}
1628
}
29+
}
30+
31+
import {
32+
to = aws_s3_bucket_lifecycle_configuration.cache
33+
id = aws_s3_bucket.cache.id
34+
}
1735

36+
resource "aws_s3_bucket_cors_configuration" "cache" {
37+
provider = aws.us
38+
bucket = aws_s3_bucket.cache.id
1839
cors_rule {
1940
allowed_headers = ["Authorization"]
2041
allowed_methods = ["GET"]
@@ -23,6 +44,11 @@ resource "aws_s3_bucket" "cache" {
2344
}
2445
}
2546

47+
import {
48+
to = aws_s3_bucket_cors_configuration.cache
49+
id = aws_s3_bucket.cache.id
50+
}
51+
2652
resource "aws_s3_bucket_object" "cache-nix-cache-info" {
2753
provider = aws.us
2854

terraform/cache_inventory.tf

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22
resource "aws_s3_bucket" "cache_inventory" {
33
provider = aws.us
44
bucket = "nix-cache-inventory"
5+
}
6+
7+
resource "aws_s3_bucket_lifecycle_configuration" "cache_inventory" {
8+
provider = aws.us
9+
bucket = aws_s3_bucket.cache_inventory.id
510

6-
lifecycle_rule {
7-
enabled = true
11+
transition_default_minimum_object_size = "varies_by_storage_class"
12+
13+
rule {
14+
id = "tf-s3-lifecycle-20231017200421961900000001"
15+
status = "Enabled"
16+
17+
filter {
18+
prefix = ""
19+
}
820

921
# Only keep the last 30 days
1022
expiration {
@@ -13,6 +25,11 @@ resource "aws_s3_bucket" "cache_inventory" {
1325
}
1426
}
1527

28+
import {
29+
to = aws_s3_bucket_lifecycle_configuration.cache_inventory
30+
id = aws_s3_bucket.cache_inventory.id
31+
}
32+
1633
resource "aws_s3_bucket_inventory" "cache_inventory" {
1734
provider = aws.us
1835

@@ -40,4 +57,3 @@ resource "aws_s3_bucket_inventory" "cache_inventory" {
4057
}
4158
}
4259
}
43-

terraform/cache_log.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ resource "aws_s3_bucket_lifecycle_configuration" "cache_log" {
2222
id = "rule-1"
2323
status = "Enabled"
2424

25+
filter {
26+
prefix = ""
27+
}
28+
2529
expiration {
2630
days = "30"
2731
}

terraform/channels.tf

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,33 @@ locals {
1010
# Use the website endpoint because the bucket is configured with website
1111
# enabled. This also means we can't use TLS between Fastly and AWS because
1212
# the website endpoint only has port 80 open.
13-
channels_backend = aws_s3_bucket.channels.website_endpoint
13+
channels_backend = "nix-channels.s3-website-us-east-1.amazonaws.com"
14+
# TODO: Uncomment this once has been applied once. This is to work around fastly bug https://github.com/fastly/terraform-provider-fastly/issues/884
15+
# channels_backend = aws_s3_bucket_website_configuration.channels.website_endpoint
1416
}
1517

1618
resource "aws_s3_bucket" "channels" {
1719
provider = aws.us
1820
bucket = "nix-channels"
21+
}
22+
23+
resource "aws_s3_bucket_website_configuration" "channels" {
24+
provider = aws.us
25+
bucket = aws_s3_bucket.channels.id
1926

20-
website {
21-
index_document = "index.html"
27+
index_document {
28+
suffix = "index.html"
2229
}
30+
}
31+
32+
import {
33+
to = aws_s3_bucket_website_configuration.channels
34+
id = aws_s3_bucket.channels.id
35+
}
36+
37+
resource "aws_s3_bucket_cors_configuration" "channels" {
38+
provider = aws.us
39+
bucket = aws_s3_bucket.channels.id
2340

2441
cors_rule {
2542
allowed_headers = ["*"]
@@ -30,6 +47,12 @@ resource "aws_s3_bucket" "channels" {
3047
}
3148
}
3249

50+
import {
51+
to = aws_s3_bucket_cors_configuration.channels
52+
id = aws_s3_bucket.channels.id
53+
54+
}
55+
3356
resource "aws_s3_bucket_object" "channels-index-html" {
3457
provider = aws.us
3558

@@ -275,5 +298,5 @@ resource "fastly_tls_subscription" "channels" {
275298

276299
# TODO: move the DNS config to terraform
277300
output "channels-managed_dns_challenge" {
278-
value = fastly_tls_subscription.channels.managed_dns_challenge
301+
value = fastly_tls_subscription.channels.managed_dns_challenges
279302
}

terraform/gh-releases.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,5 @@ resource "fastly_tls_subscription" "gh_releases" {
181181
}
182182

183183
output "gh-releases-managed_dns_challenge" {
184-
value = fastly_tls_subscription.gh_releases.managed_dns_challenge
184+
value = fastly_tls_subscription.gh_releases.managed_dns_challenges
185185
}

terraform/nixpkgs-tarballs.tf

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,27 @@ locals {
33
# Use the website endpoint because the bucket is configured with website
44
# enabled. This also means we can't use TLS between Fastly and AWS because
55
# the website endpoint only has port 80 open.
6-
tarballs_backend = aws_s3_bucket.nixpkgs-tarballs.website_endpoint
6+
tarballs_backend = "nixpkgs-tarballs.s3-website-eu-west-1.amazonaws.com"
7+
# TODO: Uncomment this once has been applied once. This is to work around fastly bug https://github.com/fastly/terraform-provider-fastly/issues/884
8+
# tarballs_backend = aws_s3_bucket_website_configuration.nixpkgs-tarballs.website_endpoint
79
}
810

911
resource "aws_s3_bucket" "nixpkgs-tarballs" {
1012
bucket = "nixpkgs-tarballs"
13+
}
1114

12-
website {
13-
index_document = "index.html"
15+
resource "aws_s3_bucket_website_configuration" "nixpkgs-tarballs" {
16+
bucket = aws_s3_bucket.nixpkgs-tarballs.id
17+
index_document {
18+
suffix = "index.html"
1419
}
1520
}
1621

22+
import {
23+
to = aws_s3_bucket_website_configuration.nixpkgs-tarballs
24+
id = aws_s3_bucket.nixpkgs-tarballs.id
25+
}
26+
1727
resource "aws_s3_bucket_policy" "nixpkgs-tarballs" {
1828
bucket = aws_s3_bucket.nixpkgs-tarballs.id
1929

@@ -284,7 +294,7 @@ resource "fastly_tls_subscription" "nixpkgs-tarballs" {
284294

285295
# TODO: move the DNS config to terraform
286296
output "nixpkgs-tarballs-managed_dns_challenge" {
287-
value = fastly_tls_subscription.nixpkgs-tarballs.managed_dns_challenge
297+
value = fastly_tls_subscription.nixpkgs-tarballs.managed_dns_challenges
288298
}
289299

290300
# Create an S3 bucket for CloudTrail logs
@@ -293,12 +303,21 @@ resource "aws_s3_bucket" "nixpkgs-tarballs-cloudtrail-logs" {
293303
# We can potentially make this public for transparency?
294304
# But first I want to see what the logs look like.
295305
acl = "private"
306+
}
296307

297-
versioning {
298-
enabled = true
308+
resource "aws_s3_bucket_versioning" "nixpkgs-tarballs-cloudtrail-logs" {
309+
bucket = aws_s3_bucket.nixpkgs-tarballs-cloudtrail-logs.id
310+
versioning_configuration {
311+
status = "Enabled"
299312
}
300313
}
301314

315+
316+
import {
317+
to = aws_s3_bucket_versioning.nixpkgs-tarballs-cloudtrail-logs
318+
id = aws_s3_bucket.nixpkgs-tarballs-cloudtrail-logs.id
319+
}
320+
302321
# Attach a policy to the CloudTrail logs S3 bucket
303322
data "aws_iam_policy_document" "nixpkgs-tarballs-cloudtrail-logs-policy" {
304323
statement {

terraform/releases.tf

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,35 @@ locals {
1212

1313
resource "aws_s3_bucket" "releases" {
1414
bucket = "nix-releases"
15+
}
16+
17+
resource "aws_s3_bucket_lifecycle_configuration" "releases" {
18+
bucket = aws_s3_bucket.releases.id
19+
1520

16-
lifecycle_rule {
17-
enabled = true
21+
transition_default_minimum_object_size = "varies_by_storage_class"
22+
rule {
23+
id = "tf-s3-lifecycle-20230907091915137900000001"
24+
status = "Enabled"
25+
26+
filter {
27+
prefix = ""
28+
}
1829

1930
transition {
2031
days = 365
2132
storage_class = "STANDARD_IA"
2233
}
2334
}
35+
}
36+
37+
import {
38+
id = aws_s3_bucket.releases.id
39+
to = aws_s3_bucket_lifecycle_configuration.releases
40+
}
41+
42+
resource "aws_s3_bucket_cors_configuration" "releases" {
43+
bucket = aws_s3_bucket.releases.id
2444

2545
cors_rule {
2646
allowed_headers = ["*"]
@@ -31,6 +51,11 @@ resource "aws_s3_bucket" "releases" {
3151
}
3252
}
3353

54+
import {
55+
to = aws_s3_bucket_cors_configuration.releases
56+
id = aws_s3_bucket.releases.id
57+
}
58+
3459
resource "aws_s3_bucket_object" "releases-index-html" {
3560
acl = "public-read"
3661
bucket = aws_s3_bucket.releases.bucket
@@ -238,5 +263,5 @@ resource "fastly_tls_subscription" "releases" {
238263

239264
# TODO: move the DNS config to terraform
240265
output "releases-managed_dns_challenge" {
241-
value = fastly_tls_subscription.releases.managed_dns_challenge
266+
value = fastly_tls_subscription.releases.managed_dns_challenges
242267
}

0 commit comments

Comments
 (0)