A reference repo demonstrating how to continuously deploy via terraform from TravisCI.
Via TravisCI (or locally), use Node.js to compile a static website; use Terraform to:
- create
www.your-domain.comandyour-domain.comAWS S3 buckets configured for static website hosting - redirect requests to the
www.your-domain.combucket toyour-domain.com - deploy the
index.htmlanderror.htmlobjects to theyour-domain.combucket - establish an AWS Route53
your-domain.comDNS zone - establish a Route53 A record set pointing
your-domain.comto theyour-domain.comS3 bucket
TravisCI:
- Uses Node.js to compile
srcto a static website. - If the branch is
master, installsterraform - If the branch is
master, executesdeploy.shto deploy the static website to AWS S3 website fronted bymikeball.mevia: terraform planterraform apply- commit
terraform.tfstateback to this repo with a[ci skip]commit message such that a TravisCI build is not triggered.
To deploy your own:
-
Fork this repo.
-
Visit travis-ci.org; activate CI for your fork of this repo.
-
Install the
travisCLI if you don't already have it:
$ gem install travis
- Use the
travisCLI to encrypt your AWS credentials and your Github access token in environment variables:
$ travis encrypt AWS_ACCESS_KEY_ID=123 AWS_SECRET_ACCESS_KEY=456 GH_TOKEN=123
- Add the encrypted credentials string to your
.travis.yml, replacing the currentsecurevalue:
...
env:
secure: "ENCRYPTED STRING HERE"
...
-
Replace
GH_USER_NAME,GH_USER_EMAIL, andGH_REPOin the.travis.ymlwith your details. -
Replace the
domainvar interraform/main.tfwith your domain name. -
Remove my
tfstatefiles to start fresh:
$ git rm terraform/terraform.tfstate*
$ git commit -m 'removed mdb tfstate'
- Push & deploy:
$ git push origin master
- Note that you may need to point the DNS servers associated with
your-domain.comto those dynamically assigned to your A record by AWS. For example, my A record uses these DNS servers.