Skip to content

Commit

Permalink
CloudFormation templates have identical signature (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
amirbenun authored Aug 9, 2023
1 parent 0243e06 commit 8c5e72d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/publish-cloudformation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 9 additions & 15 deletions scripts/publish_cft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@

function usage() {
cat <<EOF
Usage: $0 <local-file> <file-pattern>
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 <local-file> <remote-file>
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
S3_FILE="s3://elastic-cspm-cft/$REMOTE_FILE"
echo "Uploading $LOCAL_FILE to $S3_FILE"
aws s3 cp $LOCAL_FILE $S3_FILE

0 comments on commit 8c5e72d

Please sign in to comment.