Support multiple zones in compute-vm module (#114)
* support multiple zones in compute-vm module * update compute-vm variables in end-to-end examples * update README examples
This commit is contained in:
committed by
GitHub
parent
1c77ff214e
commit
dce2fca740
@@ -18,7 +18,7 @@ module "test" {
|
||||
source = "../../../../modules/compute-vm"
|
||||
project_id = "my-project"
|
||||
region = "europe-west1"
|
||||
zone = "europe-west1-b"
|
||||
zones = var.zones
|
||||
name = "test"
|
||||
network_interfaces = var.network_interfaces
|
||||
service_account_create = var.service_account_create
|
||||
|
||||
@@ -61,3 +61,8 @@ variable "service_account_create" {
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "zones" {
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
|
||||
68
tests/modules/compute_vm/test_plan_zones.py
Normal file
68
tests/modules/compute_vm/test_plan_zones.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# Copyright 2020 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.
|
||||
|
||||
|
||||
import os
|
||||
import pytest
|
||||
|
||||
|
||||
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'fixture')
|
||||
|
||||
|
||||
def test_default(plan_runner):
|
||||
_, resources = plan_runner(FIXTURES_DIR)
|
||||
assert resources[0]['values']['zone'] == 'europe-west1-b'
|
||||
|
||||
|
||||
def test_multiple_default(plan_runner):
|
||||
_, resources = plan_runner(FIXTURES_DIR, instance_count=2)
|
||||
assert set(r['values']['zone'] for r in resources) == set(['europe-west1-b'])
|
||||
|
||||
|
||||
def test_custom(plan_runner):
|
||||
_, resources = plan_runner(FIXTURES_DIR, zones='["a", "b"]')
|
||||
assert resources[0]['values']['zone'] == 'a'
|
||||
|
||||
|
||||
def test_custom_default(plan_runner):
|
||||
_, resources = plan_runner(
|
||||
FIXTURES_DIR, instance_count=3, zones='["a", "b"]')
|
||||
assert [r['values']['zone'] for r in resources] == ['a', 'b', 'a']
|
||||
|
||||
|
||||
def test_group(plan_runner):
|
||||
_, resources = plan_runner(FIXTURES_DIR, instance_count=2,
|
||||
group='{named_ports={}}', zones='["a", "b"]')
|
||||
assert resources[2]['type'] == 'google_compute_instance_group'
|
||||
assert resources[2]['values']['zone'] == 'a'
|
||||
|
||||
|
||||
def test_iam(plan_runner):
|
||||
iam_roles = '["roles/a", "roles/b"]'
|
||||
iam_members = '{"roles/a" = ["user:a@a.com"], "roles/b" = ["user:a@a.com"]}'
|
||||
_, resources = plan_runner(FIXTURES_DIR, instance_count=3,
|
||||
iam_roles=iam_roles, iam_members=iam_members,
|
||||
zones='["a", "b"]')
|
||||
iam_bindings = dict(
|
||||
(r['index'], r['values']['zone']) for r in resources if r['type']
|
||||
== 'google_compute_instance_iam_binding'
|
||||
)
|
||||
assert iam_bindings == {
|
||||
'roles/a/test-1': 'a',
|
||||
'roles/a/test-2': 'b',
|
||||
'roles/a/test-3': 'a',
|
||||
'roles/b/test-1': 'a',
|
||||
'roles/b/test-2': 'b',
|
||||
'roles/b/test-3': 'a',
|
||||
}
|
||||
Reference in New Issue
Block a user