|
| 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