Skip to content

Instantly share code, notes, and snippets.

@desterhuizen
Last active May 20, 2021 16:24
Show Gist options
  • Save desterhuizen/e77962b7928f584f4795becb37f8c4d4 to your computer and use it in GitHub Desktop.
Save desterhuizen/e77962b7928f584f4795becb37f8c4d4 to your computer and use it in GitHub Desktop.

MongoDB Atlas API Automation

Generate a deployment template

echo '{
   "name" : "<name>",
   "diskSizeGB" : "<size>",
   "providerSettings" : {
       "providerName" : "AWS",
       "diskIOPS" : 100,
       "encryptEBSVolume" : false,
       "instanceSizeName" : "<instance size>",
       "regionName" : "<region>"
   },
   "replicationFactor" : 3,
   "backupEnabled" : false,
   "autoScaling":{
       "diskGBEnabled":true
   },
   "mongoDBMajorVersion": "<version>",
   "mongoDBVersion": "<version>"
}' > ClusterTemplate.json

Update the template to contain requirements

cat ClusterTemplate.json | 
jq '. 
| .name = "MongoDB Live Cluster" 
| .providerSettings.instanceSizeName = "M30" 
| .providerSettings.regionName = "EU_WEST_1" 
| .diskSizeGB = 50 
| .mongoDBVersion = "4.0.14" 
| .mongoDBMajorVersion = "4.0"
' > BasicCluster.json

Send request to MongoDB Atlas API

export GROUPID="<Atlas Group ID>"
export USER="<Atlas API ID>"
export APIKEY="<Atlas API KEY>"

curl -X POST -u "$USER:$APIKEY" --digest -H "Content-Type: application/json" 
"https://cloud.mongodb.com/api/atlas/v1.0/groups/$GROUPID/clusters" -d @./BasicCluster.json -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment