packer-builds

Packer Builds for LXC and Libvirt
git clone https://git.in0rdr.ch/packer-builds.git
Log | Files | Refs | Pull requests | README

commit eaef1e8f7386d2ce889ff4f56b1e0feff79a9526
parent 02a363aa059834e21b1025b87496521d42615751
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Fri, 11 Oct 2024 20:07:27 +0200

feat(mariadb): convert json to hcl

Diffstat:
Dmariadb-lxc.json | 44--------------------------------------------
Amariadb-lxc.pkr.hcl | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 44 deletions(-)

diff --git a/mariadb-lxc.json b/mariadb-lxc.json @@ -1,44 +0,0 @@ -{ - "variables": { - "manifest": "manifest.json", - "mysql_bind": "127.0.0.1", - "mysql_root_password": "", - "mysql_additional_users": "\"user1\" \"user2\" \"user3\"", - "mysql_additional_passwords": "\"password1\" \"password2\" \"password3\"", - "mysql_additional_hosts": "\"127.0.0.1\" \"localhost\" \"localhost\"" - }, - "sensitive-variables": [ - "mysql_root_password", - "mysql_additional_passwords" - ], - "builders": [ - { - "type": "lxc", - "name": "mariadb", - "config_file": "config/lxc-config", - "template_name": "download", - "template_parameters": ["--dist", "Debian", "--release", "Bullseye", "--arch", "armv7l", "--no-validate"] - } - ], - "provisioners": [ - { - "type": "shell", - "script": "scripts/timezone.sh" - }, - { - "type": "shell", - "script": "scripts/mariadb.sh", - "environment_vars": [ - "MYSQL_BIND={{ user `mysql_bind` }}", - "MYSQL_ROOT_PASSWORD={{ user `mysql_root_password` }}", - "MYSQL_ADDITIONAL_USERS={{ user `mysql_additional_users` }}", - "MYSQL_ADDITIONAL_PASSWORDS={{ user `mysql_additional_passwords` }}", - "MYSQL_ADDITIONAL_HOSTS={{ user `mysql_additional_hosts` }}" - ] - }, - { - "type": "shell", - "inline": ["mysql -e \"GRANT ALL PRIVILEGES on db1.* to 'user1'@'localhost';\""] - } - ] -} diff --git a/mariadb-lxc.pkr.hcl b/mariadb-lxc.pkr.hcl @@ -0,0 +1,61 @@ +variable "manifest" { + type = string + default = "manifest.json" +} + +variable "mysql_additional_hosts" { + type = string + default = "\"127.0.0.1\" \"localhost\" \"localhost\"" +} + +variable "mysql_additional_passwords" { + type = string + default = "\"password1\" \"password2\" \"password3\"" + sensitive = true +} + +variable "mysql_additional_users" { + type = string + default = "\"user1\" \"user2\" \"user3\"" +} + +variable "mysql_bind" { + type = string + default = "127.0.0.1" +} + +variable "mysql_root_password" { + type = string + default = "" + sensitive = true +} + +source "lxc" "mariadb" { + config_file = "config/lxc-config" + template_name = "download" + template_parameters = ["--dist", "Debian_by_maurer", "--release", "Bookworm", "--arch", "armv7l", "--no-validate"] +} + +build { + sources = ["source.lxc.mariadb"] + + provisioner "shell" { + script = "scripts/timezone.sh" + } + + provisioner "shell" { + environment_vars = [ + "MYSQL_BIND=${var.mysql_bind}", + "MYSQL_ROOT_PASSWORD=${var.mysql_root_password}", + "MYSQL_ADDITIONAL_USERS=${var.mysql_additional_users}", + "MYSQL_ADDITIONAL_PASSWORDS=${var.mysql_additional_passwords}", + "MYSQL_ADDITIONAL_HOSTS=${var.mysql_additional_hosts}" + ] + script = "scripts/mariadb.sh" + } + + provisioner "shell" { + inline = ["mysql -e \"GRANT ALL PRIVILEGES on db1.* to 'user1'@'localhost';\""] + } + +}