Add Disk examples
This commit is contained in:
@@ -100,9 +100,9 @@ module "vm-default-sa-example2" {
|
||||
|
||||
Attached disks can be created and optionally initialized from a pre-existing source, or attached to VMs when pre-existing. The `source` and `source_type` attributes of the `attached_disks` variable allows several modes of operation:
|
||||
|
||||
- `source_type = "image"` can be used with zonal disks in instances and templates, set `source` to the image name or link
|
||||
- `source_type = "snapshot"` can be used with instances only, set `source` to the snapshot name or link
|
||||
- `source_type = "attach"` can be used for both instances and templates to attach an existing disk, set source to the name (for zonal disks) or link (for regional disks) of the existing disk to attach; no disk will be created
|
||||
- `source_type = "image"` can be used with zonal disks in instances and templates, set `source` to the image name or self link
|
||||
- `source_type = "snapshot"` can be used with instances only, set `source` to the snapshot name or self link
|
||||
- `source_type = "attach"` can be used for both instances and templates to attach an existing disk, set source to the name (for zonal disks) or self link (for regional disks) of the existing disk to attach; no disk will be created
|
||||
- `source_type = null` can be used where an empty disk is needed, `source` becomes irrelevant and can be left null
|
||||
|
||||
This is an example of attaching a pre-existing regional PD to a new instance:
|
||||
@@ -158,6 +158,47 @@ module "vm-disks-example" {
|
||||
# tftest modules=1 resources=2
|
||||
```
|
||||
|
||||
#### Disk types and options
|
||||
|
||||
The `attached_disks` variable exposes an `option` attribute that can be used to fine tune the configuration of each disk. The following example shows a VM with multiple disks
|
||||
|
||||
```hcl
|
||||
module "vm-disk-options-example" {
|
||||
source = "./fabric/modules/compute-vm"
|
||||
project_id = var.project_id
|
||||
zone = "europe-west1-b"
|
||||
name = "test"
|
||||
network_interfaces = [{
|
||||
network = var.vpc.self_link
|
||||
subnetwork = var.subnet.self_link
|
||||
}]
|
||||
attached_disks = [
|
||||
{
|
||||
name = "data1"
|
||||
size = "10"
|
||||
source_type = "image"
|
||||
source = "image-1"
|
||||
options = {
|
||||
auto_delete = false
|
||||
replica_zone = "europe-west1-c"
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "data2"
|
||||
size = "20"
|
||||
source_type = "snapshot"
|
||||
source = "snapshot-2"
|
||||
options = {
|
||||
type = "pd-ssd"
|
||||
mode = "READ_ONLY"
|
||||
}
|
||||
}
|
||||
]
|
||||
service_account_create = true
|
||||
}
|
||||
# tftest modules=1 resources=4 inventory=disk-options.yaml
|
||||
```
|
||||
|
||||
### Network interfaces
|
||||
|
||||
#### Internal and external IPs
|
||||
|
||||
59
tests/modules/compute_vm/examples/disk-options.yaml
Normal file
59
tests/modules/compute_vm/examples/disk-options.yaml
Normal file
@@ -0,0 +1,59 @@
|
||||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
values:
|
||||
module.vm-disk-options-example.google_compute_disk.disks["data2"]:
|
||||
name: test-data2
|
||||
project: project-id
|
||||
size: 20
|
||||
snapshot: snapshot-2
|
||||
type: pd-ssd
|
||||
zone: europe-west1-b
|
||||
module.vm-disk-options-example.google_compute_instance.default[0]:
|
||||
attached_disk:
|
||||
- device_name: data2
|
||||
disk_encryption_key_raw: null
|
||||
mode: READ_ONLY
|
||||
source: test-data2
|
||||
- device_name: data1
|
||||
disk_encryption_key_raw: null
|
||||
mode: READ_WRITE
|
||||
source: test-data1
|
||||
boot_disk:
|
||||
- auto_delete: true
|
||||
disk_encryption_key_raw: null
|
||||
initialize_params:
|
||||
- image: projects/debian-cloud/global/images/family/debian-11
|
||||
size: 10
|
||||
type: pd-balanced
|
||||
mode: READ_WRITE
|
||||
description: Managed by the compute-vm Terraform module.
|
||||
name: test
|
||||
project: project-id
|
||||
zone: europe-west1-b
|
||||
module.vm-disk-options-example.google_compute_region_disk.disks["data1"]:
|
||||
name: test-data1
|
||||
project: project-id
|
||||
region: europe-west1
|
||||
replica_zones:
|
||||
- europe-west1-b
|
||||
- europe-west1-c
|
||||
size: 10
|
||||
type: pd-balanced
|
||||
|
||||
counts:
|
||||
google_compute_disk: 1
|
||||
google_compute_instance: 1
|
||||
google_compute_region_disk: 1
|
||||
google_service_account: 1
|
||||
Reference in New Issue
Block a user