add hetzner dummy module (#55)

Signed-off-by: Arthur Koziel <arthur@arthurkoziel.com>
This commit is contained in:
Arthur Koziel 2021-05-18 14:07:26 +08:00 committed by GitHub
parent 2047fe1702
commit 16a5ba698a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,5 @@
# Description
This isn't a real Hetzner cloud provider module for Terrafom.
This is just a dummy module which creates the Ansible inventory hosts in order to make the Hetzner hosts appear the same way all the other hosts created by Terraform do.

48
modules/hetzner/main.tf Normal file
View File

@ -0,0 +1,48 @@
/*************************************************
* WARNING!
* This is not a Terraform provider for Hetzner.
* I'm just creating the inventory entries
* 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)
dc = "${var.provider_name}-${var.region}"
# map of ip => hostname
hostnames = { for i, ip in var.ips :
ip => "${var.name}-${format("%02d", i + 1)}.${local.dc}.${var.env}.${local.stage}"
}
}
/* RESOURCES ------------------------------------*/
resource "ansible_host" "host" {
for_each = local.hostnames
inventory_hostname = each.value
groups = [var.group, local.dc]
vars = {
ansible_host = each.key
ansible_ssh_user = var.ssh_user
hostname = each.value
region = var.region
dns_domain = var.domain
dns_entry = "${each.value}.${var.domain}"
data_center = local.dc
stage = local.stage
env = var.env
}
}
resource "cloudflare_record" "host" {
for_each = local.hostnames
zone_id = var.cf_zone_id
name = each.value // hostname
value = each.key // ip
type = "A"
ttl = 3600
}

View File

@ -0,0 +1,63 @@
/* SCALING --------------------------------------*/
variable "ips" {
description = "Static list of IPs used by the hosts."
type = list(string)
}
variable "region" {
description = "Region in which the host reside."
type = string
default = "eu-hel1"
}
variable "provider_name" {
description = "Short name of provider being used."
type = string
default = "he"
}
/* SECURITY --------------------------------------*/
variable "ssh_user" {
description = "Default user for SSH access."
type = string
default = "root"
}
/* CONFIG ----------------------------------------*/
variable "name" {
description = "Name for hosts. To be used in the DNS entry."
type = string
}
variable "env" {
description = "Environment for these hosts, affects DNS entries."
type = string
}
variable "stage" {
description = "Name of stage, like prod, dev, or staging."
type = string
default = ""
}
variable "group" {
description = "Ansible group to assign hosts to."
type = string
}
variable "domain" {
description = "DNS Domain to update"
type = string
}
/* DNS ------------------------------------------*/
/* We default to: statusim.net */
variable "cf_zone_id" {
description = "ID of CloudFlare zone for host record."
type = string
default = "14660d10344c9898521c4ba49789f563"
}

View File

@ -0,0 +1,13 @@
terraform {
required_version = "~> 0.14.4"
required_providers {
ansible = {
source = "nbering/ansible"
version = " = 1.0.4"
}
cloudflare = {
source = "cloudflare/cloudflare"
version = " = 2.10.1"
}
}
}