|
| 1 | +variable "ami" { |
| 2 | + type = string |
| 3 | + default = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-arm64-server-*" |
| 4 | +} |
| 5 | + |
| 6 | +variable "profile" { |
| 7 | + type = string |
| 8 | + default = "${env("AWS_PROFILE")}" |
| 9 | +} |
| 10 | + |
| 11 | +variable "ami_name" { |
| 12 | + type = string |
| 13 | + default = "supabase-postgres" |
| 14 | +} |
| 15 | + |
| 16 | +variable "ami_regions" { |
| 17 | + type = list(string) |
| 18 | + default = ["ap-southeast-2"] |
| 19 | +} |
| 20 | + |
| 21 | +variable "ansible_arguments" { |
| 22 | + type = string |
| 23 | + default = "--skip-tags,install-postgrest,--skip-tags,install-pgbouncer,--skip-tags,install-supabase-internal,ebssurrogate_mode='true'" |
| 24 | +} |
| 25 | + |
| 26 | +variable "aws_access_key" { |
| 27 | + type = string |
| 28 | + default = "" |
| 29 | +} |
| 30 | + |
| 31 | +variable "aws_secret_key" { |
| 32 | + type = string |
| 33 | + default = "" |
| 34 | +} |
| 35 | + |
| 36 | +variable "environment" { |
| 37 | + type = string |
| 38 | + default = "prod" |
| 39 | +} |
| 40 | + |
| 41 | +variable "region" { |
| 42 | + type = string |
| 43 | +} |
| 44 | + |
| 45 | +variable "build-vol" { |
| 46 | + type = string |
| 47 | + default = "xvdc" |
| 48 | +} |
| 49 | + |
| 50 | +# ccache docker image details |
| 51 | +variable "docker_user" { |
| 52 | + type = string |
| 53 | + default = "" |
| 54 | +} |
| 55 | + |
| 56 | +variable "docker_passwd" { |
| 57 | + type = string |
| 58 | + default = "" |
| 59 | +} |
| 60 | + |
| 61 | +variable "docker_image" { |
| 62 | + type = string |
| 63 | + default = "" |
| 64 | +} |
| 65 | + |
| 66 | +variable "docker_image_tag" { |
| 67 | + type = string |
| 68 | + default = "latest" |
| 69 | +} |
| 70 | + |
| 71 | +locals { |
| 72 | + creator = "packer" |
| 73 | +} |
| 74 | + |
| 75 | +variable "postgres-version" { |
| 76 | + type = string |
| 77 | + default = "" |
| 78 | +} |
| 79 | + |
| 80 | +# source block |
| 81 | +source "amazon-ebssurrogate" "source" { |
| 82 | + profile = "${var.profile}" |
| 83 | + #access_key = "${var.aws_access_key}" |
| 84 | + #ami_name = "${var.ami_name}-arm64-${formatdate("YYYY-MM-DD-hhmm", timestamp())}" |
| 85 | + ami_name = "${var.ami_name}-${var.postgres-version}" |
| 86 | + ami_virtualization_type = "hvm" |
| 87 | + ami_architecture = "arm64" |
| 88 | + ami_regions = "${var.ami_regions}" |
| 89 | + instance_type = "t4g.2xlarge" |
| 90 | + region = "${var.region}" |
| 91 | + #secret_key = "${var.aws_secret_key}" |
| 92 | + |
| 93 | + # Use latest official ubuntu focal ami owned by Canonical. |
| 94 | + source_ami_filter { |
| 95 | + filters = { |
| 96 | + virtualization-type = "hvm" |
| 97 | + name = "${var.ami}" |
| 98 | + root-device-type = "ebs" |
| 99 | + } |
| 100 | + owners = [ "099720109477" ] |
| 101 | + most_recent = true |
| 102 | + } |
| 103 | + ena_support = true |
| 104 | + launch_block_device_mappings { |
| 105 | + device_name = "/dev/xvdf" |
| 106 | + delete_on_termination = true |
| 107 | + volume_size = 10 |
| 108 | + volume_type = "gp3" |
| 109 | + } |
| 110 | + |
| 111 | + launch_block_device_mappings { |
| 112 | + device_name = "/dev/${var.build-vol}" |
| 113 | + delete_on_termination = true |
| 114 | + volume_size = 16 |
| 115 | + volume_type = "gp2" |
| 116 | + omit_from_artifact = true |
| 117 | + } |
| 118 | + |
| 119 | + run_tags = { |
| 120 | + creator = "packer" |
| 121 | + appType = "postgres" |
| 122 | + } |
| 123 | + run_volume_tags = { |
| 124 | + creator = "packer" |
| 125 | + appType = "postgres" |
| 126 | + } |
| 127 | + snapshot_tags = { |
| 128 | + creator = "packer" |
| 129 | + appType = "postgres" |
| 130 | + } |
| 131 | + tags = { |
| 132 | + creator = "packer" |
| 133 | + appType = "postgres" |
| 134 | + } |
| 135 | + |
| 136 | + communicator = "ssh" |
| 137 | + ssh_pty = true |
| 138 | + ssh_username = "ubuntu" |
| 139 | + ssh_timeout = "5m" |
| 140 | + |
| 141 | + ami_root_device { |
| 142 | + source_device_name = "/dev/xvdf" |
| 143 | + device_name = "/dev/xvda" |
| 144 | + delete_on_termination = true |
| 145 | + volume_size = 10 |
| 146 | + volume_type = "gp2" |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +# a build block invokes sources and runs provisioning steps on them. |
| 151 | +build { |
| 152 | + sources = ["source.amazon-ebssurrogate.source"] |
| 153 | + |
| 154 | + provisioner "file" { |
| 155 | + source = "ebssurrogate/files/sources-arm64.cfg" |
| 156 | + destination = "/tmp/sources.list" |
| 157 | + } |
| 158 | + |
| 159 | + provisioner "file" { |
| 160 | + source = "ebssurrogate/files/ebsnvme-id" |
| 161 | + destination = "/tmp/ebsnvme-id" |
| 162 | + } |
| 163 | + |
| 164 | + provisioner "file" { |
| 165 | + source = "ebssurrogate/files/70-ec2-nvme-devices.rules" |
| 166 | + destination = "/tmp/70-ec2-nvme-devices.rules" |
| 167 | + } |
| 168 | + |
| 169 | + provisioner "file" { |
| 170 | + source = "ebssurrogate/scripts/chroot-bootstrap.sh" |
| 171 | + destination = "/tmp/chroot-bootstrap.sh" |
| 172 | + } |
| 173 | + |
| 174 | + provisioner "file" { |
| 175 | + source = "ebssurrogate/files/cloud.cfg" |
| 176 | + destination = "/tmp/cloud.cfg" |
| 177 | + } |
| 178 | + |
| 179 | + provisioner "file" { |
| 180 | + source = "ebssurrogate/files/vector.timer" |
| 181 | + destination = "/tmp/vector.timer" |
| 182 | + } |
| 183 | + |
| 184 | + # Copy ansible playbook |
| 185 | + provisioner "shell" { |
| 186 | + inline = ["mkdir /tmp/ansible-playbook"] |
| 187 | + } |
| 188 | + |
| 189 | + provisioner "file" { |
| 190 | + source = "ansible" |
| 191 | + destination = "/tmp/ansible-playbook" |
| 192 | + } |
| 193 | + |
| 194 | + provisioner "file" { |
| 195 | + source = "scripts" |
| 196 | + destination = "/tmp/ansible-playbook" |
| 197 | + } |
| 198 | + |
| 199 | + provisioner "shell" { |
| 200 | + environment_vars = [ |
| 201 | + "ARGS=${var.ansible_arguments}", |
| 202 | + "DOCKER_USER=${var.docker_user}", |
| 203 | + "DOCKER_PASSWD=${var.docker_passwd}", |
| 204 | + "DOCKER_IMAGE=${var.docker_image}", |
| 205 | + "DOCKER_IMAGE_TAG=${var.docker_image_tag}" |
| 206 | + ] |
| 207 | + script = "ebssurrogate/scripts/surrogate-bootstrap.sh" |
| 208 | + execute_command = "sudo -S sh -c '{{ .Vars }} {{ .Path }}'" |
| 209 | + start_retry_timeout = "5m" |
| 210 | + skip_clean = true |
| 211 | + } |
| 212 | + |
| 213 | + provisioner "file" { |
| 214 | + source = "/tmp/ansible.log" |
| 215 | + destination = "/tmp/ansible.log" |
| 216 | + direction = "download" |
| 217 | + } |
| 218 | +} |
0 commit comments