-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.sh
executable file
·102 lines (84 loc) · 3.41 KB
/
configure.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
set -e
touch service.config
source service.config
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-u|--user)
GITHUB_USER="$2"
shift # past argument
shift # past value
;;
-r|--repo)
GITHUB_REPO="$2"
shift # past argument
shift # past value
;;
-b|--branch)
GITHUB_BRANCH="$2"
shift # past argument
shift # past value
;;
-e|--email)
PRIMARY_EMAIL_ADDRESS="$2"
shift # past argument
shift # past value
;;
-p|--password)
DB_ROOT_PASSWORD="$2"
shift # past argument
shift # past value
;;
-t|--github-token)
GITHUB_TOKEN="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
addOrUpdateParameter() {
echo "Adding paremeter \"$1\" as \"$3\"..."
aws ssm put-parameter \
--name $1 \
--description "$2" \
--type String \
--overwrite \
--value $3
}
createSecretIfNotExists() {
echo "Checking if secret \"$1\" already exists..."
count=$(aws secretsmanager list-secrets | jq --arg name $1 -c '[.SecretList[] | select(.Name == $name)] | length')
if [ "$count" -lt 1 ]
then
echo "Secret does not exist..."
echo "Creating secret \"$1\" to be used in the infra..."
aws secretsmanager create-secret \
--name $1 \
--description "$2" \
--secret-string $3
else
echo "Secret already exists. Not creating a new replica..."
fi
}
importSecretToCodeBuild() {
credentialsArn=$(aws codebuild import-source-credentials --server-type GITHUB --auth-type PERSONAL_ACCESS_TOKEN --token $1 | jq --raw-output .arn)
echo "$credentialsArn"
}
echo "Importing GitHub oAuth token into CodeBuild..."
credentialsArn=$(importSecretToCodeBuild "$GITHUB_TOKEN")
echo "Adding parameters to AWS SSM..."
addOrUpdateParameter /{TEMPLATE_SERVICE_HYPHEN_NAME}/code-build/github/access-token/arn "ARN of the GitHub access token imported to CodeBuild" "$credentialsArn"
addOrUpdateParameter /{TEMPLATE_SERVICE_HYPHEN_NAME}/code-pipeline/notifications/email/primary-email "Email address for primary recipient of Pipeline notifications" "$PRIMARY_EMAIL_ADDRESS"
addOrUpdateParameter /{TEMPLATE_SERVICE_HYPHEN_NAME}/code-pipeline/sources/github/user "Github user to be used for building the code in the pipeline" "$GITHUB_USER"
addOrUpdateParameter /{TEMPLATE_SERVICE_HYPHEN_NAME}/code-pipeline/sources/github/repo "Github repository name that contains the build sources for the pipeline" "$GITHUB_REPO"
addOrUpdateParameter /{TEMPLATE_SERVICE_HYPHEN_NAME}/code-pipeline/sources/github/branch "Github branch name that contains the build sources for the pipeline" "$GITHUB_BRANCH"
#addOrUpdateParameter /{TEMPLATE_SERVICE_HYPHEN_NAME}/code-pipeline/notifications/slack/workspace-id "Slack workspace ID to receive Pipeline state change notifications" "$SLACK_WORKSPACE_ID"
#addOrUpdateParameter /{TEMPLATE_SERVICE_HYPHEN_NAME}/code-pipeline/notifications/slack/channel-id "Slack channel ID to receive Pipeline state change notifications" "$SLACK_CHANNEL_ID"
createSecretIfNotExists /{TEMPLATE_SERVICE_HYPHEN_NAME}/database/cluster/root/password "Root password for the RDS cluster" "$DB_ROOT_PASSWORD"