Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
201 additions
and
27 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 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,100 @@ | ||
|
||
resource "google_compute_attached_disk" "data" { | ||
depends_on = [ | ||
google_compute_instance.vm_instance, | ||
google_compute_disk.data | ||
] | ||
|
||
disk = google_compute_disk.data.id | ||
instance = google_compute_instance.vm_instance.id | ||
device_name = "mithril-data-disk" | ||
} | ||
|
||
resource "google_compute_disk" "data" { | ||
depends_on = [ | ||
google_compute_instance.vm_instance | ||
] | ||
|
||
name = "${local.environment_name}-data" | ||
type = var.google_compute_instance_data_disk_type | ||
zone = var.google_zone | ||
size = var.google_compute_instance_data_disk_size | ||
image = var.google_compute_instance_data_disk_image | ||
snapshot = var.google_compute_instance_data_disk_snapshot | ||
labels = { | ||
environment = local.environment_name | ||
type = "data" | ||
} | ||
} | ||
|
||
resource "google_compute_resource_policy" "policy-data" { | ||
name = "${local.environment_name}-policy-data" | ||
region = var.google_region | ||
snapshot_schedule_policy { | ||
schedule { | ||
daily_schedule { | ||
days_in_cycle = var.google_compute_instance_data_disk_snapshot_pace_days | ||
start_time = var.google_compute_instance_data_disk_snapshot_start_time | ||
} | ||
} | ||
retention_policy { | ||
max_retention_days = var.google_compute_instance_data_disk_snapshot_max_retention_days | ||
on_source_disk_delete = "KEEP_AUTO_SNAPSHOTS" | ||
} | ||
} | ||
} | ||
|
||
resource "null_resource" "mithril_mount_data_disk" { | ||
depends_on = [ | ||
google_compute_attached_disk.data | ||
] | ||
|
||
triggers = { | ||
attached_disk = google_compute_attached_disk.data.id | ||
} | ||
|
||
connection { | ||
type = "ssh" | ||
user = "root" | ||
private_key = local.google_service_account_private_key | ||
host = google_compute_address.mithril-external-address.address | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
<<-EOT | ||
# Format data disk if necessary | ||
if sudo blkid /dev/sdb; then | ||
echo "Data disk already formatted" | ||
else | ||
# Copy previous data folder if necessary | ||
if [ -d "/home/curry/data" ]; then | ||
echo "Copy previous data folder" | ||
docker kill $(docker container ls -q) | ||
mv /home/curry/data /home/curry/data.copy | ||
fi | ||
# Format data disk | ||
echo "Format data disk" | ||
mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/google-mithril-data-disk | ||
fi | ||
# Mount data disk | ||
echo "Mount data disk" | ||
mkdir -p /home/curry/data | ||
mount -o discard,defaults /dev/disk/by-id/google-mithril-data-disk /home/curry/data | ||
# Restore previous data folder if necessary | ||
if [ -d "/home/curry/data.copy" ]; then | ||
echo "Restore previous data folder" | ||
cp -R /home/curry/data.copy/* /home/curry/data/ | ||
rm -rf /home/curry/data.copy | ||
fi | ||
# Update rights of data directory | ||
chown "curry":"curry" /home/curry/data -R | ||
echo "Data disk mounted!" | ||
EOT | ||
] | ||
} | ||
} |
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 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 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 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 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 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 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