Add auto_delete and instance_redistribution_type to compute-vm and compute-mig modules. (#890)
* Add auto_delete parameter to compute-vm module * Add instance_redistribution_type in compute-mig module
This commit is contained in:
parent
ccac507795
commit
ca1dc3659a
|
@ -262,13 +262,14 @@ module "mig-proxy" {
|
|||
metric = var.autoscaling_metric
|
||||
}
|
||||
update_policy = {
|
||||
type = "PROACTIVE"
|
||||
minimal_action = "REPLACE"
|
||||
min_ready_sec = 60
|
||||
max_surge_type = "fixed"
|
||||
max_surge = 3
|
||||
max_unavailable_type = null
|
||||
max_unavailable = null
|
||||
instance_redistribution_type = "PROACTIVE"
|
||||
max_surge_type = "fixed"
|
||||
max_surge = 3
|
||||
max_unavailable_type = null
|
||||
max_unavailable = null
|
||||
minimal_action = "REPLACE"
|
||||
min_ready_sec = 60
|
||||
type = "PROACTIVE"
|
||||
}
|
||||
default_version = {
|
||||
instance_template = module.proxy-vm.template.self_link
|
||||
|
|
|
@ -340,7 +340,7 @@ module "nginx-mig" {
|
|||
per_instance_config = {},
|
||||
mig_config = {
|
||||
stateful_disks = {
|
||||
persistent-disk-1 = {
|
||||
repd-1 = {
|
||||
delete_rule = "NEVER"
|
||||
}
|
||||
}
|
||||
|
@ -461,9 +461,9 @@ module "nginx-mig" {
|
|||
| [stateful_config](variables.tf#L90) | Stateful configuration can be done by individual instances or for all instances in the MIG. They key in per_instance_config is the name of the specific instance. The key of the stateful_disks is the 'device_name' field of the resource. Please note that device_name is defined at the OS mount level, unlike the disk name. | <code title="object({ per_instance_config = map(object({ stateful_disks = map(object({ source = string mode = string # READ_WRITE | READ_ONLY delete_rule = string # NEVER | ON_PERMANENT_INSTANCE_DELETION })) metadata = map(string) update_config = object({ minimal_action = string # NONE | REPLACE | RESTART | REFRESH most_disruptive_allowed_action = string # REPLACE | RESTART | REFRESH | NONE remove_instance_state_on_destroy = bool }) })) mig_config = object({ stateful_disks = map(object({ delete_rule = string # NEVER | ON_PERMANENT_INSTANCE_DELETION })) }) })">object({…})</code> | | <code>null</code> |
|
||||
| [target_pools](variables.tf#L121) | Optional list of URLs for target pools to which new instances in the group are added. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [target_size](variables.tf#L127) | Group target size, leave null when using an autoscaler. | <code>number</code> | | <code>null</code> |
|
||||
| [update_policy](variables.tf#L133) | Update policy. Type can be 'OPPORTUNISTIC' or 'PROACTIVE', action 'REPLACE' or 'restart', surge type 'fixed' or 'percent'. | <code title="object({ type = string # OPPORTUNISTIC | PROACTIVE minimal_action = string # REPLACE | RESTART min_ready_sec = number max_surge_type = string # fixed | percent max_surge = number max_unavailable_type = string max_unavailable = number })">object({…})</code> | | <code>null</code> |
|
||||
| [versions](variables.tf#L147) | Additional application versions, target_type is either 'fixed' or 'percent'. | <code title="map(object({ instance_template = string target_type = string # fixed | percent target_size = number }))">map(object({…}))</code> | | <code>null</code> |
|
||||
| [wait_for_instances](variables.tf#L157) | Wait for all instances to be created/updated before returning. | <code>bool</code> | | <code>null</code> |
|
||||
| [update_policy](variables.tf#L133) | Update policy. Type can be 'OPPORTUNISTIC' or 'PROACTIVE', action 'REPLACE' or 'restart', surge type 'fixed' or 'percent'. | <code title="object({ instance_redistribution_type = optional(string, "PROACTIVE") # NONE | PROACTIVE. The attribute is ignored if regional is set to false. max_surge_type = string # fixed | percent max_surge = number max_unavailable_type = string max_unavailable = number minimal_action = string # REPLACE | RESTART min_ready_sec = number type = string # OPPORTUNISTIC | PROACTIVE })">object({…})</code> | | <code>null</code> |
|
||||
| [versions](variables.tf#L148) | Additional application versions, target_type is either 'fixed' or 'percent'. | <code title="map(object({ instance_template = string target_type = string # fixed | percent target_size = number }))">map(object({…}))</code> | | <code>null</code> |
|
||||
| [wait_for_instances](variables.tf#L158) | Wait for all instances to be created/updated before returning. | <code>bool</code> | | <code>null</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
|
|
@ -264,9 +264,10 @@ resource "google_compute_region_instance_group_manager" "default" {
|
|||
for_each = var.update_policy == null ? [] : [var.update_policy]
|
||||
iterator = config
|
||||
content {
|
||||
type = config.value.type
|
||||
minimal_action = config.value.minimal_action
|
||||
min_ready_sec = config.value.min_ready_sec
|
||||
instance_redistribution_type = config.value.instance_redistribution_type
|
||||
type = config.value.type
|
||||
minimal_action = config.value.minimal_action
|
||||
min_ready_sec = config.value.min_ready_sec
|
||||
max_surge_fixed = (
|
||||
config.value.max_surge_type == "fixed" ? config.value.max_surge : null
|
||||
)
|
||||
|
|
|
@ -133,13 +133,14 @@ variable "target_size" {
|
|||
variable "update_policy" {
|
||||
description = "Update policy. Type can be 'OPPORTUNISTIC' or 'PROACTIVE', action 'REPLACE' or 'restart', surge type 'fixed' or 'percent'."
|
||||
type = object({
|
||||
type = string # OPPORTUNISTIC | PROACTIVE
|
||||
minimal_action = string # REPLACE | RESTART
|
||||
min_ready_sec = number
|
||||
max_surge_type = string # fixed | percent
|
||||
max_surge = number
|
||||
max_unavailable_type = string
|
||||
max_unavailable = number
|
||||
instance_redistribution_type = optional(string, "PROACTIVE") # NONE | PROACTIVE. The attribute is ignored if regional is set to false.
|
||||
max_surge_type = string # fixed | percent
|
||||
max_surge = number
|
||||
max_unavailable_type = string
|
||||
max_unavailable = number
|
||||
minimal_action = string # REPLACE | RESTART
|
||||
min_ready_sec = number
|
||||
type = string # OPPORTUNISTIC | PROACTIVE
|
||||
})
|
||||
default = null
|
||||
}
|
||||
|
|
|
@ -278,34 +278,34 @@ module "instance-group" {
|
|||
|
||||
| name | description | type | required | default |
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [name](variables.tf#L163) | Instance name. | <code>string</code> | ✓ | |
|
||||
| [network_interfaces](variables.tf#L168) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | <code title="list(object({ nat = optional(bool, false) network = string subnetwork = string addresses = optional(object({ internal = string external = string }), null) alias_ips = optional(map(string), {}) nic_type = optional(string) }))">list(object({…}))</code> | ✓ | |
|
||||
| [project_id](variables.tf#L205) | Project id. | <code>string</code> | ✓ | |
|
||||
| [zone](variables.tf#L264) | Compute zone. | <code>string</code> | ✓ | |
|
||||
| [attached_disk_defaults](variables.tf#L17) | Defaults for attached disks options. | <code title="object({ mode = string replica_zone = string type = string })">object({…})</code> | | <code title="{ mode = "READ_WRITE" replica_zone = null type = "pd-balanced" }">{…}</code> |
|
||||
| [attached_disks](variables.tf#L31) | Additional disks, if options is null defaults will be used in its place. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null. | <code title="list(object({ name = string size = string source = optional(string) source_type = optional(string) options = optional( object({ mode = optional(string, "READ_WRITE") replica_zone = optional(string) type = optional(string, "pd-balanced") }), { mode = "READ_WRITE" replica_zone = null type = "pd-balanced" } ) }))">list(object({…}))</code> | | <code>[]</code> |
|
||||
| [boot_disk](variables.tf#L64) | Boot disk properties. | <code title="object({ auto_delete = optional(bool, true) image = optional(string, "projects/debian-cloud/global/images/family/debian-11") size = optional(number, 10) type = optional(string, "pd-balanced") })">object({…})</code> | | <code title="{ auto_delete = true image = "projects/debian-cloud/global/images/family/debian-11" type = "pd-balanced" size = 10 }">{…}</code> |
|
||||
| [can_ip_forward](variables.tf#L80) | Enable IP forwarding. | <code>bool</code> | | <code>false</code> |
|
||||
| [confidential_compute](variables.tf#L86) | Enable Confidential Compute for these instances. | <code>bool</code> | | <code>false</code> |
|
||||
| [create_template](variables.tf#L92) | Create instance template instead of instances. | <code>bool</code> | | <code>false</code> |
|
||||
| [description](variables.tf#L97) | Description of a Compute Instance. | <code>string</code> | | <code>"Managed by the compute-vm Terraform module."</code> |
|
||||
| [enable_display](variables.tf#L103) | Enable virtual display on the instances. | <code>bool</code> | | <code>false</code> |
|
||||
| [encryption](variables.tf#L109) | Encryption options. Only one of kms_key_self_link and disk_encryption_key_raw may be set. If needed, you can specify to encrypt or not the boot disk. | <code title="object({ encrypt_boot = optional(bool, false) disk_encryption_key_raw = optional(string) kms_key_self_link = optional(string) })">object({…})</code> | | <code>null</code> |
|
||||
| [group](variables.tf#L119) | Define this variable to create an instance group for instances. Disabled for template use. | <code title="object({ named_ports = map(number) })">object({…})</code> | | <code>null</code> |
|
||||
| [hostname](variables.tf#L127) | Instance FQDN name. | <code>string</code> | | <code>null</code> |
|
||||
| [iam](variables.tf#L133) | IAM bindings in {ROLE => [MEMBERS]} format. | <code>map(list(string))</code> | | <code>{}</code> |
|
||||
| [instance_type](variables.tf#L139) | Instance type. | <code>string</code> | | <code>"f1-micro"</code> |
|
||||
| [labels](variables.tf#L145) | Instance labels. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [metadata](variables.tf#L151) | Instance metadata. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [min_cpu_platform](variables.tf#L157) | Minimum CPU platform. | <code>string</code> | | <code>null</code> |
|
||||
| [options](variables.tf#L183) | Instance options. | <code title="object({ allow_stopping_for_update = optional(bool, true) deletion_protection = optional(bool, false) spot = optional(bool, false) termination_action = optional(string) })">object({…})</code> | | <code title="{ allow_stopping_for_update = true deletion_protection = false spot = false termination_action = null }">{…}</code> |
|
||||
| [scratch_disks](variables.tf#L210) | Scratch disks configuration. | <code title="object({ count = number interface = string })">object({…})</code> | | <code title="{ count = 0 interface = "NVME" }">{…}</code> |
|
||||
| [service_account](variables.tf#L222) | Service account email. Unused if service account is auto-created. | <code>string</code> | | <code>null</code> |
|
||||
| [service_account_create](variables.tf#L228) | Auto-create service account. | <code>bool</code> | | <code>false</code> |
|
||||
| [service_account_scopes](variables.tf#L236) | Scopes applied to service account. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [shielded_config](variables.tf#L242) | Shielded VM configuration of the instances. | <code title="object({ enable_secure_boot = bool enable_vtpm = bool enable_integrity_monitoring = bool })">object({…})</code> | | <code>null</code> |
|
||||
| [tag_bindings](variables.tf#L252) | Tag bindings for this instance, in key => tag value id format. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [tags](variables.tf#L258) | Instance network tags for firewall rule targets. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [name](variables.tf#L180) | Instance name. | <code>string</code> | ✓ | |
|
||||
| [network_interfaces](variables.tf#L185) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | <code title="list(object({ nat = optional(bool, false) network = string subnetwork = string addresses = optional(object({ internal = string external = string }), null) alias_ips = optional(map(string), {}) nic_type = optional(string) }))">list(object({…}))</code> | ✓ | |
|
||||
| [project_id](variables.tf#L222) | Project id. | <code>string</code> | ✓ | |
|
||||
| [zone](variables.tf#L281) | Compute zone. | <code>string</code> | ✓ | |
|
||||
| [attached_disk_defaults](variables.tf#L17) | Defaults for attached disks options. | <code title="object({ auto_delete = optional(bool, false) mode = string replica_zone = string type = string })">object({…})</code> | | <code title="{ auto_delete = true mode = "READ_WRITE" replica_zone = null type = "pd-balanced" }">{…}</code> |
|
||||
| [attached_disks](variables.tf#L38) | Additional disks, if options is null defaults will be used in its place. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null. | <code title="list(object({ name = string size = string source = optional(string) source_type = optional(string) options = optional( object({ auto_delete = optional(bool, false) mode = optional(string, "READ_WRITE") replica_zone = optional(string) type = optional(string, "pd-balanced") }), { auto_delete = true mode = "READ_WRITE" replica_zone = null type = "pd-balanced" } ) }))">list(object({…}))</code> | | <code>[]</code> |
|
||||
| [boot_disk](variables.tf#L81) | Boot disk properties. | <code title="object({ auto_delete = optional(bool, true) image = optional(string, "projects/debian-cloud/global/images/family/debian-11") size = optional(number, 10) type = optional(string, "pd-balanced") })">object({…})</code> | | <code title="{ auto_delete = true image = "projects/debian-cloud/global/images/family/debian-11" type = "pd-balanced" size = 10 }">{…}</code> |
|
||||
| [can_ip_forward](variables.tf#L97) | Enable IP forwarding. | <code>bool</code> | | <code>false</code> |
|
||||
| [confidential_compute](variables.tf#L103) | Enable Confidential Compute for these instances. | <code>bool</code> | | <code>false</code> |
|
||||
| [create_template](variables.tf#L109) | Create instance template instead of instances. | <code>bool</code> | | <code>false</code> |
|
||||
| [description](variables.tf#L114) | Description of a Compute Instance. | <code>string</code> | | <code>"Managed by the compute-vm Terraform module."</code> |
|
||||
| [enable_display](variables.tf#L120) | Enable virtual display on the instances. | <code>bool</code> | | <code>false</code> |
|
||||
| [encryption](variables.tf#L126) | Encryption options. Only one of kms_key_self_link and disk_encryption_key_raw may be set. If needed, you can specify to encrypt or not the boot disk. | <code title="object({ encrypt_boot = optional(bool, false) disk_encryption_key_raw = optional(string) kms_key_self_link = optional(string) })">object({…})</code> | | <code>null</code> |
|
||||
| [group](variables.tf#L136) | Define this variable to create an instance group for instances. Disabled for template use. | <code title="object({ named_ports = map(number) })">object({…})</code> | | <code>null</code> |
|
||||
| [hostname](variables.tf#L144) | Instance FQDN name. | <code>string</code> | | <code>null</code> |
|
||||
| [iam](variables.tf#L150) | IAM bindings in {ROLE => [MEMBERS]} format. | <code>map(list(string))</code> | | <code>{}</code> |
|
||||
| [instance_type](variables.tf#L156) | Instance type. | <code>string</code> | | <code>"f1-micro"</code> |
|
||||
| [labels](variables.tf#L162) | Instance labels. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [metadata](variables.tf#L168) | Instance metadata. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [min_cpu_platform](variables.tf#L174) | Minimum CPU platform. | <code>string</code> | | <code>null</code> |
|
||||
| [options](variables.tf#L200) | Instance options. | <code title="object({ allow_stopping_for_update = optional(bool, true) deletion_protection = optional(bool, false) spot = optional(bool, false) termination_action = optional(string) })">object({…})</code> | | <code title="{ allow_stopping_for_update = true deletion_protection = false spot = false termination_action = null }">{…}</code> |
|
||||
| [scratch_disks](variables.tf#L227) | Scratch disks configuration. | <code title="object({ count = number interface = string })">object({…})</code> | | <code title="{ count = 0 interface = "NVME" }">{…}</code> |
|
||||
| [service_account](variables.tf#L239) | Service account email. Unused if service account is auto-created. | <code>string</code> | | <code>null</code> |
|
||||
| [service_account_create](variables.tf#L245) | Auto-create service account. | <code>bool</code> | | <code>false</code> |
|
||||
| [service_account_scopes](variables.tf#L253) | Scopes applied to service account. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [shielded_config](variables.tf#L259) | Shielded VM configuration of the instances. | <code title="object({ enable_secure_boot = bool enable_vtpm = bool enable_integrity_monitoring = bool })">object({…})</code> | | <code>null</code> |
|
||||
| [tag_bindings](variables.tf#L269) | Tag bindings for this instance, in key => tag value id format. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [tags](variables.tf#L275) | Instance network tags for firewall rule targets. | <code>list(string)</code> | | <code>[]</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
|
|
@ -284,7 +284,7 @@ resource "google_compute_instance_template" "default" {
|
|||
for_each = local.attached_disks
|
||||
iterator = config
|
||||
content {
|
||||
# auto_delete = config.value.options.auto_delete
|
||||
auto_delete = config.value.options.auto_delete
|
||||
device_name = config.value.name
|
||||
# Cannot use `source` with any of the fields in
|
||||
# [disk_size_gb disk_name disk_type source_image labels]
|
||||
|
|
|
@ -17,15 +17,22 @@
|
|||
variable "attached_disk_defaults" {
|
||||
description = "Defaults for attached disks options."
|
||||
type = object({
|
||||
auto_delete = optional(bool, false)
|
||||
mode = string
|
||||
replica_zone = string
|
||||
type = string
|
||||
})
|
||||
default = {
|
||||
auto_delete = true
|
||||
mode = "READ_WRITE"
|
||||
replica_zone = null
|
||||
type = "pd-balanced"
|
||||
}
|
||||
|
||||
validation {
|
||||
condition = var.attached_disk_defaults.mode == "READ_WRITE" || !var.attached_disk_defaults.auto_delete
|
||||
error_message = "auto_delete can only be specified on READ_WRITE disks."
|
||||
}
|
||||
}
|
||||
|
||||
variable "attached_disks" {
|
||||
|
@ -37,11 +44,13 @@ variable "attached_disks" {
|
|||
source_type = optional(string)
|
||||
options = optional(
|
||||
object({
|
||||
auto_delete = optional(bool, false)
|
||||
mode = optional(string, "READ_WRITE")
|
||||
replica_zone = optional(string)
|
||||
type = optional(string, "pd-balanced")
|
||||
}),
|
||||
{
|
||||
auto_delete = true
|
||||
mode = "READ_WRITE"
|
||||
replica_zone = null
|
||||
type = "pd-balanced"
|
||||
|
@ -59,6 +68,14 @@ variable "attached_disks" {
|
|||
]) == length(var.attached_disks)
|
||||
error_message = "Source type must be one of 'image', 'snapshot', 'attach', null."
|
||||
}
|
||||
|
||||
validation {
|
||||
condition = length([
|
||||
for d in var.attached_disks : d if d.options == null ||
|
||||
d.options.mode == "READ_WRITE" || !d.options.auto_delete
|
||||
]) == length(var.attached_disks)
|
||||
error_message = "auto_delete can only be specified on READ_WRITE disks."
|
||||
}
|
||||
}
|
||||
|
||||
variable "boot_disk" {
|
||||
|
|
|
@ -24,6 +24,7 @@ variable "attached_disk_defaults" {
|
|||
description = "Defaults for attached disks options."
|
||||
type = any
|
||||
default = {
|
||||
auto_delete = true
|
||||
mode = "READ_WRITE"
|
||||
replica_zone = null
|
||||
type = "pd-balanced"
|
||||
|
|
|
@ -12,8 +12,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
def test_types(plan_runner):
|
||||
_disks = '''[{
|
||||
_disks = '''[{
|
||||
name = "data1"
|
||||
size = "10"
|
||||
source_type = "image"
|
||||
|
@ -33,26 +34,35 @@ def test_types(plan_runner):
|
|||
options = null
|
||||
}]
|
||||
'''
|
||||
_, resources = plan_runner(attached_disks=_disks)
|
||||
assert len(resources) == 3
|
||||
disks = {r['values']['name']: r['values']
|
||||
for r in resources if r['type'] == 'google_compute_disk'}
|
||||
assert disks['test-data1']['size'] == 10
|
||||
assert disks['test-data2']['size'] == 20
|
||||
assert disks['test-data1']['image'] == 'image-1'
|
||||
assert disks['test-data1']['snapshot'] is None
|
||||
assert disks['test-data2']['snapshot'] == 'snapshot-2'
|
||||
assert disks['test-data2']['image'] is None
|
||||
instance = [r['values']
|
||||
for r in resources if r['type'] == 'google_compute_instance'][0]
|
||||
instance_disks = {d['source']: d['device_name']
|
||||
for d in instance['attached_disk']}
|
||||
assert instance_disks == {'test-data1': 'data1',
|
||||
'test-data2': 'data2', 'disk-3': 'data3'}
|
||||
_, resources = plan_runner(attached_disks=_disks)
|
||||
assert len(resources) == 3
|
||||
disks = {
|
||||
r['values']['name']: r['values']
|
||||
for r in resources if r['type'] == 'google_compute_disk'
|
||||
}
|
||||
assert disks['test-data1']['size'] == 10
|
||||
assert disks['test-data2']['size'] == 20
|
||||
assert disks['test-data1']['image'] == 'image-1'
|
||||
assert disks['test-data1']['snapshot'] is None
|
||||
assert disks['test-data2']['snapshot'] == 'snapshot-2'
|
||||
assert disks['test-data2']['image'] is None
|
||||
instance = [
|
||||
r['values'] for r in resources
|
||||
if r['type'] == 'google_compute_instance'
|
||||
][0]
|
||||
instance_disks = {
|
||||
d['source']: d['device_name']
|
||||
for d in instance['attached_disk']
|
||||
}
|
||||
assert instance_disks == {
|
||||
'test-data1': 'data1',
|
||||
'test-data2': 'data2',
|
||||
'disk-3': 'data3'
|
||||
}
|
||||
|
||||
|
||||
def test_options(plan_runner):
|
||||
_disks = '''[{
|
||||
_disks = '''[{
|
||||
name = "data1"
|
||||
size = "10"
|
||||
source_type = "image"
|
||||
|
@ -70,21 +80,26 @@ def test_options(plan_runner):
|
|||
}
|
||||
}]
|
||||
'''
|
||||
_, resources = plan_runner(attached_disks=_disks)
|
||||
assert len(resources) == 3
|
||||
disks_z = [r['values']
|
||||
for r in resources if r['type'] == 'google_compute_disk']
|
||||
disks_r = [r['values']
|
||||
for r in resources if r['type'] == 'google_compute_region_disk']
|
||||
assert len(disks_z) == len(disks_r) == 1
|
||||
instance = [r['values']
|
||||
for r in resources if r['type'] == 'google_compute_instance'][0]
|
||||
instance_disks = [d['device_name'] for d in instance['attached_disk']]
|
||||
assert instance_disks == ['data1', 'data2']
|
||||
_, resources = plan_runner(attached_disks=_disks)
|
||||
assert len(resources) == 3
|
||||
disks_z = [
|
||||
r['values'] for r in resources if r['type'] == 'google_compute_disk'
|
||||
]
|
||||
disks_r = [
|
||||
r['values'] for r in resources
|
||||
if r['type'] == 'google_compute_region_disk'
|
||||
]
|
||||
assert len(disks_z) == len(disks_r) == 1
|
||||
instance = [
|
||||
r['values'] for r in resources
|
||||
if r['type'] == 'google_compute_instance'
|
||||
][0]
|
||||
instance_disks = [d['device_name'] for d in instance['attached_disk']]
|
||||
assert instance_disks == ['data1', 'data2']
|
||||
|
||||
|
||||
def test_template(plan_runner):
|
||||
_disks = '''[{
|
||||
_disks = '''[{
|
||||
name = "data1"
|
||||
size = "10"
|
||||
source_type = "image"
|
||||
|
@ -102,9 +117,49 @@ def test_template(plan_runner):
|
|||
}
|
||||
}]
|
||||
'''
|
||||
_, resources = plan_runner(attached_disks=_disks,
|
||||
create_template="true")
|
||||
assert len(resources) == 1
|
||||
template = [r['values'] for r in resources if r['type']
|
||||
== 'google_compute_instance_template'][0]
|
||||
assert len(template['disk']) == 3
|
||||
_, resources = plan_runner(attached_disks=_disks, create_template="true")
|
||||
assert len(resources) == 1
|
||||
template = [
|
||||
r['values'] for r in resources
|
||||
if r['type'] == 'google_compute_instance_template'
|
||||
][0]
|
||||
assert len(template['disk']) == 3
|
||||
|
||||
|
||||
def test_auto_delete(plan_runner):
|
||||
_disks = '''[{
|
||||
name = "data1"
|
||||
size = "10"
|
||||
options = {
|
||||
auto_delete = true, mode = "READ_WRITE"
|
||||
}
|
||||
}, {
|
||||
name = "data2"
|
||||
size = "20"
|
||||
options = {
|
||||
auto_delete = false, mode = "READ_WRITE"
|
||||
},
|
||||
}, {
|
||||
name = "data3"
|
||||
size = "20"
|
||||
options = {
|
||||
mode = "READ_ONLY"
|
||||
}
|
||||
}]
|
||||
'''
|
||||
_, resources = plan_runner(attached_disks=_disks, create_template="true")
|
||||
assert len(resources) == 1
|
||||
template = [
|
||||
r['values'] for r in resources
|
||||
if r['type'] == 'google_compute_instance_template'
|
||||
][0]
|
||||
additional_disks = [
|
||||
d for d in template['disk'] if 'boot' not in d or d['boot'] != True
|
||||
]
|
||||
assert len(additional_disks) == 3
|
||||
disk_data1 = [d for d in additional_disks if d['disk_name'] == 'data1']
|
||||
disk_data2 = [d for d in additional_disks if d['disk_name'] == 'data2']
|
||||
disk_data3 = [d for d in additional_disks if d['disk_name'] == 'data3']
|
||||
assert len(disk_data1) == 1 and disk_data1[0]['auto_delete'] == True
|
||||
assert len(disk_data2) == 1 and disk_data2[0]['auto_delete'] == False
|
||||
assert len(disk_data3) == 1 and disk_data3[0]['auto_delete'] == False
|
||||
|
|
Loading…
Reference in New Issue