A demonstration environment to show how Git and Terraform can combine.
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. |
+--------------------------------------+
- Change the code.
- Add the changes to git. (
git add . ; git commit -m "Description of changes" ; git push
) - Check the plan.
- Apply the code.
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
Terraform Cloud is configured to execute this code.
Load the ssh-key into your ssh-agent:
ssh-add files/id_rsa
And login using root
:
ssh root@IP_ADDRESS
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