Skip to content

Commit 12bffc8

Browse files
committed
add script to setup ssm
1 parent 328eb74 commit 12bffc8

File tree

1 file changed

+67
-0
lines changed
  • examples/external-managed-ssm-secrets

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
# NOTE: this script is only for demonstration purposes
4+
5+
# Script to create SSM parameters outside of Terraform
6+
# and set them as environment variables for Terraform
7+
8+
APP_ID=
9+
APP_PRIVATE_KEY_FILE=
10+
APP_WEBHOOK_SECRET=
11+
APP_PRIVATE_KEY=$(base64 -i $APP_PRIVATE_KEY_FILE)
12+
SSM_PATH="/github-runners/example/app"
13+
14+
if [ -z "$APP_ID" ]; then
15+
echo "APP_ID is not set"
16+
exit 1
17+
fi
18+
19+
if [ -z "$APP_WEBHOOK_SECRET" ]; then
20+
echo "APP_WEBHOOK_SECRET is not set"
21+
exit 1
22+
fi
23+
24+
if [ -z "$APP_PRIVATE_KEY_FILE" ]; then
25+
echo "APP_PRIVATE_KEY_FILE is not set"
26+
exit 1
27+
fi
28+
29+
30+
export AWS_PAGER=""
31+
export AWS_REGION=eu-central-1
32+
export TF_VAR_aws_region=$AWS_REGION
33+
34+
35+
# GitHub App ID
36+
aws ssm put-parameter \
37+
--name "${SSM_PATH}/github_app_id" \
38+
--overwrite \
39+
--value "${APP_ID}" \
40+
--type "SecureString"
41+
42+
# GitHub App Private Key
43+
aws ssm put-parameter \
44+
--name "${SSM_PATH}/github_app_key_base64" \
45+
--overwrite \
46+
--value "${APP_PRIVATE_KEY}" \
47+
--type "SecureString"
48+
49+
# GitHub App Installation ID
50+
aws ssm put-parameter \
51+
--name "${SSM_PATH}/github_app_webhook_secret" \
52+
--overwrite \
53+
--value "${APP_WEBHOOK_SECRET}" \
54+
--type "SecureString"
55+
56+
57+
github_app_id_ssm=$(aws ssm get-parameter --name "${SSM_PATH}/github_app_id" --query 'Parameter.{arn:ARN,name:Name}' --output json)
58+
github_app_key_base64_ssm=$(aws ssm get-parameter --name "${SSM_PATH}/github_app_key_base64" --query 'Parameter.{arn:ARN,name:Name}' --output json)
59+
github_app_webhook_secret_ssm=$(aws ssm get-parameter --name "${SSM_PATH}/github_app_webhook_secret" --query 'Parameter.{arn:ARN,name:Name}' --output json)
60+
61+
export TF_VAR_github_app_ssm_parameters="{
62+
"id": `echo $github_app_id_ssm`,
63+
"key_base64": `echo $github_app_key_base64_ssm`,
64+
"webhook_secret": `echo $github_app_webhook_secret_ssm`
65+
}"
66+
67+
export TF_VAR_environment=external-ssm

0 commit comments

Comments
 (0)