New compute-vm examples and tests

This commit is contained in:
Julio Castillo
2023-02-07 10:54:55 +01:00
parent 8b51d8bbc6
commit 04602353ce
19 changed files with 824 additions and 331 deletions

View File

@@ -0,0 +1,36 @@
# 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-with-alias-ips.google_compute_instance.default[0]:
name: test
network_interface:
- access_config: []
alias_ip_range:
- ip_cidr_range: 10.16.0.10/32
subnetwork_range_name: alias1
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
nic_type: null
queue_count: null
subnetwork: subnet_self_link
project: my-project
zone: europe-west1-b
counts:
google_compute_instance: 1
modules: 1
resources: 1
outputs: {}

View File

@@ -0,0 +1,57 @@
# 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.kms-vm-example.google_compute_disk.disks["attached-disk"]:
disk_encryption_key:
- kms_key_self_link: kms_key_self_link
kms_key_service_account: null
raw_key: null
labels:
disk_name: attached-disk
disk_type: pd-balanced
name: kms-test-attached-disk
project: project-id
size: 10
type: pd-balanced
zone: europe-west1-b
module.kms-vm-example.google_compute_instance.default[0]:
attached_disk:
- device_name: attached-disk
disk_encryption_key_raw: null
mode: READ_WRITE
source: kms-test-attached-disk
boot_disk:
- auto_delete: true
disk_encryption_key_raw: null
initialize_params:
- image: projects/debian-cloud/global/images/family/debian-10
size: 10
type: pd-balanced
kms_key_self_link: kms_key_self_link
mode: READ_WRITE
name: kms-test
zone: europe-west1-b
module.kms-vm-example.google_service_account.service_account[0]:
account_id: tf-vm-kms-test
description: null
disabled: false
display_name: Terraform VM kms-test.
project: project-id
timeouts: null
counts:
google_compute_disk: 1
google_compute_instance: 1
google_service_account: 1

View File

@@ -0,0 +1,31 @@
# 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.template-confidential-example.google_compute_instance_template.default[0]:
confidential_instance_config:
- enable_confidential_compute: true
name_prefix: confidential-template-
project: project-id
region: europe-west1
module.vm-confidential-example.google_compute_instance.default[0]:
confidential_instance_config:
- enable_confidential_compute: true
name: confidential-vm
project: project-id
zone: europe-west1-b
counts:
google_compute_instance: 1
google_compute_instance_template: 1

View File

@@ -0,0 +1,27 @@
# 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.instance-group.google_compute_instance.default[0]: {}
module.instance-group.google_compute_instance_group.unmanaged[0]:
name: ilb-test
named_port: []
network: projects/xxx/global/networks/aaa
project: my-project
timeouts: null
zone: europe-west1-b
counts:
google_compute_instance: 1
google_compute_instance_group: 1

View File

@@ -0,0 +1,43 @@
# 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:
google_compute_image.cos-gvnic:
guest_os_features:
- type: GVNIC
- type: SEV_CAPABLE
- type: UEFI_COMPATIBLE
- type: VIRTIO_SCSI_MULTIQUEUE
name: my-image
project: my-project
source_image: https://www.googleapis.com/compute/v1/projects/cos-cloud/global/images/cos-89-16108-534-18
module.vm-with-gvnic.google_compute_instance.default[0]:
name: test
network_interface:
- access_config: []
alias_ip_range: []
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
nic_type: GVNIC
queue_count: null
subnetwork: subnet_self_link
project: my-project
zone: europe-west1-b
counts:
google_compute_image: 1
google_compute_instance: 1
google_service_account: 1
modules: 1
resources: 3

View File

@@ -0,0 +1,34 @@
# 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-iam-example.google_compute_instance.default[0]:
name: webserver
module.vm-iam-example.google_compute_instance_iam_binding.default["roles/compute.instanceAdmin"]:
condition: []
instance_name: webserver
members:
- group:admin@example.com
- group:webserver@example.com
project: project-id
role: roles/compute.instanceAdmin
zone: europe-west1-b
counts:
google_compute_instance: 1
google_compute_instance_iam_binding: 1
modules: 1
resources: 2
outputs: {}

View File

@@ -0,0 +1,45 @@
# 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-external-ip.google_compute_instance.default[0]:
name: vm-external-ip
network_interface:
- access_config:
- nat_ip: 8.8.8.8
public_ptr_domain_name: null
alias_ip_range: []
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
nic_type: null
queue_count: null
subnetwork: subnet_self_link
project: my-project
zone: europe-west1-b
module.vm-internal-ip.google_compute_instance.default[0]:
name: vm-internal-ip
network_interface:
- access_config: []
alias_ip_range: []
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
network_ip: 10.0.0.2
nic_type: null
queue_count: null
subnetwork: subnet_self_link
project: my-project
zone: europe-west1-b
counts:
google_compute_instance: 2

