Skip to content

Commit

Permalink
Initial commit to plan / apply / destroy digitalocean compute resources
Browse files Browse the repository at this point in the history
  • Loading branch information
compscidr committed Mar 22, 2021
0 parents commit 28d0304
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
#
*.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Infrastructure as Code

Most of this was created from this guide:
https://www.digitalocean.com/community/tutorials/how-to-use-terraform-with-digitalocean#step-4-%E2%80%94-using-terraform-to-create-the-nginx-server

## Commands:
To plan:
`terraform plan -var "do_token=${DO_PAT}" -var "pvt_key=$HOME/.ssh/id_rsa"`

To apply:
`terraform apply -var "do_token=${DO_PAT}" -var "pvt_key=$HOME/.ssh/id_rsa"`

To show state:
`terraform show terraform.tfstate`

To destroy:
`terraform plan -destroy -out=terraform.tfplan \
-var "do_token=${DO_PAT}" \
-var "pvt_key=$HOME/.ssh/id_rsa" \`

to make the destroy plan and `terraform apply terraform.tfplan`
18 changes: 18 additions & 0 deletions compute-1.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "digitalocean_droplet" "compute-1" {
image = "ubuntu-20-10-x64"
name = "compute-1"
region = "sfo2"
size = "s-1vcpu-1gb"
private_networking = true
ssh_keys = [
data.digitalocean_ssh_key.terraform.id
]

connection {
host = self.ipv4_address
user = "root"
type = "ssh"
private_key = file(var.pvt_key)
timeout = "2m"
}
}
19 changes: 19 additions & 0 deletions provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "1.22.2"
}
}
}

variable "do_token" {}
variable "pvt_key" {}

provider "digitalocean" {
token = var.do_token
}

data "digitalocean_ssh_key" "terraform" {
name = "terraform"
}

0 comments on commit 28d0304

Please sign in to comment.