lpi-deploy-digitalocean/lpi.tf
2018-10-20 13:18:34 +03:00

93 lines
2.5 KiB
HCL

provider "digitalocean" {
token = "${var.do_token}"
}
resource "digitalocean_volume" "centos_lpi" {
count = "${var.count}"
name = "${var.server_name["centos"]}-${count.index}.vol"
region = "${var.region}"
size = 20
description = "Empty Volume"
}
resource "digitalocean_droplet" "centos_lpi" {
count = "${var.count}"
name = "${var.server_name["centos"]}-${count.index}.${var.domain}"
image = "${var.images["centos"]}"
size = "${var.size}"
region = "${var.region}"
ssh_keys = "${var.ssh_keys}"
volume_ids = ["${element(digitalocean_volume.centos_lpi.*.id, count.index)}"]
}
resource "digitalocean_volume" "debian_lpi" {
count = "${var.count}"
name = "${var.server_name["debian"]}-${count.index}.vol"
region = "${var.region}"
size = 20
description = "Empty Volume"
}
resource "digitalocean_droplet" "debian_lpi" {
count = "${var.count}"
name = "${var.server_name["debian"]}-${count.index}.${var.domain}"
image = "${var.images["debian"]}"
size = "${var.size}"
region = "${var.region}"
ssh_keys = "${var.ssh_keys}"
volume_ids = ["${element(digitalocean_volume.debian_lpi.*.id, count.index)}"]
}
provider "dns" {
update {
server = "${var.dns_server}"
key_name = "${var.dns_key_name}"
key_algorithm = "hmac-sha512"
key_secret = "${var.dns_key}"
}
}
resource "dns_a_record_set" "centos_lpi" {
count = "${var.count}"
zone = "${var.domain}."
name = "${var.server_name["centos"]}-${count.index}"
addresses = ["${element(digitalocean_droplet.centos_lpi.*.ipv4_address, count.index)}"]
ttl = 300
provisioner "remote-exec" {
inline = [
"rndc sync -clean",
]
connection {
type = "ssh"
host = "${var.dns_server}"
user = "root"
port = "3347"
private_key = "${file("private.key")}"
}
}
}
resource "dns_a_record_set" "debian_lpi" {
count = "${var.count}"
zone = "${var.domain}."
name = "${var.server_name["debian"]}-${count.index}"
addresses = ["${element(digitalocean_droplet.debian_lpi.*.ipv4_address, count.index)}"]
ttl = 300
provisioner "remote-exec" {
inline = [
"rndc sync -clean",
]
connection {
type = "ssh"
host = "${var.dns_server}"
user = "root"
port = "3347"
private_key = "${file("private.key")}"
}
}
}