extract Terraform dummy-module to separate repo
https://github.com/status-im/infra-tf-dummy-module Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
8335563a38
commit
6f5c5a53dc
|
@ -1,7 +0,0 @@
|
|||
# Description
|
||||
|
||||
This is a dummy module which does not create any actual cloud resources. It's intended for registering hosts which cannot be managed with Terraform to our infra.
|
||||
|
||||
For example providers like Hetzner or MacStadium have no provider module for Terrafom.
|
||||
|
||||
This module creates the Ansible inventory hosts in order to make hosts appear the same way all the other hosts created by Terraform do.
|
|
@ -1,51 +0,0 @@
|
|||
/*************************************************
|
||||
* WARNING!
|
||||
* This is 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.prefix}-${var.region}"
|
||||
# map of hostname => ip
|
||||
hostnames = { for i, ip in var.ips :
|
||||
"${var.name}-${format("%02d", i + 1)}.${local.dc}.${var.env}.${local.stage}" => ip
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* RESOURCES ------------------------------------*/
|
||||
|
||||
resource "ansible_host" "host" {
|
||||
for_each = local.hostnames
|
||||
inventory_hostname = each.key
|
||||
groups = [var.group, local.dc, "${var.env}.${local.stage}"]
|
||||
|
||||
vars = {
|
||||
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_user = (var.become_user == null ? null : var.become_user)
|
||||
ansible_become_method = (var.become_method == null ? null : var.become_method)
|
||||
}
|
||||
}
|
||||
|
||||
resource "cloudflare_record" "host" {
|
||||
for_each = local.hostnames
|
||||
|
||||
zone_id = var.zone_id
|
||||
name = each.key
|
||||
value = each.value
|
||||
type = "A"
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
output "public_ips" {
|
||||
value = var.ips
|
||||
}
|
||||
|
||||
output "hostnames" {
|
||||
value = keys(local.hostnames)
|
||||
}
|
||||
|
||||
output "hosts" {
|
||||
value = local.hostnames
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/* SCALING --------------------------------------*/
|
||||
|
||||
variable "region" {
|
||||
description = "Region in which the host reside."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "prefix" {
|
||||
description = "Short name of provider being used."
|
||||
type = string
|
||||
default = "ms"
|
||||
}
|
||||
|
||||
/* STATIC ---------------------------------------*/
|
||||
|
||||
variable "ips" {
|
||||
description = "Static list of IPs used by the hosts."
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
/* GENERAL --------------------------------------*/
|
||||
|
||||
variable "name" {
|
||||
description = "Prefix of hostname before index."
|
||||
type = string
|
||||
default = "node"
|
||||
}
|
||||
|
||||
variable "group" {
|
||||
description = "Name of Ansible group to add hosts to."
|
||||
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 "domain" {
|
||||
description = "DNS Domain to update"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "zone_id" {
|
||||
description = "ID of CloudFlare zone for host record."
|
||||
/* We default to: statusim.net */
|
||||
default = "14660d10344c9898521c4ba49789f563"
|
||||
}
|
||||
|
||||
variable "shell_type" {
|
||||
description = "Type of shell used by Ansible."
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "become_user" {
|
||||
description = "What user Ansible should become."
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
variable "become_method" {
|
||||
description = "Method used by Ansible to become a user."
|
||||
type = string
|
||||
default = null
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
terraform {
|
||||
required_version = "~> 1.0.0"
|
||||
required_providers {
|
||||
ansible = {
|
||||
source = "nbering/ansible"
|
||||
version = " = 1.0.4"
|
||||
}
|
||||
cloudflare = {
|
||||
source = "cloudflare/cloudflare"
|
||||
version = " = 2.21.0"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue