You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Description: Generate all identifiers needs to poulate the IaC (terraform and ansible). Identifiers are a required component as cloud resources often have strict usage conventions that need to be appied to dynamic user input.
9
-
functiongenerate_identifiers () {
10
-
# Generate TF_STATE_BUCKET ID if empty
11
-
if [ -z"${TF_STATE_BUCKET}" ];then
12
-
if [[ ${#GITHUB_IDENTIFIER}< 55 ]];then
13
-
TF_STATE_BUCKET="${GITHUB_IDENTIFIER}-tf-state"
14
-
else
15
-
TF_STATE_BUCKET="${GITHUB_IDENTIFIER}-tf"
16
-
fi
17
-
else
18
-
export TF_STATE_BUCKET=${TF_STATE_BUCKET}
19
-
fi
20
-
# Generate LB_LOGS_BUCKET ID
21
-
if [[ ${#GITHUB_IDENTIFIER}< 59 ]];then
22
-
export LB_LOGS_BUCKET="${GITHUB_IDENTIFIER}-logs"
23
-
else
24
-
export LB_LOGS_BUCKET="${GITHUB_IDENTIFIER}-lg"
25
-
fi
26
-
}
27
-
# Function: check_bucket_names
28
-
# Description: Runs a handful of RegEx to ensure strict usage requirements are followed.
29
-
functiongenerate_bucket_names() {
30
-
31
-
# check length of bucket name
32
-
if [[ ${#1}-lt 3 ||${#1}-gt 63 ]];then
33
-
echo"Bucket name must be between 3 and 63 characters long."
34
-
exit 1
35
-
fi
36
-
37
-
# check that bucket name consists only of lowercase letters, numbers, dots (.), and hyphens (-)
38
-
if [[ !$1=~ ^[a-z0-9.-]+$ ]];then
39
-
echo"Bucket name can only consist of lowercase letters, numbers, dots (.), and hyphens (-)."
40
-
exit 1
41
-
fi
42
-
43
-
# check that bucket name begins and ends with a letter or number
44
-
if [[ !$1=~ ^[a-zA-Z0-9] ]];then
45
-
echo"Bucket name must begin with a letter or number."
46
-
exit 1
47
-
fi
48
-
if [[ !$1=~ [a-zA-Z0-9]$ ]];then
49
-
echo"Bucket name must end with a letter or number."
50
-
exit 1
51
-
fi
52
-
53
-
# check that bucket name does not contain two adjacent periods
54
-
if [[ $1=~\.\. ]];then
55
-
echo"Bucket name cannot contain two adjacent periods."
56
-
exit 1
57
-
fi
58
-
59
-
# check that bucket name is not formatted as an IP address
60
-
if [[ $1=~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]];then
61
-
echo"Bucket name cannot be formatted as an IP address."
62
-
exit 1
63
-
fi
64
-
65
-
# check that bucket name does not start with the prefix xn--
66
-
if [[ $1=~ ^xn-- ]];then
67
-
echo"Bucket name cannot start with the prefix xn--."
68
-
exit 1
69
-
fi
70
-
71
-
# check that bucket name does not end with the suffix -s3alias
72
-
if [[ $1=~-s3alias$ ]];then
73
-
echo"Bucket name cannot end with the suffix -s3alias."
74
-
exit 1
75
-
fi
76
-
}
7
+
case$1in
8
+
tf)
9
+
# Generate TF_STATE_BUCKET ID if empty
10
+
if [ -z"${TF_STATE_BUCKET}" ];then
11
+
# Add trailing id depending on name length - See AWS S3 bucket naming rules
12
+
if [[ ${#GITHUB_IDENTIFIER}< 55 ]];then
13
+
TF_STATE_BUCKET="${GITHUB_IDENTIFIER}-tf-state"
14
+
else
15
+
TF_STATE_BUCKET="${GITHUB_IDENTIFIER}-tf"
16
+
fi
17
+
fi
18
+
echo"$TF_STATE_BUCKET"
77
19
78
-
generate_identifiers
79
-
80
-
generate_bucket_names $TF_STATE_BUCKET
81
-
generate_bucket_names $LB_LOGS_BUCKET
82
-
83
-
export TF_STATE_BUCKET=${TF_STATE_BUCKET}
84
-
export LB_LOGS_BUCKET=${LB_LOGS_BUCKET}
20
+
;;
21
+
lb)
22
+
# Generate LB_LOGS_BUCKET ID
23
+
# Add trailing id depending on name length - See AWS S3 bucket naming rules
0 commit comments