Skip to content

Commit

Permalink
adding versioning to organizations template
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanbrie committed Nov 11, 2024
1 parent d641470 commit 1f67e99
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions aws_organizations/main_organizations.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# version: <VERSION_PLACEHOLDER>
AWSTemplateFormatVersion: 2010-09-09
Description: Configures the Datadog AWS Integration
Parameters:
Expand Down
25 changes: 21 additions & 4 deletions aws_organizations/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ else
BUCKET=$1
fi

# Read the version
VERSION=$(head -n 1 version.txt)

# Confirm the bucket for the current release doesn't already exist so we don't overwrite it
set +e
EXIT_CODE=0
response=$(aws s3api head-object \
--bucket "${BUCKET}" \
--key "aws/${VERSION}/main_organizations.yaml" > /dev/null 2>&1)

if [[ ${?} -eq 0 ]]; then
echo "S3 bucket path ${BUCKET}/aws/${VERSION} already exists. Please up the version."
exit 1
fi
set -e

# Upload templates to a private bucket -- useful for testing
if [[ $# -eq 2 ]] && [[ $2 = "--private" ]]; then
PRIVATE_TEMPLATE=true
Expand All @@ -22,7 +38,7 @@ fi
# Confirm to proceed
for i in *.yaml; do
[ -f "$i" ] || break
echo "About to upload $i to s3://${BUCKET}/aws/$i"
echo "About to upload $i to s3://${BUCKET}/aws/${VERSION}/$i"
done
read -p "Continue (y/n)?" CONT
if [ "$CONT" != "y" ]; then
Expand All @@ -33,16 +49,17 @@ fi
# Update bucket placeholder
cp main_organizations.yaml main_organizations.yaml.bak
perl -pi -e "s/<BUCKET_PLACEHOLDER>/${BUCKET}/g" main_organizations.yaml
perl -pi -e "s/<VERSION_PLACEHOLDER>/${VERSION}/g" main_organizations.yaml
trap 'mv main_organizations.yaml.bak main_organizations.yaml' EXIT

# Upload
if [ "$PRIVATE_TEMPLATE" = true ] ; then
aws s3 cp . s3://${BUCKET}/aws --recursive --exclude "*" --include "*.yaml"
aws s3 cp . s3://${BUCKET}/aws/${VERSION} --recursive --exclude "*" --include "*.yaml"
else
aws s3 cp . s3://${BUCKET}/aws --recursive --exclude "*" --include "*.yaml" \
aws s3 cp . s3://${BUCKET}/aws/${VERSION} --recursive --exclude "*" --include "*.yaml" \
--grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
fi
echo "Done uploading the template. Navigate to https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacksets/create and use the template URL below."
echo "https://${BUCKET}.s3.amazonaws.com/aws/main_organizations.yaml"
echo "https://${BUCKET}.s3.amazonaws.com/aws/${VERSION}/main_organizations.yaml"

echo "Done!"
1 change: 1 addition & 0 deletions aws_organizations/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v2.0.0

0 comments on commit 1f67e99

Please sign in to comment.