set -e

# get the resource group from the first argument, default to working directorn basename
resourceGroupName=${1:-$(basename $(pwd))}

# get the stack from the second argument, or invoke 'pulumi stack select' to get it
stackName=$2

(
set -e
cd "infrastructure/resourceGroups/$resourceGroupName"

pulumi stack select $stackName

# Load Pulumi output
pulumiOutput=$(pulumi stack output --json)

# Extract necessary values from Pulumi output
bucketName=$(echo $pulumiOutput | jq -r '.bucketName')

aws s3 sync ../../../<%=outputDir %>/ s3://$bucketName
)
