File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,19 @@ resource "google_compute_health_check" "tcp_check" {
105105 }
106106}
107107
108+ # Create a persistent boot disk for the VM
109+ resource "google_compute_disk" "vm_boot_disk" {
110+ name = " ${ var . vm_name } -boot-disk"
111+ type = " pd-standard"
112+ zone = var. zone
113+ image = " ubuntu-2204-lts"
114+ size = 20
115+
116+ lifecycle {
117+ prevent_destroy = true
118+ }
119+ }
120+
108121# Create the compute instance
109122resource "google_compute_instance" "server" {
110123 name = var. vm_name
@@ -115,9 +128,8 @@ resource "google_compute_instance" "server" {
115128 allow_stopping_for_update = true
116129
117130 boot_disk {
118- initialize_params {
119- image = " ubuntu-2204-lts"
120- }
131+ source = google_compute_disk. vm_boot_disk . id
132+ auto_delete = false # Important: Prevents disk deletion with VM
121133 }
122134
123135 network_interface {
You can’t perform that action at this time.
0 commit comments