-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit to plan / apply / destroy digitalocean compute resources
- Loading branch information
0 parents
commit 28d0304
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |