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:
Ludovico Magnocavallo 2021-03-31 20:01:10 +02:00 committed by GitHub
parent 4c1cbef4be
commit 5149795bec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 6 deletions

View File

@ -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&#40;string&#41;">list(string)</code> | | <code title="">[]</code> |
| *shielded_config* | Shielded VM configuration of the instances. | <code title="object&#40;&#123;&#10;enable_secure_boot &#61; bool&#10;enable_vtpm &#61; bool&#10;enable_integrity_monitoring &#61; bool&#10;&#125;&#41;">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&#40;string&#41;">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&#40;string&#41;">list(string)</code> | | <code title="">[]</code> |

View File

@ -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",

View File

@ -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)

View File

@ -29,4 +29,5 @@ module "test" {
iam = var.iam
metadata = var.metadata
metadata_list = var.metadata_list
single_name = var.single_name
}

View File

@ -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
}

View File

@ -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