Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to trigger a CodeDeploy deployment with Terraform after changes in configuration?

I am currently migrating my config management on AWS to Terraform to make it more pluggable. What I like is the possibility to manage rolling updates to an Autoscaling Group where Terraform waits until the new instances are in service before it destroys the old infrastructure. This works fine with the "bare" infrastructure. But I ran into a problem when update the actual app instances. The code is deployed via AWS CodeDeploy and I can tell Terraform to use the generated name of the new Autoscaling Group as deployment target but it doesn't deploy the code to the new instances on startup. When I manually select "deploy changes to the deployment group" the deployment starts successfully. Any ideas how to automate this step?

like image 772
kgorskowski Avatar asked Mar 10 '17 16:03

kgorskowski


People also ask

Can we rollback CodeDeploy deployment?

CodeDeploy rolls back deployments by redeploying a previously deployed revision of an application as a new deployment. These rolled-back deployments are technically new deployments, with new deployment IDs, rather than restored versions of a previous deployment. Deployments can be rolled back automatically or manually.

Can Terraform be used for code deployment?

Seriously, Terraform is not application deployment software.


1 Answers

https://www.terraform.io/docs/provisioners/local-exec.html might be able to do this. Couple assumptions

  • You've got something like aws-cli installed where you're running terraform.
  • You've got your dependencies setup so that your CodeDeploy step would be one of the last things executed. If that's not the case you can play with depends_on https://www.terraform.io/intro/getting-started/dependencies.html#implicit-and-explicit-dependencies

Once your code has been posted, you would just add a

resource "something" "some_name" {
    # Whatever config you've setup for the resource
    provisioner "local-exec" {
        command = "aws deploy create-deployment"
  }
}

FYI the aws deploy create-deployment command is not complete, so you'll have to play with that in your environment till you've got the values needed to trigger the rollout but hopefully this is enough to get you started.

like image 182
Paul Avatar answered Oct 02 '22 10:10

Paul