Skip to content

Commit ea44b89

Browse files
authored
feat: add support for adding additional network interfaces (#199)
* Additional Network Interface Support * Update README.md with params * Fixing Lint Errors * Fixing Lint Errors Co-authored-by: Stenal P Jolly <[email protected]>
1 parent f654b1d commit ea44b89

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

modules/instance_template/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
1515
|------|-------------|------|---------|:--------:|
1616
| 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 |
1717
| 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 |
18+
| 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 |
1819
| auto\_delete | Whether or not the boot disk should be auto-deleted | `string` | `"true"` | no |
1920
| can\_ip\_forward | Enable IP forwarding, for NAT instances for example | `string` | `"false"` | no |
2021
| 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 |

modules/instance_template/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,23 @@ resource "google_compute_instance_template" "tpl" {
112112
}
113113
}
114114

115+
dynamic "network_interface" {
116+
for_each = var.additional_networks
117+
content {
118+
network = network_interface.value.network
119+
subnetwork = network_interface.value.subnetwork
120+
subnetwork_project = network_interface.value.subnetwork_project
121+
network_ip = length(network_interface.value.network_ip) > 0 ? network_interface.value.network_ip : null
122+
dynamic "access_config" {
123+
for_each = network_interface.value.access_config
124+
content {
125+
nat_ip = access_config.value.nat_ip
126+
network_tier = access_config.value.network_tier
127+
}
128+
}
129+
}
130+
}
131+
115132
lifecycle {
116133
create_before_destroy = "true"
117134
}

modules/instance_template/variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,21 @@ variable "network_ip" {
153153
default = ""
154154
}
155155

156+
variable "additional_networks" {
157+
description = "Additional network interface details for GCE, if any."
158+
default = []
159+
type = list(object({
160+
network = string
161+
subnetwork = string
162+
subnetwork_project = string
163+
network_ip = string
164+
access_config = list(object({
165+
nat_ip = string
166+
network_tier = string
167+
}))
168+
}))
169+
}
170+
156171
###########
157172
# metadata
158173
###########

modules/umig/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ See the [simple](https://github.com/terraform-google-modules/terraform-google-vm
1616
| Name | Description | Type | Default | Required |
1717
|------|-------------|------|---------|:--------:|
1818
| 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 |
19+
| 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 |
1920
| hostname | Hostname of instances | `string` | `""` | no |
2021
| instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes |
2122
| named\_ports | Named name and named port | <pre>list(object({<br> name = string<br> port = number<br> }))</pre> | `[]` | no |

modules/umig/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ resource "google_compute_instance_from_template" "compute_instance" {
6666
}
6767
}
6868

69+
dynamic "network_interface" {
70+
for_each = var.additional_networks
71+
content {
72+
network = network_interface.value.network
73+
subnetwork = network_interface.value.subnetwork
74+
subnetwork_project = network_interface.value.subnetwork_project
75+
network_ip = length(network_interface.value.network_ip) > 0 ? network_interface.value.network_ip : null
76+
dynamic "access_config" {
77+
for_each = network_interface.value.access_config
78+
content {
79+
nat_ip = access_config.value.nat_ip
80+
network_tier = access_config.value.network_tier
81+
}
82+
}
83+
}
84+
}
85+
6986
source_instance_template = var.instance_template
7087
}
7188

modules/umig/variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ variable "subnetwork_project" {
4040
default = ""
4141
}
4242

43+
variable "additional_networks" {
44+
description = "Additional network interface details for GCE, if any."
45+
default = []
46+
type = list(object({
47+
network = string
48+
subnetwork = string
49+
subnetwork_project = string
50+
network_ip = string
51+
access_config = list(object({
52+
nat_ip = string
53+
network_tier = string
54+
}))
55+
}))
56+
}
57+
4358
variable "hostname" {
4459
description = "Hostname of instances"
4560
default = ""

0 commit comments

Comments
 (0)