Allow using a non-suffixed name in compute-vm (#217)
* allow using a non-suffixed name in compute-vm * update README
This commit is contained in:
parent
4c1cbef4be
commit
5149795bec
|
@ -283,6 +283,7 @@ module "instance-group" {
|
|||
| *service_account_create* | Auto-create service account. | <code title="">bool</code> | | <code title="">false</code> |
|
||||
| *service_account_scopes* | Scopes applied to service account. | <code title="list(string)">list(string)</code> | | <code title="">[]</code> |
|
||||
| *shielded_config* | Shielded VM configuration of the instances. | <code title="object({ enable_secure_boot = bool enable_vtpm = bool enable_integrity_monitoring = bool })">object({...})</code> | | <code title="">null</code> |
|
||||
| *single_name* | Do not append progressive count to instance name. | <code title="">bool</code> | | <code title="">false</code> |
|
||||
| *tags* | Instance tags. | <code title="list(string)">list(string)</code> | | <code title="">[]</code> |
|
||||
| *use_instance_template* | Create instance template instead of instances. | <code title="">bool</code> | | <code title="">false</code> |
|
||||
| *zones* | Compute zone, instance will cycle through the list, defaults to the 'b' zone in the region. | <code title="list(string)">list(string)</code> | | <code title="">[]</code> |
|
||||
|
|
|
@ -43,9 +43,13 @@ locals {
|
|||
"${pair.0}/${pair.1}" => { role = pair.0, name = pair.1, members = var.iam[pair.0] }
|
||||
}
|
||||
names = (
|
||||
var.use_instance_template ? { (var.name) = 0 } : {
|
||||
for i in range(0, var.instance_count) : "${var.name}-${i + 1}" => i
|
||||
}
|
||||
var.use_instance_template
|
||||
? { (var.name) = 0 }
|
||||
: (
|
||||
var.single_name && var.instance_count == 1
|
||||
? { (var.name) = 0 }
|
||||
: { for i in range(0, var.instance_count) : "${var.name}-${i + 1}" => i }
|
||||
)
|
||||
)
|
||||
service_account_email = (
|
||||
var.service_account_create
|
||||
|
@ -64,7 +68,7 @@ locals {
|
|||
? [
|
||||
"https://www.googleapis.com/auth/cloud-platform",
|
||||
"https://www.googleapis.com/auth/userinfo.email"
|
||||
]
|
||||
]
|
||||
: [
|
||||
"https://www.googleapis.com/auth/devstorage.read_only",
|
||||
"https://www.googleapis.com/auth/logging.write",
|
||||
|
|
|
@ -230,6 +230,12 @@ variable "service_account_scopes" {
|
|||
default = []
|
||||
}
|
||||
|
||||
variable "single_name" {
|
||||
description = "Do not append progressive count to instance name."
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Instance tags."
|
||||
type = list(string)
|
||||
|
|
|
@ -29,4 +29,5 @@ module "test" {
|
|||
iam = var.iam
|
||||
metadata = var.metadata
|
||||
metadata_list = var.metadata_list
|
||||
single_name = var.single_name
|
||||
}
|
||||
|
|
|
@ -64,12 +64,17 @@ variable "network_interfaces" {
|
|||
}]
|
||||
}
|
||||
|
||||
variable "use_instance_template" {
|
||||
variable "service_account_create" {
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "service_account_create" {
|
||||
variable "single_name" {
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "use_instance_template" {
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
|
|
@ -26,6 +26,13 @@ def test_single_instance(plan_runner):
|
|||
assert resources[0]['type'] == 'google_compute_instance'
|
||||
|
||||
|
||||
def test_single_instance_single_name(plan_runner):
|
||||
_, resources = plan_runner(FIXTURES_DIR, single_name=1)
|
||||
assert len(resources) == 1
|
||||
assert resources[0]['type'] == 'google_compute_instance'
|
||||
assert resources[0]['values']['name'] == 'test'
|
||||
|
||||
|
||||
def test_multiple_instances(plan_runner):
|
||||
_, resources = plan_runner(FIXTURES_DIR, instance_count=2)
|
||||
assert len(resources) == 2
|
||||
|
|
Loading…
Reference in New Issue