Skip to content

Commit

Permalink
Merge pull request chvancooten#6 from thehackerish/main
Browse files Browse the repository at this point in the history
Replace deprecated template_file with filetemplate
  • Loading branch information
chvancooten authored Jun 21, 2022
2 parents f7e8d7e + 931a66d commit fd1cf1c
Showing 1 changed file with 24 additions and 48 deletions.
72 changes: 24 additions & 48 deletions Terraform/08-ansible.tf
Original file line number Diff line number Diff line change
@@ -1,78 +1,54 @@
# Prepare the Windows group variable template with the right username and password
data "template_file" "ansible-groupvars-windows" {
template = "${file("../Ansible/group_vars/windows.tmpl")}"
resource "local_file" "ansible-groupvars-windows-creation" {

depends_on = [
var.windows-user,
var.domain-dns-name,
random_string.windowspass
]

vars = {
username = var.windows-user
password = random_string.windowspass.result
domain_name = var.domain-dns-name
}
}

resource "null_resource" "ansible-groupvars-windows-creation" {
triggers = {
template_rendered = "${data.template_file.ansible-groupvars-windows.rendered}"
}

provisioner "local-exec" {
command = "echo '${data.template_file.ansible-groupvars-windows.rendered}' > ../Ansible/group_vars/windows.yml"
}
content = templatefile("${path.module}/../Ansible/group_vars/windows.tmpl",
{
username = var.windows-user
password = random_string.windowspass.result
domain_name = var.domain-dns-name
})

filename = "../Ansible/group_vars/windows.yml"
}

# Prepare the Linux group variable template with the right username and password
data "template_file" "ansible-groupvars-linux" {
template = "${file("../Ansible/group_vars/linux.tmpl")}"
resource "local_file" "ansible-groupvars-linux-creation" {

depends_on = [
var.linux-user,
random_string.linuxpass
]

vars = {
username = var.linux-user
password = random_string.linuxpass.result
}
}
content = templatefile("${path.module}/../Ansible/group_vars/linux.tmpl",
{
username = var.linux-user
password = random_string.linuxpass.result
})

resource "null_resource" "ansible-groupvars-linux-creation" {
triggers = {
template_rendered = "${data.template_file.ansible-groupvars-linux.rendered}"
}

provisioner "local-exec" {
command = "echo '${data.template_file.ansible-groupvars-linux.rendered}' > ../Ansible/group_vars/linux.yml"
}
filename = "../Ansible/group_vars/linux.yml"
}

# Prepare the Elastic group variable template with the right username and password
data "template_file" "ansible-groupvars-elastic" {
template = "${file("../Ansible/group_vars/elastic.tmpl")}"
resource "local_file" "ansible-groupvars-elastic-creation" {

depends_on = [
random_string.linuxpass,
azurerm_network_interface.cloudlabs-vm-elastic-nic
]

vars = {
password = random_string.linuxpass.result
ip = azurerm_network_interface.cloudlabs-vm-elastic-nic.private_ip_address
}
}
content = templatefile("${path.module}/../Ansible/group_vars/linux.tmpl",
{
password = random_string.linuxpass.result
ip = azurerm_network_interface.cloudlabs-vm-elastic-nic.private_ip_address
})

resource "null_resource" "ansible-groupvars-elastic-creation" {
triggers = {
template_rendered = "${data.template_file.ansible-groupvars-elastic.rendered}"
}

provisioner "local-exec" {
command = "echo '${data.template_file.ansible-groupvars-elastic.rendered}' > ../Ansible/group_vars/elastic.yml"
}
filename = "../Ansible/group_vars/elastic.yml"
}

# Provision the lab using Ansible from the hackbox machine
Expand Down Expand Up @@ -110,4 +86,4 @@ resource "null_resource" "ansible-provisioning" {
"ansible-playbook -v cloudlabs.yml"
]
}
}
}

0 comments on commit fd1cf1c

Please sign in to comment.