A terraform example using .tf.makefile
This is a basic example for using .tf.makefile in a flat single layer structured terraform project.
Copy/Symlink/Submodule .tf.makefile's .tf.makefile to this project.
make tf:make
This will copy over the .tfvars
templates for configuration.
Generating the SSH keys
make ssh-keygen
These keys will be registed with our droplet and used for SSH access.
Deploy
Once that is configured you can go ahead and deploy. Digital Ocean is our provider here, so you will need an account from them.
make apply
or
make tf:apply
or
make terraform-example
Note, make apply
and make terraform-example
will throw a make
error,
more on that here.
If everything is configured and deploys correctly you can visit the IP and you should see something like,
Hello World!
I was created through a terraform deployment!
SSH
To SSH into your droplet
make ssh
You'll be prompted for a login
, use core
since we are using Coreos as our
OS.
Un-deploying
Aka. destroy.
make destroy
or
make tf:destroy
You will be prompted to confirm, this is a dangerous process, so .tf.makefile has a confirmation sequence, as well as confirmation from terraform itself.
You will notice that upon initially running make apply
you will get a make
error. This was deliberate to illustrate a particular use case.
Many terraforms are written for 3rd parties and the final checkout destination
may not always be the exact same name as the repo itself, case in point. I
built this original in a folder called terraform-nginx-example
.
There are two options,
-
Rewrite the targets
make tf:rename
This will rewrite the generated targets to match the new checkout folder name.
-
Use the standard
tf:...
prefixed commands, ie.make tf:apply
For a multiple layer (service) terraform project using .tf.makefile
, can be
found here.