feat: initial commit

This commit is contained in:
lucasdpt
2026-06-04 09:45:51 +02:00
commit 4f9511f313
15 changed files with 600 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
terraform {
required_providers {
random = {
source = "hashicorp/random"
version = "~> 3.6"
}
local = {
source = "hashicorp/local"
version = "~> 2.5"
}
vagrant = {
source = "bmatcuk/vagrant"
version = "~> 4.0"
}
}
}
locals {
vagrantfile_hash = filemd5("${path.module}/Vagrantfile")
provisioning_files = sort(concat(
[for file in fileset("${path.module}/ansible", "**") : "ansible/${file}"],
[for file in fileset("${path.module}/sql", "**") : "sql/${file}"],
))
provisioning_hash = sha256(join("", [
for file in local.provisioning_files : filesha256("${path.module}/${file}")
]))
}
resource "random_password" "mysql" {
length = 16
special = false
}
resource "local_file" "ansible_vars" {
filename = "${path.module}/ansible/group_vars/all.yml"
content = <<EOT
mysql_root_password: "${random_password.mysql.result}"
mysql_database: "tpdb"
mysql_host: "192.168.56.10"
mysql_network_cidr: "192.168.56.0/24"
mysql_port: 3306
EOT
}
resource "vagrant_vm" "environment" {
vagrantfile_dir = path.module
env = {
VAGRANTFILE_HASH = local.vagrantfile_hash
VAGRANT_NO_PARALLEL = "true"
DEBIAN_FRONTEND = "noninteractive"
NEEDRESTART_MODE = "a"
}
}
resource "terraform_data" "run_ansible" {
depends_on = [vagrant_vm.environment, local_file.ansible_vars]
triggers_replace = [
random_password.mysql.result,
local.provisioning_hash,
local.vagrantfile_hash,
]
provisioner "local-exec" {
command = "ANSIBLE_CONFIG=ansible/ansible.cfg ansible-playbook -i ansible/inventory.ini ansible/site.yml"
}
}
output "mysql_password" {
value = random_password.mysql.result
sensitive = true
}