Skip to content

Commit

Permalink
feat: add support for adding additional network interfaces (#199)
Browse files Browse the repository at this point in the history
* Additional Network Interface Support

* Update README.md with params

* Fixing Lint Errors

* Fixing Lint Errors

Co-authored-by: Stenal P Jolly <[email protected]>
  • Loading branch information
stenalpjolly and stenalpjolly authored Aug 2, 2021
1 parent f654b1d commit ea44b89
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/instance_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
|------|-------------|------|---------|:--------:|
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | <pre>list(object({<br> nat_ip = string<br> network_tier = string<br> }))</pre> | `[]` | no |
| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#disk_name | <pre>list(object({<br> disk_name = string<br> device_name = string<br> auto_delete = bool<br> boot = bool<br> disk_size_gb = number<br> disk_type = string<br> disk_labels = map(string)<br> }))</pre> | `[]` | no |
| additional\_networks | Additional network interface details for GCE, if any. | <pre>list(object({<br> network = string<br> subnetwork = string<br> subnetwork_project = string<br> network_ip = string<br> access_config = list(object({<br> nat_ip = string<br> network_tier = string<br> }))<br> }))</pre> | `[]` | no |
| auto\_delete | Whether or not the boot disk should be auto-deleted | `string` | `"true"` | no |
| can\_ip\_forward | Enable IP forwarding, for NAT instances for example | `string` | `"false"` | no |
| disk\_encryption\_key | The self link of the encryption key that is stored in Google Cloud KMS to use to encrypt all the disks on this instance | `string` | `null` | no |
Expand Down
17 changes: 17 additions & 0 deletions modules/instance_template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ resource "google_compute_instance_template" "tpl" {
}
}

dynamic "network_interface" {
for_each = var.additional_networks
content {
network = network_interface.value.network
subnetwork = network_interface.value.subnetwork
subnetwork_project = network_interface.value.subnetwork_project
network_ip = length(network_interface.value.network_ip) > 0 ? network_interface.value.network_ip : null
dynamic "access_config" {
for_each = network_interface.value.access_config
content {
nat_ip = access_config.value.nat_ip
network_tier = access_config.value.network_tier
}
}
}
}

lifecycle {
create_before_destroy = "true"
}
Expand Down
15 changes: 15 additions & 0 deletions modules/instance_template/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ variable "network_ip" {
default = ""
}

variable "additional_networks" {
description = "Additional network interface details for GCE, if any."
default = []
type = list(object({
network = string
subnetwork = string
subnetwork_project = string
network_ip = string
access_config = list(object({
nat_ip = string
network_tier = string
}))
}))
}

###########
# metadata
###########
Expand Down
1 change: 1 addition & 0 deletions modules/umig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | <pre>list(list(object({<br> nat_ip = string<br> network_tier = string<br> })))</pre> | `[]` | no |
| additional\_networks | Additional network interface details for GCE, if any. | <pre>list(object({<br> network = string<br> subnetwork = string<br> subnetwork_project = string<br> network_ip = string<br> access_config = list(object({<br> nat_ip = string<br> network_tier = string<br> }))<br> }))</pre> | `[]` | no |
| hostname | Hostname of instances | `string` | `""` | no |
| instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes |
| named\_ports | Named name and named port | <pre>list(object({<br> name = string<br> port = number<br> }))</pre> | `[]` | no |
Expand Down
17 changes: 17 additions & 0 deletions modules/umig/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ resource "google_compute_instance_from_template" "compute_instance" {
}
}

dynamic "network_interface" {
for_each = var.additional_networks
content {
network = network_interface.value.network
subnetwork = network_interface.value.subnetwork
subnetwork_project = network_interface.value.subnetwork_project
network_ip = length(network_interface.value.network_ip) > 0 ? network_interface.value.network_ip : null
dynamic "access_config" {
for_each = network_interface.value.access_config
content {
nat_ip = access_config.value.nat_ip
network_tier = access_config.value.network_tier
}
}
}
}

source_instance_template = var.instance_template
}

Expand Down
15 changes: 15 additions & 0 deletions modules/umig/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ variable "subnetwork_project" {
default = ""
}

variable "additional_networks" {
description = "Additional network interface details for GCE, if any."
default = []
type = list(object({
network = string
subnetwork = string
subnetwork_project = string
network_ip = string
access_config = list(object({
nat_ip = string
network_tier = string
}))
}))
}

variable "hostname" {
description = "Hostname of instances"
default = ""
Expand Down

0 comments on commit ea44b89

Please sign in to comment.