Add support for PSC network attachments and interfaces in modules (#2125)
* support network attachments in net-vpc module * support network attachments in net-address module * fix examples * fix examples * add support for psc interfaces to compute-vm module
This commit is contained in:
committed by
GitHub
parent
ef19524b0b
commit
da68d3cfc4
@@ -25,6 +25,7 @@ In both modes, an optional service account can be created and assigned to either
|
||||
- [Internal and external IPs](#internal-and-external-ips)
|
||||
- [Using Alias IPs](#using-alias-ips)
|
||||
- [Using gVNIC](#using-gvnic)
|
||||
- [PSC interfaces](#psc-interfaces)
|
||||
- [Metadata](#metadata)
|
||||
- [IAM](#iam)
|
||||
- [Spot VM](#spot-vm)
|
||||
@@ -382,6 +383,40 @@ module "vm-with-gvnic" {
|
||||
# tftest modules=1 resources=3 inventory=gvnic.yaml
|
||||
```
|
||||
|
||||
#### PSC interfaces
|
||||
|
||||
[Private Service Connect interfaces](https://cloud.google.com/vpc/docs/about-private-service-connect-interfaces) can be configured via the `network_attached_interfaces` variable, which is a simple list of network attachment ids, one per interface. PSC interfaces will be defined after regular interfaces.
|
||||
|
||||
```hcl
|
||||
|
||||
# create the network attachment from a service project
|
||||
module "net-attachment" {
|
||||
source = "./fabric/modules/net-address"
|
||||
project_id = "prj-svc"
|
||||
network_attachments = {
|
||||
svc-0 = {
|
||||
subnet_self_link = "projects/prj-host/regions/europe-west8/subnetworks/gce"
|
||||
producer_accept_lists = ["my-vm-project"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module "vm-psc-interface" {
|
||||
source = "./fabric/modules/compute-vm"
|
||||
project_id = "my-vm-project"
|
||||
zone = "europe-west8-b"
|
||||
name = "vm-internal-ip"
|
||||
network_interfaces = [{
|
||||
network = "internal"
|
||||
subnetwork = "internal"
|
||||
}]
|
||||
network_attached_interfaces = [
|
||||
module.net-attachment.network_attachment_ids["svc-0"]
|
||||
]
|
||||
}
|
||||
# tftest modules=2 resources=2
|
||||
```
|
||||
|
||||
### Metadata
|
||||
|
||||
You can define labels and custom metadata values. Metadata can be leveraged, for example, to define a custom startup script.
|
||||
@@ -773,9 +808,9 @@ module "sole-tenancy" {
|
||||
| name | description | type | required | default |
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [name](variables.tf#L235) | Instance name. | <code>string</code> | ✓ | |
|
||||
| [network_interfaces](variables.tf#L240) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | <code title="list(object({ network = string subnetwork = string alias_ips = optional(map(string), {}) nat = optional(bool, false) nic_type = optional(string) stack_type = optional(string) addresses = optional(object({ internal = optional(string) external = optional(string) }), null) }))">list(object({…}))</code> | ✓ | |
|
||||
| [project_id](variables.tf#L282) | Project id. | <code>string</code> | ✓ | |
|
||||
| [zone](variables.tf#L380) | Compute zone. | <code>string</code> | ✓ | |
|
||||
| [network_interfaces](variables.tf#L247) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | <code title="list(object({ network = string subnetwork = string alias_ips = optional(map(string), {}) nat = optional(bool, false) nic_type = optional(string) stack_type = optional(string) addresses = optional(object({ internal = optional(string) external = optional(string) }), null) }))">list(object({…}))</code> | ✓ | |
|
||||
| [project_id](variables.tf#L289) | Project id. | <code>string</code> | ✓ | |
|
||||
| [zone](variables.tf#L387) | Compute zone. | <code>string</code> | ✓ | |
|
||||
| [attached_disk_defaults](variables.tf#L17) | Defaults for attached disks options. | <code title="object({ auto_delete = optional(bool, false) mode = string replica_zone = string type = string })">object({…})</code> | | <code title="{ auto_delete = true mode = "READ_WRITE" replica_zone = null type = "pd-balanced" }">{…}</code> |
|
||||
| [attached_disks](variables.tf#L37) | 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. | <code title="list(object({ name = string device_name = optional(string) size = string snapshot_schedule = optional(string) source = optional(string) source_type = optional(string) options = optional( object({ auto_delete = optional(bool, false) mode = optional(string, "READ_WRITE") replica_zone = optional(string) type = optional(string, "pd-balanced") }), { auto_delete = true mode = "READ_WRITE" replica_zone = null type = "pd-balanced" } ) }))">list(object({…}))</code> | | <code>[]</code> |
|
||||
| [boot_disk](variables.tf#L83) | Boot disk properties. | <code title="object({ auto_delete = optional(bool, true) snapshot_schedule = optional(string) source = optional(string) initialize_params = optional(object({ image = optional(string, "projects/debian-cloud/global/images/family/debian-11") size = optional(number, 10) type = optional(string, "pd-balanced") })) use_independent_disk = optional(bool, false) })">object({…})</code> | | <code title="{ initialize_params = {} }">{…}</code> |
|
||||
@@ -793,14 +828,15 @@ module "sole-tenancy" {
|
||||
| [labels](variables.tf#L217) | Instance labels. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [metadata](variables.tf#L223) | Instance metadata. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [min_cpu_platform](variables.tf#L229) | Minimum CPU platform. | <code>string</code> | | <code>null</code> |
|
||||
| [options](variables.tf#L256) | Instance options. | <code title="object({ allow_stopping_for_update = optional(bool, true) deletion_protection = optional(bool, false) node_affinities = optional(map(object({ values = list(string) in = optional(bool, true) })), {}) spot = optional(bool, false) termination_action = optional(string) })">object({…})</code> | | <code title="{ allow_stopping_for_update = true deletion_protection = false spot = false termination_action = null }">{…}</code> |
|
||||
| [scratch_disks](variables.tf#L287) | Scratch disks configuration. | <code title="object({ count = number interface = string })">object({…})</code> | | <code title="{ count = 0 interface = "NVME" }">{…}</code> |
|
||||
| [service_account](variables.tf#L299) | Service account email and scopes. If email is null, the default Compute service account will be used unless auto_create is true, in which case a service account will be created. Set the variable to null to avoid attaching a service account. | <code title="object({ auto_create = optional(bool, false) email = optional(string) scopes = optional(list(string)) })">object({…})</code> | | <code>{}</code> |
|
||||
| [shielded_config](variables.tf#L309) | Shielded VM configuration of the instances. | <code title="object({ enable_secure_boot = bool enable_vtpm = bool enable_integrity_monitoring = bool })">object({…})</code> | | <code>null</code> |
|
||||
| [snapshot_schedules](variables.tf#L319) | Snapshot schedule resource policies that can be attached to disks. | <code title="map(object({ schedule = object({ daily = optional(object({ days_in_cycle = number start_time = string })) hourly = optional(object({ hours_in_cycle = number start_time = string })) weekly = optional(list(object({ day = string start_time = string }))) }) description = optional(string) retention_policy = optional(object({ max_retention_days = number on_source_disk_delete_keep = optional(bool) })) snapshot_properties = optional(object({ chain_name = optional(string) guest_flush = optional(bool) labels = optional(map(string)) storage_locations = optional(list(string)) })) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [tag_bindings](variables.tf#L362) | Resource manager tag bindings for this instance, in tag key => tag value format. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [tag_bindings_firewall](variables.tf#L368) | Firewall (network scoped) tag bindings for this instance, in tag key => tag value format. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [tags](variables.tf#L374) | Instance network tags for firewall rule targets. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [network_attached_interfaces](variables.tf#L240) | Network interfaces using network attachments. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [options](variables.tf#L263) | Instance options. | <code title="object({ allow_stopping_for_update = optional(bool, true) deletion_protection = optional(bool, false) node_affinities = optional(map(object({ values = list(string) in = optional(bool, true) })), {}) spot = optional(bool, false) termination_action = optional(string) })">object({…})</code> | | <code title="{ allow_stopping_for_update = true deletion_protection = false spot = false termination_action = null }">{…}</code> |
|
||||
| [scratch_disks](variables.tf#L294) | Scratch disks configuration. | <code title="object({ count = number interface = string })">object({…})</code> | | <code title="{ count = 0 interface = "NVME" }">{…}</code> |
|
||||
| [service_account](variables.tf#L306) | Service account email and scopes. If email is null, the default Compute service account will be used unless auto_create is true, in which case a service account will be created. Set the variable to null to avoid attaching a service account. | <code title="object({ auto_create = optional(bool, false) email = optional(string) scopes = optional(list(string)) })">object({…})</code> | | <code>{}</code> |
|
||||
| [shielded_config](variables.tf#L316) | Shielded VM configuration of the instances. | <code title="object({ enable_secure_boot = bool enable_vtpm = bool enable_integrity_monitoring = bool })">object({…})</code> | | <code>null</code> |
|
||||
| [snapshot_schedules](variables.tf#L326) | Snapshot schedule resource policies that can be attached to disks. | <code title="map(object({ schedule = object({ daily = optional(object({ days_in_cycle = number start_time = string })) hourly = optional(object({ hours_in_cycle = number start_time = string })) weekly = optional(list(object({ day = string start_time = string }))) }) description = optional(string) retention_policy = optional(object({ max_retention_days = number on_source_disk_delete_keep = optional(bool) })) snapshot_properties = optional(object({ chain_name = optional(string) guest_flush = optional(bool) labels = optional(map(string)) storage_locations = optional(list(string)) })) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [tag_bindings](variables.tf#L369) | Resource manager tag bindings for this instance, in tag key => tag value format. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [tag_bindings_firewall](variables.tf#L375) | Firewall (network scoped) tag bindings for this instance, in tag key => tag value format. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [tags](variables.tf#L381) | Instance network tags for firewall rule targets. | <code>list(string)</code> | | <code>[]</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
||||
@@ -267,6 +267,13 @@ resource "google_compute_instance" "default" {
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "network_interface" {
|
||||
for_each = var.network_attached_interfaces
|
||||
content {
|
||||
network_attachment = network_interface.value
|
||||
}
|
||||
}
|
||||
|
||||
scheduling {
|
||||
automatic_restart = !var.options.spot
|
||||
instance_termination_action = local.termination_action
|
||||
@@ -425,6 +432,13 @@ resource "google_compute_instance_template" "default" {
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "network_interface" {
|
||||
for_each = var.network_attached_interfaces
|
||||
content {
|
||||
network_attachment = network_interface.value
|
||||
}
|
||||
}
|
||||
|
||||
scheduling {
|
||||
automatic_restart = !var.options.spot
|
||||
instance_termination_action = local.termination_action
|
||||
|
||||
@@ -237,6 +237,13 @@ variable "name" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "network_attached_interfaces" {
|
||||
description = "Network interfaces using network attachments."
|
||||
type = list(string)
|
||||
nullable = false
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "network_interfaces" {
|
||||
description = "Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed."
|
||||
type = list(object({
|
||||
|
||||
Reference in New Issue
Block a user