Skip to content

Commit d0ed8bb

Browse files
Removed SUBNETWORK_PROJECT (using self links instead)
Changed the format for shared VPC to use ID or self link instead. This is because some resources such as Cloud SQL always require self links, and other resources require self links when using shared VPC. * Network ID format: projects/{{project}}/global/networks/{{name}} * Subnetwork ID format: projects/{{project}}/regions/{{region}}/subnetworks/{{name}} Simple names such as "default" are still supported. They will be converted automatically to a network/subnetwork ID. The project will be assumed to be the same project as the knfsd proxy cluster. Change-Id: I8cb44038d69654a23f1e3bac6e981f5618abc724
1 parent f3cf6e2 commit d0ed8bb

File tree

7 files changed

+25
-18
lines changed

7 files changed

+25
-18
lines changed

deployment/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ terraform apply
8686

8787
| Variable | Description | Required | Default |
8888
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------------------------------------ |
89-
| NETWORK | The network name (VPC) to use for the deployment of the Knfsd Compute Engine Instances. | False | `default` |
90-
| SUBNETWORK | The subnetwork name (subnet) to use for the deployment of the Knfsd Compute Engine Instances. | False | `default` |
91-
| SUBNETWORK_PROJECT | The project that the subnetwork exists in. This only needs to be set if using a Shared VPC, where the subnetwork exists in a different project. Otherwise it defaults to the provider project. | False | null |
89+
| NETWORK | The network id or self link (VPC) to use for the deployment of the Knfsd Compute Engine Instances. A network id is in the format `projects/{{project}}/global/networks/{{name}}` | False | `default` |
90+
| SUBNETWORK | The subnetwork id or self link (subnet) to use for the deployment of the Knfsd Compute Engine Instances. A subnetwork id is in the format `projects/{{project}}/regions/{{region}}/subnetworks/{{name}}` | False | `default` |
9291
| AUTO_CREATE_FIREWALL_RULES | Should firewall rules automatically be created to allow [health check connectivity](https://cloud.google.com/load-balancing/docs/health-check-concepts#ip-ranges)? Best practice is to set this to false and create the firewall rules yourself; see [firewall configuration](../deployment/firewall.md) for more details. | False | `true` |
9392
| TRAFFIC_DISTRIBUTION_MODE | The [client traffic distribution mode](./traffic-distribution.md) used to distribute traffic between proxy instances in the KNFSD proxy cluster. Can be either `dns_round_robin`, `loadbalancer`, or `none`. The recommended option is `dns_round_robin`. If using `none` you will need to provide your own solution to handle traffic distribution. | True | |
9493
| LOADBALANCER_IP | The IP address to use for the Internal Load Balancer when `TRAFFIC_DISTRIBUTION_MODE = "loadbalancer"`. If not specified, a random IP address will be assigned within the subnet. | False | null |

deployment/terraform-module-knfsd/compute.tf

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ resource "google_compute_instance_template" "nfsproxy-template" {
128128
}
129129

130130
network_interface {
131-
network = var.NETWORK
132-
subnetwork = var.SUBNETWORK
133-
subnetwork_project = var.SUBNETWORK_PROJECT != "" ? var.SUBNETWORK_PROJECT : null
131+
network = local.network
132+
subnetwork = local.subnetwork
134133
nic_type = (var.ENABLE_HIGH_BANDWIDTH_CONFIGURATION || var.ENABLE_GVNIC) ? "GVNIC" : "VIRTIO_NET"
135134
}
136135

@@ -388,7 +387,7 @@ resource "google_compute_firewall" "allow-tcp-healthcheck" {
388387

389388
project = var.PROJECT
390389
name = "allow-nfs-tcp-healthcheck"
391-
network = var.NETWORK
390+
network = local.network
392391
priority = 1000
393392

394393
allow {

deployment/terraform-module-knfsd/loadbalancer.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ resource "google_compute_address" "nfsproxy_static" {
2929
region = var.REGION
3030
name = "${var.PROXY_BASENAME}-static-ip"
3131
address_type = "INTERNAL"
32-
subnetwork = var.SUBNETWORK
32+
subnetwork = local.subnetwork
3333
address = var.LOADBALANCER_IP
3434
purpose = "SHARED_LOADBALANCER_VIP"
3535

@@ -50,8 +50,8 @@ module "loadbalancer" {
5050
PROJECT = var.PROJECT
5151
REGION = var.REGION
5252
PROXY_BASENAME = var.PROXY_BASENAME
53-
NETWORK = var.NETWORK
54-
SUBNETWORK = var.SUBNETWORK
53+
NETWORK = local.network
54+
SUBNETWORK = local.subnetwork
5555
SERVICE_LABEL = var.SERVICE_LABEL
5656
IP_ADDRESS = google_compute_address.nfsproxy_static[0].address
5757
ENABLE_UDP = var.ENABLE_UDP

deployment/terraform-module-knfsd/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ locals {
2727
)
2828
MIG_REPLACEMENT_METHOD_DEFAULT = var.ASSIGN_STATIC_IPS ? "RECREATE" : "SUBSTITUTE"
2929
deploy_fsid_database = var.FSID_MODE == "external" && var.FSID_DATABASE_DEPLOY
30+
31+
# Check if network/subnetwork are using simple names. If so, convert them to
32+
# IDs so that they can be used with resources such as Cloud SQL.
33+
network = strcontains(var.NETWORK, "/") ? var.NETWORK : "projects/${var.PROJECT}/global/networks/${var.NETWORK}"
34+
subnetwork = strcontains(var.SUBNETWORK, "/") ? var.SUBNETWORK : "projects/${var.PROJECT}/regions/${var.REGION}/subnetworks/${var.SUBNETWORK}"
3035
}
3136

3237
# Validate that SERVICE_ACCOUNT is set when deploying an external database.

deployment/terraform-module-knfsd/variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ variable "PROJECT" {
5353
}
5454
}
5555

56-
variable "SUBNETWORK_PROJECT" {
57-
type = string
58-
default = ""
59-
}
60-
6156
variable "REGION" {
6257
type = string
6358
nullable = false

docs/changes/changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Fix proxy startup script always prints "Error starting proxy"
66
* Fix auto-reexporting the root of an NFS v4 server
77
* Assign a public IP to the build machine by default
8+
* Removed `SUBNETWORK_PROJECT` (using self links instead)
89

910
## Fetch Ubuntu Kernel source from launchpad
1011

@@ -31,6 +32,15 @@ When building using packer, assign a public IP (`omit_external_ip = false`) to t
3132

3233
When `omit_external_ip = true` the GCP network will require that Cloud NAT is configured so that the build instance can fetch packages and source code from the public internet.
3334

35+
## Removed `SUBNETWORK_PROJECT` (using self links instead)
36+
37+
Changed the format for shared VPC to use ID or self link instead. This is because some resources such as Cloud SQL always require self links, and other resources require self links when using shared VPC.
38+
39+
* Network ID format: `projects/{{project}}/global/networks/{{name}}`
40+
* Subnetwork ID format: `projects/{{project}}/regions/{{region}}/subnetworks/{{name}}`
41+
42+
Simple names such as "default" are still supported. They will be converted automatically to a network/subnetwork ID. The project will be assumed to be the same project as the knfsd proxy cluster.
43+
3444
# v1.0.0-beta7
3545

3646
* Fix error applying Terraform when nodes greater than 1

image/smoke-tests/terraform/main.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ module "proxy" {
4949
REGION = var.region
5050
ZONE = var.zone
5151

52-
NETWORK = google_compute_network.this.name
53-
SUBNETWORK = google_compute_subnetwork.this.name
54-
SUBNETWORK_PROJECT = google_compute_subnetwork.this.project
52+
NETWORK = google_compute_network.this.id
53+
SUBNETWORK = google_compute_subnetwork.this.id
5554

5655
AUTO_CREATE_FIREWALL_RULES = false
5756
TRAFFIC_DISTRIBUTION_MODE = "dns_round_robin"

0 commit comments

Comments
 (0)