|
| 1 | +# Generate a packer build for an AMI (Amazon Image) |
| 2 | + |
| 3 | +packer { |
| 4 | + required_plugins { |
| 5 | + googlecompute = { |
| 6 | + version = "= 1.1.3" |
| 7 | + source = "github.com/hashicorp/googlecompute" |
| 8 | + } |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +variable "enable_secure_boot" { |
| 13 | + type = bool |
| 14 | + default = true |
| 15 | +} |
| 16 | + |
| 17 | +variable "machine_architecture" { |
| 18 | + type = string |
| 19 | + default = "x86-64" |
| 20 | +} |
| 21 | + |
| 22 | +variable "machine_type" { |
| 23 | + type = string |
| 24 | + default = "c2-standard-16" |
| 25 | +} |
| 26 | + |
| 27 | +variable "project_id" { |
| 28 | + type = string |
| 29 | + default = "llnl-flux" |
| 30 | +} |
| 31 | + |
| 32 | +variable "builder_service_account" { |
| 33 | + type = string |
| 34 | + default = "llnl-flux" |
| 35 | +} |
| 36 | + |
| 37 | +# gcloud compute images describe-from-family rocky-linux-8-optimized-gcp --project=rocky-linux-cloud |
| 38 | +variable "source_image" { |
| 39 | + type = string |
| 40 | + default = "rocky-linux-8-optimized-gcp-v20240709" |
| 41 | +} |
| 42 | + |
| 43 | +variable "source_image_project_id" { |
| 44 | + type = string |
| 45 | + default = "rocky-linux-cloud" |
| 46 | +} |
| 47 | + |
| 48 | +variable "subnetwork" { |
| 49 | + type = string |
| 50 | + default = "default" |
| 51 | +} |
| 52 | + |
| 53 | +variable "zone" { |
| 54 | + type = string |
| 55 | + default = "us-central1-a" |
| 56 | +} |
| 57 | + |
| 58 | +# "timestamp" template function replacement for image naming |
| 59 | +# This is so us of the future can remember when images were built |
| 60 | +locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } |
| 61 | + |
| 62 | +source "googlecompute" "flux-framework" { |
| 63 | + project_id = var.project_id |
| 64 | + source_image = var.source_image |
| 65 | + source_image_project_id = [var.source_image_project_id] |
| 66 | + zone = var.zone |
| 67 | + image_name = "flux-framework-${var.machine_architecture}-v{{timestamp}}" |
| 68 | + image_family = "flux-framework-${var.machine_architecture}" |
| 69 | + image_description = "flux-framework" |
| 70 | + machine_type = var.machine_type |
| 71 | + disk_size = 256 |
| 72 | + subnetwork = var.subnetwork |
| 73 | + tags = ["packer", "flux-framework", "${var.machine_architecture}"] |
| 74 | + startup_script_file = "build.sh" |
| 75 | + ssh_username = "rocky" |
| 76 | + # IMPORTANT: you need to generate this |
| 77 | + # account_file = "packer-build.key" |
| 78 | + # impersonate_service_account = var.builder_service_account |
| 79 | + enable_secure_boot = var.enable_secure_boot |
| 80 | +} |
| 81 | + |
| 82 | +build { |
| 83 | + sources = ["sources.googlecompute.flux-framework"] |
| 84 | +} |
0 commit comments