Skip to content

A "Hello World" in Golang deployed to AWS ECS (Docker) using Terraform

License

Notifications You must be signed in to change notification settings

grisha/hello-go-ecs-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A "Hello World" in Golang deployed to AWS ECS (Docker) using Terraform

Big thanks to Tadas Vilkeliskis for Bootstrapping Docker Infrastructure With Terraform write up.

How to use this

  1. Make sure you have the following installed and/or created/configured/working:

  2. Allow Terraform to use your credentials in ~/.aws/config by symlinking it to credentials:

ln -s ~/.aws/confic ~/.aws/credentials
  1. Install this example:
go get github.com/grisha/hello-go-ecs-terraform
  1. Change into the project directory:
cd $GOPATH/src/grisha/hello-go-ecs-terraform
  1. Edit tf/variables.tf file so that it has the following:
variable "key_name" { default = "YOUR-AWS-KEY-PAIR-NAME" }
variable "dockerimg" { default = "YOUR-DOCKER-HUB-USERNAME/IMAGE-NAME" }
  1. The docker hub username must be correct (though the actual image doesn not need to exist, it will be created for you), and you should be authenticated with:
docker login
  1. Check that terraform works with:
make plan
  1. If the above produces no errors, give it a try. Note that due to timing of AWS object creations sometimes you have to run this twice, it succeeds on the second try:
make apply
  1. You should now see a load balancer in the AWS console, where it should list its DNS name. You should also see an ECS service and its tasks and associated EC2 instances. The whole thing will take a few minutes to create.

  2. Once it's all created, you should be able to hit the ELB DNS name with your browser and see the app in action.

  3. In this set up Terraform uses the .git/logs/HEAD file as the indicator that code has changed, but this file only changes when you commit something (The idea being that your CI, e.g. Jenkins would actually perform the make apply). If you want to force deploy the code that you currently have, you can do this:

    make force_deploy

    Once you do this, you should see the ECS gradually replace your tasks with the new version.

  4. When finished, you can destroy everything with:

make destroy

About

A "Hello World" in Golang deployed to AWS ECS (Docker) using Terraform

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages