From 8c5e72de3e5d4aca35f5205ea174ce8917e3417a Mon Sep 17 00:00:00 2001 From: Amir Ben Nun <34831306+amirbenun@users.noreply.github.com> Date: Wed, 9 Aug 2023 13:10:28 +0300 Subject: [PATCH] CloudFormation templates have identical signature (#1211) --- .github/workflows/publish-cloudformation.yml | 9 +++++--- scripts/publish_cft.sh | 24 ++++++++------------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.github/workflows/publish-cloudformation.yml b/.github/workflows/publish-cloudformation.yml index 48eac75383..664e7e7df1 100644 --- a/.github/workflows/publish-cloudformation.yml +++ b/.github/workflows/publish-cloudformation.yml @@ -25,11 +25,14 @@ jobs: - name: Upload to S3 if elastic-agent CloudFormation template has changed run: | - CNVM_FILENAME="cloudformation-cnvm-VERSION-DATE.yml" + DATE=$(date +"%Y-%m-%d-%H-%M-%S") + VERSION=$(grep defaultBeatVersion version/version.go | cut -f2 -d "\"") + + CNVM_FILENAME="cloudformation-cnvm-$VERSION-$DATE.yml" ./scripts/publish_cft.sh deploy/cloudformation/elastic-agent-ec2-cnvm.yml $CNVM_FILENAME - CSPM_FILENAME="cloudformation-cspm-single-account-VERSION-DATE.yml" + CSPM_FILENAME="cloudformation-cspm-single-account-$VERSION-$DATE.yml" ./scripts/publish_cft.sh deploy/cloudformation/elastic-agent-ec2-cspm.yml $CSPM_FILENAME - CSPM_ORG_FILENAME="cloudformation-cspm-organization-account-VERSION-DATE.yml" + CSPM_ORG_FILENAME="cloudformation-cspm-organization-account-$VERSION-$DATE.yml" ./scripts/publish_cft.sh deploy/cloudformation/elastic-agent-ec2-cspm-organization.yml $CSPM_ORG_FILENAME diff --git a/scripts/publish_cft.sh b/scripts/publish_cft.sh index 190174347e..7ee1734f6c 100755 --- a/scripts/publish_cft.sh +++ b/scripts/publish_cft.sh @@ -2,26 +2,20 @@ function usage() { cat < -Create a concrete remote file name from the pattern. -Replace CFT_VERSION with the remote file name. -Upload the local file to the remote file name. +Usage: $0 +Replace the CFT_VERSION placeholder in the local-file. +Upload the local-file to S3 with the remote-file name. EOF } LOCAL_FILE=$1 -FILEPATTERN=$2 +REMOTE_FILE=$2 : "${LOCAL_FILE:?$(echo "Missing local file" && usage && exit 1)}" -: "${FILEPATTERN:?$(echo "Missing file pattern" && usage && exit 1)}" +: "${REMOTE_FILE:?$(echo "Missing remote file" && usage && exit 1)}" -VERSION=$(grep defaultBeatVersion version/version.go | cut -f2 -d "\"") -DATE=$(date +"%Y-%m-%d-%H-%M-%S") -FILEPATTERN=${FILEPATTERN/VERSION/$VERSION} -FILEPATTERN=${FILEPATTERN/DATE/$DATE} +sed --in-place'' s/CFT_VERSION/$REMOTE_FILE/g $LOCAL_FILE -sed --in-place'' s/CFT_VERSION/$FILEPATTERN/g $LOCAL_FILE - -REMOTE_FILE="s3://elastic-cspm-cft/$FILEPATTERN" -echo "Uploading $LOCAL_FILE to $REMOTE_FILE" -aws s3 cp $LOCAL_FILE $REMOTE_FILE \ No newline at end of file +S3_FILE="s3://elastic-cspm-cft/$REMOTE_FILE" +echo "Uploading $LOCAL_FILE to $S3_FILE" +aws s3 cp $LOCAL_FILE $S3_FILE \ No newline at end of file