Skip to content

Commit

Permalink
CloudFormation: Upload to link parametrized only by version (#1427)
Browse files Browse the repository at this point in the history
  • Loading branch information
orestisfl authored Oct 19, 2023
1 parent 9fff93d commit 2c109e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/publish-cloudformation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,4 @@ jobs:
aws-region: us-east-2

- name: Upload to S3 if elastic-agent CloudFormation template has changed
run: |
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"
./scripts/publish_cft.sh deploy/cloudformation/elastic-agent-ec2-cspm.yml $CSPM_FILENAME
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
run: scripts/publish_ft.sh
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ repos:
- id: shfmt
args: ["-i", "4"]
- id: shellcheck
files: deploy/azure/.*sh
files: (deploy/azure/.*sh|scripts/publish_cft.sh)

- repo: local
hooks:
Expand Down
29 changes: 13 additions & 16 deletions scripts/publish_cft.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#!/bin/bash
set -euo pipefail

function usage() {
cat <<EOF
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.
function upload_file() {
local local_file=${1:?Missing local file name}
local remote_file=${2:?Missing remote file name}

EOF
}

LOCAL_FILE=$1
REMOTE_FILE=$2
: "${LOCAL_FILE:?$(echo "Missing local file" && usage && exit 1)}"
: "${REMOTE_FILE:?$(echo "Missing remote file" && usage && exit 1)}"
sed --in-place'' "s/CFT_VERSION/$remote_file/g" "$local_file"

sed --in-place'' s/CFT_VERSION/$REMOTE_FILE/g $LOCAL_FILE
local s3_file="s3://elastic-cspm-cft/$remote_file"
echo "Uploading $local_file to $s3_file"
aws s3 cp "$local_file" "$s3_file"
}

S3_FILE="s3://elastic-cspm-cft/$REMOTE_FILE"
echo "Uploading $LOCAL_FILE to $S3_FILE"
aws s3 cp $LOCAL_FILE $S3_FILE
version=$(grep defaultBeatVersion version/version.go | cut -f2 -d "\"")
upload_file deploy/cloudformation/elastic-agent-ec2-cnvm.yml "cloudformation-cnvm-$version.yml"
upload_file deploy/cloudformation/elastic-agent-ec2-cspm.yml "cloudformation-cspm-single-account-$version.yml"
upload_file deploy/cloudformation/elastic-agent-ec2-cspm-organization.yml "cloudformation-cspm-organization-account-$version.yml"

0 comments on commit 2c109e6

Please sign in to comment.