Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying update to generators #30

Merged
merged 3 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions operations/_scripts/deploy/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -x
echo "In deploy.sh"
GITHUB_REPO_NAME=$(echo $GITHUB_REPOSITORY | sed 's/^.*\///')

# Generate the tf state bucket
export TF_STATE_BUCKET="$(/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_tf_state_bucket.sh | xargs)"
# Generate buckets identifiers
/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_buckets_identifiers.sh

# Generate subdomain
/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_subdomain.sh
Expand Down
80 changes: 80 additions & 0 deletions operations/_scripts/generate/generate_buckets_identifiers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

set -e

GITHUB_IDENTIFIER="$(echo $($GITHUB_ACTION_PATH/operations/_scripts/generate/generate_identifier.sh) | tr '[:upper:]' '[:lower:]')"

function generateIdentifiers () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for the other function, naming and description would be nice to haves.

And quickly looking at it, I didn't understand what kind of Identifiers the function generates.
generate_bucket_names() or generate_bucket_identifiers perhaps would be more clear?

# Generate TF_STATE_BUCKET ID if empty
if [ -z "${TF_STATE_BUCKET}" ]; then
if [[ ${#GITHUB_IDENTIFIER} < 55 ]]; then
TF_STATE_BUCKET="${GITHUB_IDENTIFIER}-tf-state"
else
TF_STATE_BUCKET="${GITHUB_IDENTIFIER}-tf"
fi
else
export TF_STATE_BUCKET=${TF_STATE_BUCKET}
fi
# Generate LB_LOGS_BUCKET ID
if [[ ${#GITHUB_IDENTIFIER} < 59 ]]; then
export LB_LOGS_BUCKET="${GITHUB_IDENTIFIER}-logs"
else
export LB_LOGS_BUCKET="${GITHUB_IDENTIFIER}-lg"
fi
}

function checkBucket() {
Copy link
Member

@arm4b arm4b Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to have a function here 👍

let's also follow the more common bash shellcheck naming standards (similar to python, lowercase with underscore separators):

Suggested change
function checkBucket() {
# a brief function description
function check_bucket_name() {

Could we also include a line comment for this function describing briefly what it does?

# check length of bucket name
if [[ ${#1} -lt 3 || ${#1} -gt 63 ]]; then
echo "Bucket name must be between 3 and 63 characters long."
exit 1
fi

# check that bucket name consists only of lowercase letters, numbers, dots (.), and hyphens (-)
if [[ ! $1 =~ ^[a-z0-9.-]+$ ]]; then
echo "Bucket name can only consist of lowercase letters, numbers, dots (.), and hyphens (-)."
exit 1
fi

# check that bucket name begins and ends with a letter or number
if [[ ! $1 =~ ^[a-zA-Z0-9] ]]; then
echo "Bucket name must begin with a letter or number."
exit 1
fi
if [[ ! $1 =~ [a-zA-Z0-9]$ ]]; then
echo "Bucket name must end with a letter or number."
exit 1
fi

# check that bucket name does not contain two adjacent periods
if [[ $1 =~ \.\. ]]; then
echo "Bucket name cannot contain two adjacent periods."
exit 1
fi

# check that bucket name is not formatted as an IP address
if [[ $1 =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo "Bucket name cannot be formatted as an IP address."
exit 1
fi

# check that bucket name does not start with the prefix xn--
if [[ $1 =~ ^xn-- ]]; then
echo "Bucket name cannot start with the prefix xn--."
exit 1
fi

# check that bucket name does not end with the suffix -s3alias
if [[ $1 =~ -s3alias$ ]]; then
echo "Bucket name cannot end with the suffix -s3alias."
exit 1
fi
}

generateIdentifiers

checkBucket $TF_STATE_BUCKET
checkBucket $LB_LOGS_BUCKET

export TF_STATE_BUCKET=${TF_STATE_BUCKET}
export LB_LOGS_BUCKET=${LB_LOGS_BUCKET}
16 changes: 0 additions & 16 deletions operations/_scripts/generate/generate_tf_state_bucket.sh

This file was deleted.

2 changes: 1 addition & 1 deletion operations/_scripts/generate/generate_tf_vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ app_branch_name = \"${GITHUB_BRANCH_NAME}\"
app_install_root = \"/home/ubuntu\"

# Logs
lb_access_bucket_name = \"${TF_STATE_BUCKET}-logs\"
lb_access_bucket_name = \"${LB_LOGS_BUCKET}\"

# Security Group names
security_group_name = \"${GITHUB_IDENTIFIER}\"
Expand Down