Skip to content

Commit 45b9537

Browse files
committed
chore: add terraform configuration for creating a droplet on Digital Ocean.
Part of #1000 [skip ci]
1 parent 67105eb commit 45b9537

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ vagrant/provisioning/roles/php-coder.nginx/
3232
vagrant/provisioning/roles/mystamps-nginx/files/prod/my-stamps.ru.key
3333
vagrant/provisioning/roles/mystamps-nginx/files/prod/my-stamps.ru.crt
3434

35+
# Terraform related files
36+
infra/terraform/.terraform/
37+
infra/terraform/terraform.tfplan
38+
infra/terraform/terraform.tfvars
39+
infra/terraform/terraform.tfstate
40+
3541
# used by docker/prod.yml
3642
docker/application-prod.properties
3743
docker/mysql_backup_mystamps.sql.gz

infra/terraform/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Provisioning a server with Terraform
2+
3+
* Setup credentials (only first time)
4+
```console
5+
$ cd infra/terraform
6+
$ cp terraform.tfvars{.example,}
7+
$ vim terraform.tfvars
8+
```
9+
* Initialize and download modules (if needed)
10+
```console
11+
$ terraform init
12+
```
13+
* Import existing configuration (optionally; only first time)
14+
```console
15+
$ terraform import digitalocean_droplet.web <id>
16+
```
17+
* Plan and apply:
18+
```console
19+
$ terraform plan -out terraform.tfplan
20+
$ terraform apply terraform.tfplan
21+
```

infra/terraform/my-stamps.tf

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# @todo #1000 CI: validate and check Terraform configuration
2+
3+
variable "token" {}
4+
5+
# Provider docs: https://www.terraform.io/docs/providers/do/index.html
6+
provider "digitalocean" {
7+
token = var.token
8+
version = "~> 1.12"
9+
}
10+
11+
# Droplet docs: https://www.terraform.io/docs/providers/do/r/droplet.html
12+
resource "digitalocean_droplet" "web" {
13+
# "ubuntu-16-04-x64" resolves into Ubuntu 16.04.6 while our server is based on Ubuntu 16.04.1
14+
image = "18572320"
15+
name = "my-stamps.ru"
16+
region = "fra1"
17+
size = "s-1vcpu-1gb"
18+
private_networking = true
19+
}
20+
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# How to obtain a token: https://www.digitalocean.com/docs/api/create-personal-access-token/
2+
token = "<insert-token-here>"

0 commit comments

Comments
 (0)