Skip to content

Commit 6d1e3b1

Browse files
committed
add the datastream syncer
1 parent c5896a1 commit 6d1e3b1

4 files changed

Lines changed: 101 additions & 22 deletions

File tree

infra/aws/terraform/registry.k8s.io/main.tf

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,35 @@ locals {
1818
// aws ec2 describe-regions --all-regions --query "Regions[].RegionName" --output json | jq .[] | awk '{print $0","}' | sort --version-sort
1919
regions = [
2020
"af-south-1",
21-
# "ap-east-1",
22-
# "ap-east-2",
21+
"ap-east-1",
22+
"ap-east-2",
2323
"ap-northeast-1",
24-
# "ap-northeast-2",
25-
# "ap-northeast-3",
24+
"ap-northeast-2",
25+
"ap-northeast-3",
2626
"ap-southeast-1",
2727
"ap-southeast-2",
28-
# "ap-southeast-3",
29-
# "ap-southeast-4",
30-
# "ap-southeast-5",
31-
# "ap-southeast-6",
32-
# "ap-southeast-7",
28+
"ap-southeast-3",
29+
"ap-southeast-4",
30+
"ap-southeast-5",
31+
"ap-southeast-6",
32+
"ap-southeast-7",
3333
"ap-south-1",
34-
# "ap-south-2",
35-
# "ca-central-1",
36-
# "ca-west-1",
34+
"ap-south-2",
35+
"ca-central-1",
36+
"ca-west-1",
3737
"eu-central-1",
38-
# "eu-central-2",
39-
# "eu-north-1",
38+
"eu-central-2",
39+
"eu-north-1",
4040
"eu-south-1",
41-
# "eu-south-2",
41+
"eu-south-2",
4242
"eu-west-1",
43-
# "eu-west-2",
43+
"eu-west-2",
4444
"eu-west-3",
45-
# "il-central-1",
46-
# "me-central-1",
47-
# "me-south-1",
48-
# "mx-central-1",
49-
# "sa-east-1",
45+
"il-central-1",
46+
"me-central-1",
47+
"me-south-1",
48+
"mx-central-1",
49+
"sa-east-1",
5050
"us-east-1",
5151
"us-east-2",
5252
"us-west-1",
@@ -78,6 +78,9 @@ module "s3_buckets" {
7878
for_each = setsubtract(toset(local.regions), ["us-east-2"])
7979
source = "./s3"
8080
region = each.key
81+
alternative_bucket_names = {
82+
eu-west-2 = "767373bbdcb8270361b96548387bf2a9ad0d48758c35-eu-west-2"
83+
}
8184

8285
prefix = var.prefix
8386
}

infra/aws/terraform/registry.k8s.io/s3/bucket.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
resource "aws_s3_bucket" "registry-k8s-io" {
18-
bucket = "${var.prefix}registry-k8s-io-${var.region}"
18+
bucket = lookup(var.alternative_bucket_names, var.region, "${var.prefix}registry-k8s-io-${var.region}")
1919
region = var.region
2020
}
2121

infra/aws/terraform/registry.k8s.io/s3/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ variable "region" {
3636
type = string
3737
}
3838

39+
variable "alternative_bucket_names" {
40+
description = "Map of region to alternative bucket name if the default naming convention is not used"
41+
type = map(string)
42+
default = {}
43+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
locals {
18+
// When we complete the initial datasync, remove the region from this list
19+
// aws ec2 describe-regions --all-regions --query "Regions[].RegionName" --output json | jq .[] | awk '{print $0","}' | sort --version-sort
20+
new_regions = [
21+
# "foobar"
22+
]
23+
}
24+
25+
module "s3_locations" {
26+
source = "github.com/upodroid/terraform-aws-datasync//modules/datasync-locations?ref=main"
27+
s3_locations = concat(
28+
[
29+
{
30+
name = "source-bucket"
31+
s3_bucket_arn = module.us-east-2.bucket_arn
32+
subdirectory = "/"
33+
create_role = false
34+
s3_config_bucket_access_role_arn = "arn:aws:iam::513428760722:role/AWSDataSyncS3BucketAccess"
35+
region = "us-east-2"
36+
},
37+
],
38+
[
39+
for idx, region in local.new_regions :
40+
{
41+
name = "${region}"
42+
s3_bucket_arn = module.s3_buckets[region].bucket_arn
43+
subdirectory = "/"
44+
create_role = false
45+
s3_config_bucket_access_role_arn = "arn:aws:iam::513428760722:role/AWSDataSyncS3BucketAccess"
46+
region = "${region}"
47+
}
48+
]
49+
)
50+
}
51+
52+
module "s3_to_s3_tasks" {
53+
source = "github.com/upodroid/terraform-aws-datasync//modules/datasync-task?ref=main"
54+
datasync_tasks = [
55+
for idx, region in local.new_regions :
56+
{
57+
name = "${region}"
58+
source_location_arn = "arn:aws:datasync:us-east-2:513428760722:location/loc-050a6ce9904237d71"
59+
destination_location_arn = module.s3_locations.s3_locations[region].arn
60+
task_mode = "ENHANCED"
61+
options = {
62+
verify_mode = "ONLY_FILES_TRANSFERRED" # Enhanced mode supports ONLY_FILES_TRANSFERRED or NONE
63+
gid = "NONE"
64+
posix_permissions = "NONE"
65+
uid = "NONE"
66+
}
67+
schedule_expression = "cron(0 0 * * ? *)" # Run at 00:00 every day, we only need the first run.
68+
region = "us-east-2"
69+
}
70+
]
71+
}

0 commit comments

Comments
 (0)