-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathcfn-test-create-inputs.sh
executable file
·58 lines (48 loc) · 1.84 KB
/
cfn-test-create-inputs.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
#!/usr/bin/env bash
# cfn-test-create-inputs.sh
#
# This tool generates json files in the inputs/ for `cfn test`.
#
set -o errexit
set -o nounset
set -o pipefail
function usage {
echo "Creates project and tenant for the query limit test"
}
if [ "$#" -ne 2 ]; then usage; fi
if [[ "$*" == help ]]; then usage; fi
rm -rf inputs
mkdir inputs
#set profile
profile="default"
if [ ${MONGODB_ATLAS_PROFILE+x} ]; then
echo "profile set to ${MONGODB_ATLAS_PROFILE}"
profile=${MONGODB_ATLAS_PROFILE}
fi
projectName="${1}"
projectId=$(atlas projects list --output json | jq --arg NAME "${projectName}" -r '.results[] | select(.name==$NAME) | .id')
if [ -z "$projectId" ]; then
projectId=$(atlas projects create "${projectName}" --output=json | jq -r '.id')
echo -e "Created project \"${projectName}\" with id: ${projectId}\n"
else
echo -e "FOUND project \"${projectName}\" with id: ${projectId}\n"
fi
#LimitName is an enum from this list. i.e. "bytesProcessed.query" "bytesProcessed.daily" "bytesProcessed.weekly" "bytesProcessed.monthly"
#create federated tenant
tenantName="${projectName}-tenant"
if atlas dataFederation describe "${tenantName}" --projectId "${projectId}"; then
echo "tenant already exists with name ${tenantName}"
else
atlas dataFederation create "${tenantName}" --projectId "${projectId}"
echo "tenant created with name ${tenantName}"
fi
jq --arg projectId "${projectId}" \
--arg tenantName "${tenantName}" \
--arg profile "$profile" \
'.Profile?|=$profile |.ProjectId?|=$projectId | .TenantName?|=$tenantName' \
"$(dirname "$0")/inputs_1_create.template.json" >"inputs/inputs_1_create.json"
jq --arg projectId "${projectId}" \
--arg tenantName "${tenantName}" \
--arg profile "$profile" \
'.Profile?|=$profile |.ProjectId?|=$projectId | .TenantName?|=$tenantName' \
"$(dirname "$0")/inputs_1_update.template.json" >"inputs/inputs_1_update.json"