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.com
andyour-domain.com
AWS S3 buckets configured for static website hosting - redirect requests to the
www.your-domain.com
bucket toyour-domain.com
- deploy the
index.html
anderror.html
objects to theyour-domain.com
bucket - establish an AWS Route53
your-domain.com
DNS zone - establish a Route53 A record set pointing
your-domain.com
to theyour-domain.com
S3 bucket
TravisCI:
- Uses Node.js to compile
src
to a static website. - If the branch is
master
, installsterraform
- If the branch is
master
, executesdeploy.sh
to deploy the static website to AWS S3 website fronted bymikeball.me
via: terraform plan
terraform apply
- commit
terraform.tfstate
back 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
travis
CLI if you don't already have it:
$ gem install travis
- Use the
travis
CLI 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 currentsecure
value:
...
env:
secure: "ENCRYPTED STRING HERE"
...
-
Replace
GH_USER_NAME
,GH_USER_EMAIL
, andGH_REPO
in the.travis.yml
with your details. -
Replace the
domain
var interraform/main.tf
with your domain name. -
Remove my
tfstate
files 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.com
to those dynamically assigned to your A record by AWS. For example, my A record uses these DNS servers.