Ver código fonte

terraform default module structure

master
pai
commit
9e3aa5b404
4 arquivos alterados com 47 adições e 61 exclusões
  1. +0
    -61
      inventory.tf
  2. +0
    -0
      main.tf
  3. +28
    -0
      outputs.tf
  4. +19
    -0
      variables.tf

+ 0
- 61
inventory.tf Ver arquivo

@@ -1,27 +1,3 @@
variable "vm_hosts" {
default = {
#"hostname.example.com" = {
# provider = "hetzner"
# groups = [ "testgroup" ]
# volumes = {
# data = { size = 32 }
# }
#}
}
}

variable "groups" {
default = {
#testgroup = {
# testvar1 = "bla"
#}
}
}

variable "ansible_inventory_filename" {
type = string
default = "inventory.json"
}

locals {
vm_hosts_with_groups = {
@@ -31,41 +7,4 @@ locals {
for hostname, host in var.vm_hosts: hostname => host if !contains(keys(host),"groups")
}
vm_groups = distinct(flatten(values(local.hetzner_vm_hosts_with_groups)[*].groups))
ansible_inventory = {
all = {
hosts = {
for hostname,host in var.vm_hosts: hostname => {}
}
children = merge(
{
for group in local.vm_groups: group => {
hosts = {
for hostname, host in local.vm_hosts_with_groups:
hostname => {}
if contains(host.groups,group)
}
}
},{
for providername, provider in local.providers: "provider_${providername}" => {
hosts = {
for hostname, host in var.vm_hosts:
hostname => local.providers[host.provider].hostvars[hostname]
if host.provider == providername
}
}
}
)
}
}
}

output "ansible_inventory" {
value = local.ansible_inventory
}

resource "local_file" "ansible_inventory" {
content = jsonencode(local.ansible_inventory)
filename = var.ansible_inventory_filename
file_permission = "0644"
directory_permission = "0755"
}

versions.tf → main.tf Ver arquivo


+ 28
- 0
outputs.tf Ver arquivo

@@ -0,0 +1,28 @@
output "ansible_inventory" {
value = {
all = {
hosts = {
for hostname,host in var.vm_hosts: hostname => {}
}
children = merge(
{
for group in local.vm_groups: group => {
hosts = {
for hostname, host in local.vm_hosts_with_groups:
hostname => {}
if contains(host.groups,group)
}
}
},{
for providername, provider in local.providers: "provider_${providername}" => {
hosts = {
for hostname, host in var.vm_hosts:
hostname => local.providers[host.provider].hostvars[hostname]
if host.provider == providername
}
}
}
)
}
}
}

+ 19
- 0
variables.tf Ver arquivo

@@ -0,0 +1,19 @@
variable "vm_hosts" {
default = {
#"hostname.example.com" = {
# provider = "hetzner"
# groups = [ "testgroup" ]
# volumes = {
# data = { size = 32 }
# }
#}
}
}

variable "groups" {
default = {
#testgroup = {
# testvar1 = "bla"
#}
}
}

Carregando…
Cancelar
Salvar