Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/secure-env-vars/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module "atlantis" {
command = ["/home/atlantis/custom-entrypoint.sh"]
args = ["server"]

startup_script = templatefile("${path.module}/custom-entrypoint.sh.tftpl", {
startup_script = templatefile("${path.module}/startup-script.sh.tftpl", {
cloud_sdk_version = "455.0.0"
app_key_secret_name = local.secret_names.app_key
app_id_secret_name = local.secret_names.app_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

set -e

mkdir -p ${mount_folder}
# cloud-init executes after the startup script, so we need to wait until the disk is mounted
timeout 1m bash -c "until /bin/findmnt -t ext4 -T ${mount_folder}; do sleep 1; done"

# if timeout failed, print msg
if [ $? -ne 0 ]; then
echo "Error: Disk not mounted at ${mount_folder} within timeout period"
echo "Please rerun this script: 'google_metadata_script_runner startup'"
fi

chown 100 ${mount_folder}
cat <<'EOF' > "${mount_folder}/${entrypoint_filename}"
#!/bin/bash
Expand Down
19 changes: 19 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ data "cloudinit_config" "config" {
gzip = false
base64_encode = false

part {
# https://docs.cloud.google.com/compute/docs/disks/format-mount-disk-linux
# https://docs.cloud.google.com/container-optimized-os/docs/concepts/disks-and-filesystem#mounting_and_formatting_disks
filename = "bootcmd"
content_type = "text/cloud-config"
merge_type = "list(append)+dict(no_replace, recurse_list)+str()"
content = yamlencode({
bootcmd = [
# Format disk if not already formatted
"/sbin/blkid /dev/disk/by-id/google-${local.atlantis_persistent_disk_name} --probe --match-types ext4 || mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/google-${local.atlantis_persistent_disk_name}",
# Check and repair filesystem
"/sbin/fsck.ext4 -tvy /dev/disk/by-id/google-${local.atlantis_persistent_disk_name}",
# Create mount point and mount the disk
"mkdir -p ${local.atlantis_disk_mount_path}",
"mount -t ext4 -o discard,defaults /dev/disk/by-id/google-${local.atlantis_persistent_disk_name} ${local.atlantis_disk_mount_path}"
]
})
}

part {
filename = "runcmda"
content_type = "text/cloud-config"
Expand Down