View File

@@ -0,0 +1,32 @@
# 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-metadata-example.google_compute_instance.default[0]:
metadata:
startup-script: |
#! /bin/bash
apt-get update
apt-get install -y nginx
name: nginx-server
project: project-id
zone: europe-west1-b
labels:
env: dev
system: crm
module.vm-metadata-example.google_service_account.service_account[0]: {}
counts:
google_compute_instance: 1
google_service_account: 1

View File

@@ -0,0 +1,49 @@
# 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-default-sa-example2.google_compute_instance.default[0]:
name: test3
project: project-id
service_account:
- scopes:
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring.write
zone: europe-west1-b
module.vm-managed-sa-example.google_compute_instance.default[0]:
name: test1
project: project-id
service_account:
- scopes:
- https://www.googleapis.com/auth/cloud-platform
- https://www.googleapis.com/auth/userinfo.email
zone: europe-west1-b
module.vm-managed-sa-example.google_service_account.service_account[0]:
account_id: tf-vm-test1
display_name: Terraform VM test1.
project: project-id
module.vm-managed-sa-example2.google_compute_instance.default[0]:
name: test2
project: project-id
service_account:
- scopes:
- https://www.googleapis.com/auth/cloud-platform
zone: europe-west1-b
counts:
google_compute_instance: 3
google_service_account: 1
modules: 3
resources: 4

View File

@@ -0,0 +1,72 @@
# 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.simple-vm-example.google_compute_instance.default[0]:
advanced_machine_features: []
allow_stopping_for_update: true
attached_disk: []
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
can_ip_forward: false
deletion_protection: false
description: Managed by the compute-vm Terraform module.
enable_display: false
hostname: null
labels: null
machine_type: f1-micro
metadata: null
metadata_startup_script: null
name: test
network_interface:
- access_config: []
alias_ip_range: []
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
nic_type: null
queue_count: null
subnetwork: subnet_self_link
project: project-id
scheduling:
- automatic_restart: true
instance_termination_action: null
max_run_duration: []
min_node_cpus: null
node_affinities: []
on_host_maintenance: MIGRATE
preemptible: false
provisioning_model: STANDARD
scratch_disk: []
service_account:
- scopes:
- https://www.googleapis.com/auth/cloud-platform
- https://www.googleapis.com/auth/userinfo.email
shielded_instance_config: []
tags: null
zone: europe-west1-b
module.simple-vm-example.google_service_account.service_account[0]:
account_id: tf-vm-test
display_name: Terraform VM test.
project: project-id
counts:
google_compute_instance: 1
google_service_account: 1

View File

@@ -0,0 +1,31 @@
# 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.spot-vm-example.google_compute_instance.default[0]:
name: test
project: project-id
scheduling:
- automatic_restart: false
instance_termination_action: STOP
max_run_duration: []
min_node_cpus: null
node_affinities: []
on_host_maintenance: TERMINATE
preemptible: true
provisioning_model: SPOT
zone: europe-west1-b
counts:
google_compute_instance: 1

View File

@@ -0,0 +1,65 @@
# 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.cos-test.google_compute_instance_template.default[0]:
disk:
- auto_delete: true
boot: true
disk_encryption_key: []
disk_name: null
disk_size_gb: 10
disk_type: pd-balanced
labels: null
resource_policies: null
source: null
source_image: projects/cos-cloud/global/images/family/cos-stable
source_image_encryption_key: []
source_snapshot: null
source_snapshot_encryption_key: []
- auto_delete: true
device_name: disk-1
disk_encryption_key: []
disk_name: disk-1
disk_size_gb: 10
disk_type: pd-balanced
labels: null
mode: READ_WRITE
resource_policies: null
source: null
source_image_encryption_key: []
source_snapshot: null
source_snapshot_encryption_key: []
type: PERSISTENT
name_prefix: test-
network_interface:
- access_config: []
alias_ip_range: []
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
network_ip: null
nic_type: null
queue_count: null
subnetwork: subnet_self_link
project: my-project
region: europe-west1
service_account:
- email: vm-default@my-project.iam.gserviceaccount.com
scopes:
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring.write
counts:
google_compute_instance_template: 1

View File

@@ -1,31 +0,0 @@
/**
* Copyright 2022 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.
*/
module "test" {
source = "../../../../modules/compute-vm"
project_id = "my-project"
zone = "europe-west1-b"
name = "test"
attached_disks = var.attached_disks
attached_disk_defaults = var.attached_disk_defaults
create_template = var.create_template
confidential_compute = var.confidential_compute
group = var.group
iam = var.iam
metadata = var.metadata
network_interfaces = var.network_interfaces
service_account_create = var.service_account_create
}

