forked from caddyserver/dist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
packer: convert JSON packer template to HCL (caddyserver#75)
* packer: convert JSON packer template to HCL * packer: delete the JSON template * packer: make it beautiful * packer: remove the autogenerated disclaimer Co-authored-by: Dave Henderson <[email protected]> Co-authored-by: Dave Henderson <[email protected]>
- Loading branch information
1 parent
2f23e8a
commit 7e1546d
Showing
3 changed files
with
68 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
packer { | ||
required_plugins { | ||
digitalocean = { | ||
version = ">= 1.0.0" | ||
source = "github.com/hashicorp/digitalocean" | ||
} | ||
} | ||
} | ||
|
||
variable "token" { | ||
type = string | ||
default = env("DIGITALOCEAN_TOKEN") | ||
} | ||
|
||
# "timestamp" template function replacement | ||
locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } | ||
|
||
# All locals variables are generated from variables that uses expressions | ||
# that are not allowed in HCL2 variables. | ||
# Read the documentation for locals blocks here: | ||
# https://www.packer.io/docs/templates/hcl_templates/blocks/locals | ||
locals { | ||
image_name = "marketplace-snapshot-${local.timestamp}" | ||
ssh_user = "root" | ||
} | ||
|
||
source "digitalocean" "caddy_image" { | ||
api_token = var.token | ||
image = "ubuntu-20-04-x64" | ||
region = "nyc3" | ||
size = "s-1vcpu-1gb" | ||
snapshot_name = local.image_name | ||
ssh_username = local.ssh_user | ||
} | ||
|
||
build { | ||
sources = ["source.digitalocean.caddy_image"] | ||
|
||
provisioner "shell" { | ||
scripts = [ | ||
"scripts/00-base.sh", | ||
"scripts/10-firewall.sh", | ||
"scripts/20-caddy.sh" | ||
] | ||
} | ||
|
||
provisioner "file" { | ||
destination = "/etc/fail2ban/jail.local" | ||
source = "files/fail2ban/jail.local" | ||
} | ||
|
||
provisioner "ansible" { | ||
galaxy_file = "ansible/requirements.yml" | ||
playbook_file = "ansible/ansible-playbook.yml" | ||
user = local.ssh_user | ||
} | ||
|
||
provisioner "shell" { | ||
scripts = [ | ||
"scripts/50-services.sh", | ||
"scripts/90-cleanup.sh", | ||
"scripts/95-prep.sh", | ||
"scripts/99-img_check.sh" | ||
] | ||
} | ||
} |