Skip to content

Commit

Permalink
Merge pull request #110 from konstruktoid/packerinit
Browse files Browse the repository at this point in the history
add required_plugins
  • Loading branch information
konstruktoid committed Oct 9, 2023
2 parents 30aee37 + abde7a4 commit 2d6308a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ on how to rewrite the template if you want to use it for another platforms.

### Using `packer`

#### Amazon Web Services

Requires [Packer](https://www.packer.io/) and a
[Amazon Web Services](https://aws.amazon.com/) account.

Ensure that the correct `release` and `aws_region` are set in
`ubuntu-aws-vars.json` before validating the configuration and building the
Amazon Machine Image.

```sh
packer init -upgrade -var-file ubuntu-aws-vars.json ubuntu-hardened-aws.pkr.hcl
packer validate -var-file ubuntu-aws-vars.json ubuntu-hardened-aws.pkr.hcl
packer build -timestamp-ui -var-file ubuntu-aws-vars.json ubuntu-hardened-aws.pkr.hcl
```

#### Local files

> **Note**
Expand All @@ -44,20 +59,6 @@ one.
`packer build -force -timestamp-ui -var-file <var-file> ubuntu-hardened-box.pkr.hcl`
is the `packer` command used if all files are valid.

#### Amazon Web Services

Requires [Packer](https://www.packer.io/) and a
[Amazon Web Services](https://aws.amazon.com/) account.

Ensure that the correct `release` and `aws_region` are set in
`ubuntu-aws-vars.json` before validating the configuration and building the
Amazon Machine Image.

```sh
packer validate -var-file ubuntu-aws-vars.json ubuntu-hardened-aws.pkr.hcl
packer build -timestamp-ui -var-file ubuntu-aws-vars.json ubuntu-hardened-aws.pkr.hcl
```

### Verification

There's a [SLSA](https://slsa.dev/) artifact present under the
Expand Down
2 changes: 2 additions & 0 deletions build_box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ shellcheck -x -s bash -f gcc scripts/* || exit 1

vagrant destroy --force

packer init -upgrade ubuntu-hardened-box.pkr.hcl

grep -o 'box = ".*"' Vagrantfile | awk -F '"' '{print $2}' | while read -r BOX; do
vagrant box remove "${BOX}" --all || true
done
Expand Down
9 changes: 9 additions & 0 deletions ubuntu-hardened-aws.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ variable "release" {

locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }

packer {
required_plugins {
amazon = {
version = ">= 1.2.6"
source = "github.com/hashicorp/amazon"
}
}
}

source "amazon-ebs" "hardened" {
ami_name = "hardened-ubuntu-${local.timestamp}"
instance_type = var.instance_type
Expand Down
9 changes: 9 additions & 0 deletions ubuntu-hardened-box.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ locals {
basename = "ubuntu-${var.release}"
}

packer {
required_plugins {
vagrant = {
version = ">= 1.0.2"
source = "github.com/hashicorp/vagrant"
}
}
}

source "virtualbox-iso" "ubuntu-hardened-server" {
boot_command = [
"c<wait>",
Expand Down

0 comments on commit 2d6308a

Please sign in to comment.