Search code examples
continuous-deploymentamazon-aminetflixasgard

Automate Asgard next group creation


Is there a way to automate creating the next asgard auto scaling group? I have the AMI image ID I want to deploy with. I poked around their API and it doesn't seem clear to me how this can be done. Does anyone have any suggestions?


Solution

  • For anyone coming here I've solved this using some simple shell scripts. You can wrap this up in any REST api or language you want, but the gist is

    • Query the prepare endpoint for your cluster and include the environment. This gives you the current launch configuration + the list of all AMI's for that cluster
    • Get the last ami in the list since its sorted ascending (last ami is the most recent)
    • Set the ami field of the prepare json you pulled using the new ami
    • Post the new json back to the start endpoint

    function asgard(){
      verb=$1
      url="https://my.asgard.com/us-east-1/$2"
      shift
      http ${VERB} --verify=no "$url" -b
    }
    
    function next-ami(){
      cluster=$1
    
      prepare-ami $cluster true | \
        jq ".environment.images | reverse | .[0]"
    }
    
    function prepare-ami(){
      cluster=$1
    
      includeEnv=$2
    
      asgard GET "deployment/prepare/${cluster}?deploymentTemplateName=CreateAndCleanUpPreviousAsg&includeEnvironment=${includeEnv}"
    }
    
    function get-next-ami(){
      cluster=$1
    
      next=`next-ami ${cluster} | jq ".id"`
    
      prepare-ami ${cluster} "false" | jq ".lcOptions.imageId |= ${next}"
    }
    
    function start-deployment(){
      cluster=$1
      payload=$2
    
      echo $payload | asgard POST "deployment/start/${cluster}"
    }
    

    Source post: http://onoffswitch.net/scripting-deployment-clusters-asgard/