imfreedom/bamboo-terraform
Clone
Summary
Browse
Changes
Graph
set bamboo capabilities to an empty dict by default
draft
default
tip
2019-10-01, Gary Kramlich
05b5b1440935
set bamboo capabilities to an empty dict by default
variable
"cache_enabled"
{
default
=
true
}
variable
"cache_disk_size"
{
default
=
"107374182400"
}
# 100gb
variable
"cache_memory"
{
default
=
"1024"
}
# 1gb
variable
"cache_cpu"
{
default
=
"1"
}
resource
"libvirt_volume"
"cache"
{
count
=
"${var.cache_enabled ? 1 : 0 }"
name
=
"${format("%s-cache-root", var.node_name)}"
format
=
"qcow2"
base_volume_id
=
"${libvirt_volume.debian_base.id}"
size
=
"${var.cache_disk_size}"
pool
=
"${var.volume_pool}"
}
data
"template_file"
"cache_user_data"
{
count
=
"${var.cache_enabled ? 1 : 0 }"
template
=
<<
EOF
#cloud-config
fqdn: $${fqdn}
users:
- name: root
ssh_authorized_keys:
- $${admin_ssh_pubkey}
growpart:
mode: auto
devices: ['/']
ignore_growroot_disabled: false
EOF
vars
{
admin_ssh_pubkey
=
"${var.admin_ssh_pubkey}"
fqdn
=
"${format("%s-cache", var.node_name)}"
}
}
resource
"libvirt_cloudinit_disk"
"cache"
{
count
=
"${var.cache_enabled ? 1 : 0 }"
name
=
"${format("%s-cache-init.iso", var.node_name)}"
user_data
=
"${data.template_file.cache_user_data.rendered}"
}
resource
"libvirt_domain"
"cache"
{
count
=
"${var.cache_enabled ? 1 : 0 }"
name
=
"${format("%s-cache", var.node_name)}"
memory
=
"${var.cache_memory}"
vcpu
=
"${var.cache_cpu}"
autostart
=
true
cloudinit
=
"${libvirt_cloudinit_disk.cache.id}"
console
{
type
=
"pty"
target_port
=
"0"
target_type
=
"serial"
}
disk
{
volume_id
=
"${libvirt_volume.cache.id}"
}
network_interface
{
network_name
=
"default"
wait_for_lease
=
true
}
boot_device
{
dev
=
[
"hd"
]
}
}
# Create the variables file for the cache (used by the worker)
resource
"local_file"
"cache_variables"
{
content
=
"${join("\n", list("---", format("cache_enabled: %s", var.cache_enabled ? "true" : "false"), var.cache_enabled ? format("cache_hostname: %s-cache", var.node_name) : ""))}"
filename
=
"${path.module}/cache.variables"
}
# Create the ansible inventory
resource
"local_file"
"cache_hosts"
{
count
=
"${var.cache_enabled ? 1 : 0 }"
content
=
"${join("\n", formatlist("%s ansible_ssh_common_args='-o ProxyJump=%s -o StrictHostKeyChecking=off' ansible_user=root ansible_host=%s", libvirt_domain.cache.*.name, replace(replace(var.libvirt_uri, "qemu+ssh://", ""), "/system", ""), flatten(libvirt_domain.cache.*.network_interface.0.addresses)))}"
filename
=
"${path.module}/hosts.cache"
}
# Run ansible against all the workers
resource
"null_resource"
"cache_ansible"
{
count
=
"${var.cache_enabled ? 1 : 0 }"
triggers
=
{
hosts
=
"${sha1(local_file.cache_hosts.content)}"
ansible
=
"${data.archive_file.ansible_scripts.output_sha}"
}
provisioner
"local-exec"
{
command
=
"ansible-playbook -i ${path.module}/hosts.cache -b ansible/cache.yml --vault-password-file=secrets/ansible_vault_password.txt"
}
}
# Output the ip of the cache
output
"cache_ip"
{
value
=
"${flatten(libvirt_domain.cache.*.network_interface.0.addresses)}"
}