{# terraback/templates/gcp/compute/gcp_disk.tf.j2 #}
{% for disk in resources %}
resource "google_compute_disk" "{{ disk.name_sanitized }}" {
  name     = "{{ disk.name }}"
  type     = "{{ disk.type }}"
  zone     = "{{ disk.zone }}"
  size     = {{ disk.size_gb }}
  project  = "{{ disk.project }}"
  {%- if disk.image %}
  image    = "{{ disk.image }}"
  {%- endif %}
  {%- if disk.labels %}
  labels = {
    {%- for key, value in disk.labels.items() %}
    {{ key }} = "{{ value }}"
    {%- endfor %}
  }
  {%- endif %}

  {%- if disk.disk_encryption_key %}
  disk_encryption_key {
    {%- if disk.disk_encryption_key.raw_key %}
    raw_key = "{{ disk.disk_encryption_key.raw_key }}"
    {%- endif %}
    {%- if disk.disk_encryption_key.kms_key_self_link %}
    kms_key_self_link = "{{ disk.disk_encryption_key.kms_key_self_link }}"
    {%- endif %}
  }
  {%- endif %}

  lifecycle {
    prevent_destroy = true
  }
}
{% endfor %}
