Skip to content

A demonstration environment to show how Git and Terraform can combine.

Notifications You must be signed in to change notification settings

robertdebock/git-terraform-demo

Repository files navigation

Git Terraform demo

A demonstration environment to show how Git and Terraform can combine.

Overview

This is the infrastructure that's being built by this code:

+--- ssh_key: terraform-demo ---+
| ~/.ssh/id_rsa                 |
+-------------------------------+
                 ^
                 |
+--- droplet: terraform-example ---+
| size:                            |
|   - small (1gb)                  |
|   - medium (2gb)                 |
|   - large (4gb)                  |
+----------------------------------+
                 |
                 V
+---  template_file: cloud-init.yml ---+
| packages:                            |
|   - httpd                            |
| # And a few other tasks.             |
+--------------------------------------+

Workflow

  1. Change the code.
  2. Add the changes to git. (git add . ; git commit -m "Description of changes" ; git push)
  3. Check the plan.
  4. Apply the code.

Setup

The private SSH key is not saved in the repository, you may need to recreate a private and public key:

cd files
ssh-keyget -f id_rsa
git add id_rsa.pub
git commit -m "New ssh key."
git push

Applying the code

Terraform Cloud is configured to execute this code.

Logging in.

Load the ssh-key into your ssh-agent:

ssh-add files/id_rsa

And login using root:

ssh root@IP_ADDRESS

Importing resources

You can import resource into the remote state:

First create an empty resource in some .tf file. Likely main.tf:

resource "digitalocean_droplet" "imported" {}

Next import the resource:

terraform import digitalocean_droplet.imported 263628785

Now you can see the resource in the state:

terraform show

And the resource can also be removed:

terraform state rm digitalocean_droplet.imported

About

A demonstration environment to show how Git and Terraform can combine.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages