2021-05-18 06:07:26 +00:00
|
|
|
/*************************************************
|
|
|
|
* WARNING!
|
2022-02-25 13:19:08 +00:00
|
|
|
* This is just creating the inventory entries
|
2021-05-18 06:07:26 +00:00
|
|
|
* the same way I do it for other hosts so
|
|
|
|
* Ansible can use them during provisioning.
|
|
|
|
*************************************************/
|
|
|
|
|
|
|
|
/* DERIVED --------------------------------------*/
|
|
|
|
|
|
|
|
locals {
|
|
|
|
stage = var.stage != "" ? var.stage : terraform.workspace
|
|
|
|
tokens = split(".", local.stage)
|
2022-02-25 13:19:08 +00:00
|
|
|
dc = "${var.prefix}-${var.region}"
|
|
|
|
# map of hostname => ip
|
2021-05-18 06:07:26 +00:00
|
|
|
hostnames = { for i, ip in var.ips :
|
2022-02-25 13:19:08 +00:00
|
|
|
"${var.name}-${format("%02d", i + 1)}.${local.dc}.${var.env}.${local.stage}" => ip
|
2021-05-18 06:07:26 +00:00
|
|
|
}
|
2022-02-25 13:19:08 +00:00
|
|
|
|
2021-05-18 06:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RESOURCES ------------------------------------*/
|
|
|
|
|
|
|
|
resource "ansible_host" "host" {
|
|
|
|
for_each = local.hostnames
|
2022-02-25 13:19:08 +00:00
|
|
|
inventory_hostname = each.key
|
2021-05-19 10:04:12 +00:00
|
|
|
groups = [var.group, local.dc, "${var.env}.${local.stage}"]
|
2022-02-25 13:19:08 +00:00
|
|
|
|
2021-05-18 06:07:26 +00:00
|
|
|
vars = {
|
2022-02-25 13:19:08 +00:00
|
|
|
hostname = each.key
|
|
|
|
dns_entry = "${each.key}.${var.domain}"
|
|
|
|
dns_domain = var.domain
|
|
|
|
data_center = local.dc
|
|
|
|
region = var.region
|
|
|
|
env = var.env
|
|
|
|
stage = local.stage
|
|
|
|
ansible_host = each.value
|
|
|
|
/* Optional extra Ansible variables necessary for Windows */
|
|
|
|
ansible_shell_type = (var.shell_type == null ? null : var.shell_type)
|
|
|
|
ansible_become = (var.become == null ? null : var.become)
|
2021-05-18 06:07:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "cloudflare_record" "host" {
|
|
|
|
for_each = local.hostnames
|
2022-02-25 13:19:08 +00:00
|
|
|
|
|
|
|
zone_id = var.zone_id
|
|
|
|
name = each.key
|
|
|
|
value = each.value
|
|
|
|
type = "A"
|
2021-05-18 06:07:26 +00:00
|
|
|
}
|