Skip to content

Commit dde01ff

Browse files
authored
feat: Add support for assigning public IPs directly to instances. (#83)
1 parent b3b27d0 commit dde01ff

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

examples/compute_instance/simple/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This is a simple, minimal example of how to use the compute_instance module
77

88
| Name | Description | Type | Default | Required |
99
|------|-------------|:----:|:-----:|:-----:|
10+
| nat\_ip | Public ip address | string | `"null"` | no |
11+
| network\_tier | Network network_tier | string | `"PREMIUM"` | no |
1012
| num\_instances | Number of instances to create | string | n/a | yes |
1113
| project\_id | The GCP project to use for integration tests | string | n/a | yes |
1214
| region | The GCP region to create and test resources in | string | `"us-central1"` | no |

examples/compute_instance/simple/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ module "compute_instance" {
3434
num_instances = var.num_instances
3535
hostname = "instance-simple"
3636
instance_template = module.instance_template.self_link
37+
access_config = [{
38+
nat_ip = var.nat_ip
39+
network_tier = var.network_tier
40+
}, ]
3741
}

examples/compute_instance/simple/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ variable "num_instances" {
3535
description = "Number of instances to create"
3636
}
3737

38+
variable "nat_ip" {
39+
description = "Public ip address"
40+
default = null
41+
}
42+
43+
variable "network_tier" {
44+
description = "Network network_tier"
45+
default = "PREMIUM"
46+
}
3847

3948

4049
variable "service_account" {

modules/compute_instance/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ See the [simple](examples/compute_instance/simple) for a usage example.
1515

1616
| Name | Description | Type | Default | Required |
1717
|------|-------------|:----:|:-----:|:-----:|
18+
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | object | `<list>` | no |
1819
| hostname | Hostname of instances | string | `""` | no |
1920
| instance\_template | Instance template self_link used to create compute instances | string | n/a | yes |
2021
| network | Network to deploy to. Only one of network or subnetwork should be specified. | string | `""` | no |

modules/compute_instance/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ resource "google_compute_instance_from_template" "compute_instance" {
5050
subnetwork = var.subnetwork
5151
subnetwork_project = var.subnetwork_project
5252
network_ip = length(var.static_ips) == 0 ? "" : element(local.static_ips, count.index)
53+
dynamic "access_config" {
54+
for_each = var.access_config
55+
content {
56+
nat_ip = access_config.value.nat_ip
57+
network_tier = access_config.value.network_tier
58+
}
59+
}
5360
}
5461

5562
source_instance_template = var.instance_template

modules/compute_instance/variables.tf

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

43+
variable "access_config" {
44+
description = "Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet."
45+
type = list(object({
46+
nat_ip = string
47+
network_tier = string
48+
}))
49+
default = []
50+
}
51+
4352
variable "num_instances" {
4453
description = "Number of instances to create. This value is ignored if static_ips is provided."
4554
default = "1"

0 commit comments

Comments
 (0)