TheSudoYT / terraform-aws-palworld

Terraform module for Palworld Server Infrastructure on AWS
BSD 3-Clause "New" or "Revised" License
11 stars 5 forks source link

fix(s3-regions): Fix to Support All Region Endpoints for S3 #16

Closed Josh-Tracy closed 7 months ago

Josh-Tracy commented 7 months ago

Details

Fixes #15

This doc https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#VirtualHostingBackwardsCompatibility explains that newer regions to not support the legacy global s3 endpoint.

Problem

Multiple functions in user_data contain the following aws or similar commands without region specified

aws s3 cp "$src" "$dst" 

This results in the following errors for newer regions trying to access s3 bucket objects:

An error occurred (IllegalLocationConstraintException) when calling the PutObject operation: The af-south-1 location constraint is incompatible for the region specific endpoint this request was sent to.

Fix

Appended --region ${aws_region} to the end of all aws commands. AWS region is taken from a data source

data "aws_region" "current" {}

and interpolated into user_data

data "template_file" "user_data_template" {
  template = file("${path.module}/templates/user_data_script.sh.tpl")
  vars = {
    aws_region             = data.aws_region.current.name
..
..
}