mirror of
https://github.com/0x1d/terraform-docker-packer.git
synced 2025-12-14 22:02:26 +01:00
Example and docs
This commit is contained in:
42
README.md
42
README.md
@@ -1,4 +1,40 @@
|
||||
# PI Bakery
|
||||
# Terraform Docker Packer
|
||||
|
||||
## Firstboot
|
||||
Adopted from https://github.com/nmcclain/raspberian-firstboot
|
||||
This Terraform module serves as an abstraction to builds machine images from Packer configurations through Docker.
|
||||
|
||||
## Requirements
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_docker"></a> [docker](#requirement\_docker) | ~> 3.0.1 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_docker"></a> [docker](#provider\_docker) | 3.0.2 |
|
||||
| <a name="provider_local"></a> [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 |
|
||||
|------|-------------|------|---------|:--------:|
|
||||
| <a name="input_packer_config"></a> [packer\_config](#input\_packer\_config) | n/a | `string` | n/a | yes |
|
||||
| <a name="input_packer_image"></a> [packer\_image](#input\_packer\_image) | n/a | `string` | `"mkaczanowski/packer-builder-arm:latest"` | no |
|
||||
| <a name="input_packer_variables"></a> [packer\_variables](#input\_packer\_variables) | n/a | `any` | n/a | yes |
|
||||
|
||||
## Outputs
|
||||
|
||||
No outputs.
|
||||
|
||||
7
ctl.sh
7
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}
|
||||
}
|
||||
|
||||
9
examples/raspios/README.md
Normal file
9
examples/raspios/README.md
Normal file
@@ -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
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
image_path = "rpi-arm64.img"
|
||||
scripts = ["scripts/pi.sh","scripts/docker.sh","scripts/hashi.sh"]
|
||||
|
||||
9
main.tf
9
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" {
|
||||
|
||||
@@ -7,7 +7,6 @@ variable "packer_config" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "provisioning_scripts" {
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
variable "packer_variables" {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user