-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.tf
77 lines (64 loc) · 1.79 KB
/
data.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
locals {
default_environment_variables = [
"DROPLET_INTERNAL_IP=${digitalocean_droplet.this.ipv4_address_private}",
"DROPLET_EXTERNAL_IP=${digitalocean_droplet.this.ipv4_address}",
]
default_packages = [
"curl",
"mc",
"net-tools"
]
default_commands = [
"sudo mkdir -p ${var.app_data}/${var.app_configurations}",
"sudo chown ${var.droplet_user}:terraform ${var.app_data}/${var.app_configurations}",
"sudo chmod 775 ${var.app_data}/${var.app_configurations}",
]
user_data = <<EOF
#cloud-config
ssh_pwauth: false
disable_root: true
package_update: true
package_upgrade: true
manage_etc_hosts: true
users:
- name: ${var.droplet_user}
groups:
- sudo
sudo:
- ALL=(ALL) NOPASSWD:ALL
ssh-authorized-keys:
- ${data.digitalocean_ssh_key.user.public_key}
- name: terraform
groups:
- sudo
sudo:
- ALL=(ALL) NOPASSWD:ALL
ssh-authorized-keys:
- ${data.digitalocean_ssh_key.remote_provisioner.public_key}
packages:
${local.default_packages != null ? join("\n", formatlist(" - '%s'", local.default_packages)) : ""}
${var.os_packages != null ? join("\n", formatlist(" - '%s'", var.os_packages)) : ""}
runcmd:
${local.default_commands != null ? join("\n", formatlist(" - '%s'", local.default_commands)) : ""}
EOF
}
data "digitalocean_ssh_key" "user" {
name = var.droplet_user
}
data "digitalocean_ssh_key" "remote_provisioner" {
name = "terraform"
}
data "digitalocean_project" "this" {
name = var.droplet_project
}
data "digitalocean_domain" "this" {
name = var.droplet_dns_zone
}
data "digitalocean_vpc" "this" {
name = "${var.droplet_region}-vpc-${var.droplet_project}"
}
data "digitalocean_droplet_snapshot" "this" {
name = var.droplet_image
region = var.droplet_region
most_recent = true
}