Implement group membership in compute-vm module (#3816)
* implement group membership in compute-vm module * fix newline, update copyright
This commit is contained in:
committed by
GitHub
parent
2fe082f7d1
commit
44d00ed670
@@ -965,6 +965,25 @@ module "instance-group" {
|
||||
# tftest inventory=group.yaml e2e
|
||||
```
|
||||
|
||||
You can also use the `group` variable to add the instance to an existing unmanaged instance group by providing the group's self link or ID in the `membership` field.
|
||||
|
||||
```hcl
|
||||
module "instance-group-membership" {
|
||||
source = "./fabric/modules/compute-vm"
|
||||
project_id = var.project_id
|
||||
zone = "${var.region}-b"
|
||||
name = "ilb-test-member"
|
||||
network_interfaces = [{
|
||||
network = var.vpc.self_link
|
||||
subnetwork = var.subnet.self_link
|
||||
}]
|
||||
group = {
|
||||
membership = "my-existing-group-id"
|
||||
}
|
||||
}
|
||||
# tftest inventory=group-membership.yaml
|
||||
```
|
||||
|
||||
### Instance Schedule and Resource Policies
|
||||
|
||||
One instance start and stop schedule can be defined via the `instance_schedule` variable. Note that this requires [additional permissions on Compute Engine Service Agent](https://cloud.google.com/compute/docs/instances/schedule-instance-start-stop#service_agent_required_roles). Already defined resource policies can be set via the `resource_policies` variable.
|
||||
|
||||
@@ -98,7 +98,7 @@ resource "google_compute_instance_iam_binding" "default" {
|
||||
}
|
||||
|
||||
resource "google_compute_instance_group" "unmanaged" {
|
||||
count = var.group != null && !local.is_template ? 1 : 0
|
||||
count = try(var.group.membership, null) == null && var.group != null && !local.is_template ? 1 : 0
|
||||
project = local.project_id
|
||||
network = (
|
||||
length(var.network_interfaces) > 0
|
||||
@@ -119,6 +119,14 @@ resource "google_compute_instance_group" "unmanaged" {
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_instance_group_membership" "unmanaged" {
|
||||
count = try(var.group.membership, null) != null && !local.is_template ? 1 : 0
|
||||
project = local.project_id
|
||||
zone = local.zone
|
||||
instance = google_compute_instance.default[0].self_link
|
||||
instance_group = var.group.membership
|
||||
}
|
||||
|
||||
resource "google_service_account" "service_account" {
|
||||
count = try(var.service_account.auto_create, null) == true ? 1 : 0
|
||||
project = local.project_id
|
||||
|
||||
Reference in New Issue
Block a user