-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdo.tf
59 lines (50 loc) · 1.31 KB
/
do.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
variable "do_token" {}
variable "do_region" {}
variable "ssh_key" {}
variable "domain_name" {}
variable "droplet_name" {}
# Configure the DigitalOcean Provider
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}
provider "digitalocean" {
token = var.do_token
}
resource "digitalocean_ssh_key" "do_sshkey" {
name = "Digital Ocean"
public_key = "${file("${var.ssh_key}")}"
}
resource "random_id" "ipsec_key" {
byte_length = 32
}
data "template_file" "init" {
template = "${file("init.tpl")}"
vars = {
ipsec_ip = "0.0.0.0"
secret_key = "${random_id.ipsec_key.hex}"
}
}
# Create a web server
resource "digitalocean_droplet" "mydroplet" {
image = "ubuntu-16-04-x64"
name = "${var.droplet_name}"
region = "${var.do_region}"
size = "s-1vcpu-1gb"
ssh_keys = ["${digitalocean_ssh_key.do_sshkey.id}"]
user_data = "${data.template_file.init.rendered}"
}
resource "digitalocean_domain" "my-domain" {
name = "${var.domain_name}"
ip_address = "${digitalocean_droplet.mydroplet.ipv4_address}"
}
resource "digitalocean_record" "mydroplet" {
domain = "${digitalocean_domain.my-domain.name}"
type = "A"
name = "${var.droplet_name}"
value = "${digitalocean_droplet.mydroplet.ipv4_address}"
}