View File

@@ -1,70 +0,0 @@
/**
* Copyright 2022 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.
*/
variable "attached_disks" {
description = "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."
type = any
default = []
}
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"
}
}
variable "confidential_compute" {
type = bool
default = false
}
variable "create_template" {
type = bool
default = false
}
variable "group" {
type = any
default = null
}
variable "iam" {
type = map(set(string))
default = {}
}
variable "metadata" {
type = map(string)
default = {}
}
variable "network_interfaces" {
type = any
default = [{
network = "https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default",
subnetwork = "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/subnetworks/default-default",
}]
}
variable "service_account_create" {
type = bool
default = false
}

View File

@@ -1,77 +0,0 @@
# Copyright 2022 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.
def test_defaults(plan_runner):
_, resources = plan_runner()
assert len(resources) == 1
assert resources[0]['type'] == 'google_compute_instance'
def test_service_account(plan_runner):
_, resources = plan_runner(service_account_create='true')
assert len(resources) == 2
assert set(r['type'] for r in resources) == set([
'google_compute_instance', 'google_service_account'
])
def test_template(plan_runner):
_, resources = plan_runner(create_template='true')
assert len(resources) == 1
assert resources[0]['type'] == 'google_compute_instance_template'
assert resources[0]['values']['name_prefix'] == 'test-'
def test_group(plan_runner):
_, resources = plan_runner(group='{named_ports={}}')
assert len(resources) == 2
assert set(r['type'] for r in resources) == set([
'google_compute_instance_group', 'google_compute_instance'
])
def test_iam(plan_runner):
iam = (
'{"roles/compute.instanceAdmin" = ["user:a@a.com", "user:b@a.com"],'
'"roles/iam.serviceAccountUser" = ["user:a@a.com"]}'
)
_, resources = plan_runner(iam=iam)
assert len(resources) == 3
assert set(r['type'] for r in resources) == set([
'google_compute_instance', 'google_compute_instance_iam_binding'])
iam_bindings = dict(
(r['index'], r['values']['members']) for r in resources if r['type']
== 'google_compute_instance_iam_binding'
)
assert iam_bindings == {
'roles/compute.instanceAdmin': ['user:a@a.com', 'user:b@a.com'],
'roles/iam.serviceAccountUser': ['user:a@a.com'],
}
def test_confidential_compute(plan_runner):
_, resources = plan_runner(confidential_compute='true')
assert len(resources) == 1
assert resources[0]['values']['confidential_instance_config'] == [
{'enable_confidential_compute': True}]
assert resources[0]['values']['scheduling'][0]['on_host_maintenance'] == 'TERMINATE'
def test_confidential_compute_template(plan_runner):
_, resources = plan_runner(confidential_compute='true',
create_template='true')
assert len(resources) == 1
assert resources[0]['values']['confidential_instance_config'] == [
{'enable_confidential_compute': True}]
assert resources[0]['values']['scheduling'][0]['on_host_maintenance'] == 'TERMINATE'

View File

@@ -1,4 +1,4 @@
# Copyright 2022 Google LLC
# 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.
@@ -14,7 +14,7 @@
def test_types(plan_runner):
_disks = '''[{
_disks = '''[{
name = "data1"
size = "10"
source_type = "image"
@@ -34,35 +34,53 @@ 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"
source = "image-1"
options = null
}, {
name = "data2"
size = "20"
source_type = "snapshot"
source = "snapshot-2"
options = null
}, {
name = "data3"
size = null
source_type = "attach"
source = "disk-3"
}
{
name = "data1"
size = "10"
source_type = "image"
@@ -80,26 +98,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"
@@ -117,17 +135,18 @@ 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 = '''[{
_disks = '''[{
name = "data1"
size = "10"
options = {
@@ -147,19 +166,20 @@ def test_auto_delete(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]
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
_, 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

View File

@@ -1,42 +0,0 @@
# Copyright 2022 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.
def test_address(plan_runner):
nics = '''[{
network = "https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default",
subnetwork = "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/subnetworks/default-default",
nat = false,
addresses = {external=null, internal="10.0.0.2"}
}]
'''
_, resources = plan_runner(network_interfaces=nics)
assert len(resources) == 1
n = resources[0]['values']['network_interface'][0]
assert n['network_ip'] == "10.0.0.2"
assert n['access_config'] == []
def test_nat_address(plan_runner):
nics = '''[{
network = "https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default",
subnetwork = "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/subnetworks/default-default",
nat = true,
addresses = {external="8.8.8.8", internal=null}
}]
'''
_, resources = plan_runner(network_interfaces=nics)
assert len(resources) == 1
n = resources[0]['values']['network_interface'][0]
assert 'network_ip' not in n
assert n['access_config'][0]['nat_ip'] == '8.8.8.8'