diff --git a/README.md b/README.md index b673075..b4558f1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,40 @@ -# PI Bakery +# Terraform Docker Packer -## Firstboot -Adopted from https://github.com/nmcclain/raspberian-firstboot \ No newline at end of file +This Terraform module serves as an abstraction to builds machine images from Packer configurations through Docker. + +## Requirements + +| Name | Version | +|------|---------| +| [docker](#requirement\_docker) | ~> 3.0.1 | + +## Providers + +| Name | Version | +|------|---------| +| [docker](#provider\_docker) | 3.0.2 | +| [local](#provider\_local) | 2.5.2 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [docker_container.packer](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container) | resource | +| [docker_image.packer](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/image) | resource | +| [local_file.packer_variables](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [packer\_config](#input\_packer\_config) | n/a | `string` | n/a | yes | +| [packer\_image](#input\_packer\_image) | n/a | `string` | `"mkaczanowski/packer-builder-arm:latest"` | no | +| [packer\_variables](#input\_packer\_variables) | n/a | `any` | n/a | yes | + +## Outputs + +No outputs. diff --git a/ctl.sh b/ctl.sh index 2b86457..701d42a 100755 --- a/ctl.sh +++ b/ctl.sh @@ -6,8 +6,11 @@ function info { function build { function image { - terraform apply - docker logs -f $(docker ps -q -f name=packer-builder-arm) + pushd examples/raspios + terraform init + terraform apply + docker logs -f $(docker ps -q -f name=packer-builder-arm) + popd } ${@:-info} } diff --git a/examples/raspios/README.md b/examples/raspios/README.md new file mode 100644 index 0000000..b2ccd20 --- /dev/null +++ b/examples/raspios/README.md @@ -0,0 +1,9 @@ +# RaspiOS + +Build a new RaspiOS device image. +The Packer config will run some scripts through the Shell provisioner in order to setup and configure the device image. + +## Firstboot + +This example contains a Systemd service and script that will run at first boot and sets the hostname to `rpi-SERIAL`. +Adopted from https://github.com/nmcclain/raspberian-firstboot \ No newline at end of file diff --git a/examples/raspios/main.tf b/examples/raspios/main.tf index 711de10..7fef991 100644 --- a/examples/raspios/main.tf +++ b/examples/raspios/main.tf @@ -1,9 +1,12 @@ module "raspios" { source = "../../" packer_config = "packer/raspios.pkr.hcl" - provisioning_scripts = [ - "scripts/pi.sh", - "scripts/docker.sh", - "scripts/hashi.sh" - ] + packer_variables = { + image_path = "rpi-arm64.img" + scripts = [ + "scripts/pi.sh", + "scripts/docker.sh", + "scripts/hashi.sh" + ] + } } \ No newline at end of file diff --git a/examples/raspios/variables.pkrvars.hcl b/examples/raspios/variables.pkrvars.hcl index eeec147..ba997d2 100755 --- a/examples/raspios/variables.pkrvars.hcl +++ b/examples/raspios/variables.pkrvars.hcl @@ -1 +1,2 @@ +image_path = "rpi-arm64.img" scripts = ["scripts/pi.sh","scripts/docker.sh","scripts/hashi.sh"] diff --git a/main.tf b/main.tf index 228bac2..831ad05 100644 --- a/main.tf +++ b/main.tf @@ -1,12 +1,15 @@ locals { packer_variables_file = "variables.pkrvars.hcl" + packer_variables = <<-EOT +%{ for key, value in var.packer_variables ~} +${key} = ${try(jsonencode(value), "\"${value}\"")} +%{ endfor ~} +EOT } resource "local_file" "packer_variables" { filename = local.packer_variables_file - content = <<-EOT - scripts = ${jsonencode(var.provisioning_scripts)} - EOT + content = local.packer_variables } resource "docker_image" "packer" { diff --git a/variables.tf b/variables.tf index 81cc517..bf3c93d 100644 --- a/variables.tf +++ b/variables.tf @@ -7,7 +7,6 @@ variable "packer_config" { type = string } -variable "provisioning_scripts" { - type = list(string) - default = [] -} +variable "packer_variables" { + +} \ No newline at end of file