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
|
This Terraform module serves as an abstraction to builds machine images from Packer configurations through Docker.
|
||||||
Adopted from https://github.com/nmcclain/raspberian-firstboot
|
|
||||||
|
## 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 build {
|
||||||
function image {
|
function image {
|
||||||
terraform apply
|
pushd examples/raspios
|
||||||
docker logs -f $(docker ps -q -f name=packer-builder-arm)
|
terraform init
|
||||||
|
terraform apply
|
||||||
|
docker logs -f $(docker ps -q -f name=packer-builder-arm)
|
||||||
|
popd
|
||||||
}
|
}
|
||||||
${@:-info}
|
${@:-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" {
|
module "raspios" {
|
||||||
source = "../../"
|
source = "../../"
|
||||||
packer_config = "packer/raspios.pkr.hcl"
|
packer_config = "packer/raspios.pkr.hcl"
|
||||||
provisioning_scripts = [
|
packer_variables = {
|
||||||
"scripts/pi.sh",
|
image_path = "rpi-arm64.img"
|
||||||
"scripts/docker.sh",
|
scripts = [
|
||||||
"scripts/hashi.sh"
|
"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"]
|
scripts = ["scripts/pi.sh","scripts/docker.sh","scripts/hashi.sh"]
|
||||||
|
|||||||
9
main.tf
9
main.tf
@@ -1,12 +1,15 @@
|
|||||||
locals {
|
locals {
|
||||||
packer_variables_file = "variables.pkrvars.hcl"
|
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" {
|
resource "local_file" "packer_variables" {
|
||||||
filename = local.packer_variables_file
|
filename = local.packer_variables_file
|
||||||
content = <<-EOT
|
content = local.packer_variables
|
||||||
scripts = ${jsonencode(var.provisioning_scripts)}
|
|
||||||
EOT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "docker_image" "packer" {
|
resource "docker_image" "packer" {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ variable "packer_config" {
|
|||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "provisioning_scripts" {
|
variable "packer_variables" {
|
||||||
type = list(string)
|
|
||||||
default = []
|
}
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user