-
Notifications
You must be signed in to change notification settings - Fork 260
/
main.tf
59 lines (52 loc) · 1.6 KB
/
main.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
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.8.0"
}
}
}
provider "digitalocean" {
# You need to set this in your .bashrc
# export DIGITALOCEAN_TOKEN="Your API TOKEN"
#
}
resource "digitalocean_droplet" "mywebserver" {
# Obtain your ssh_key id number via your account. See Document https://developers.digitalocean.com/documentation/v2/#list-all-keys
# ssh_keys = [digitalocean_ssh_key.example.fingerprint]
image = var.ubuntu
region = var.do_ams3
size = "s-1vcpu-1gb"
private_networking = true
backups = true
ipv6 = true
name = "mywebserver-ams3"
user_data = file("cloudinit.conf")
connection {
host = self.ipv4_address
type = "ssh"
private_key = file("~/.ssh/id_rsa")
user = "root"
timeout = "2m"
}
}
# resource "digitalocean_ssh_key" "example" {
# name = "examplekey"
# public_key = file(var.ssh_key_path)
# }
resource "digitalocean_domain" "mywebserver" {
name = "www.mywebserver.com"
ip_address = digitalocean_droplet.mywebserver.ipv4_address
}
resource "digitalocean_record" "mywebserver_ipv4_dns" {
domain = digitalocean_domain.mywebserver.name
type = "A"
name = "mywebserver"
value = digitalocean_droplet.mywebserver.ipv4_address
}
resource "digitalocean_record" "mywebserver_ipv6_dns" {
domain = digitalocean_domain.mywebserver.name
type = "AAAA"
name = "mywebserver"
value = digitalocean_droplet.mywebserver.ipv6_address
}