Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict VM-instance network variables validation #1553

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/compute/vm-instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ limitations under the License.
| <a name="input_metadata"></a> [metadata](#input\_metadata) | Metadata, provided as a map | `map(string)` | `{}` | no |
| <a name="input_name_prefix"></a> [name\_prefix](#input\_name\_prefix) | An optional name for all VM and disk resources. <br>If not supplied, `deployment_name` will be used. <br>When `name_prefix` is supplied, and `add_deployment_name_before_prefix` is set, <br>then resources are named by "<`deployment_name`>-<`name_prefix`>-<#>". | `string` | `null` | no |
| <a name="input_network_interfaces"></a> [network\_interfaces](#input\_network\_interfaces) | A list of network interfaces. The options match that of the terraform<br>network\_interface block of google\_compute\_instance. For descriptions of the<br>subfields or more information see the documentation:<br>https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#nested_network_interface<br><br>**\_NOTE:\_** If `network_interfaces` are set, `network_self_link` and<br>`subnetwork_self_link` will be ignored, even if they are provided through<br>the `use` field. `bandwidth_tier` and `disable_public_ips` also do not apply<br>to network interfaces defined in this variable.<br><br>Subfields:<br>network (string, required if subnetwork is not supplied)<br>subnetwork (string, required if network is not supplied)<br>subnetwork\_project (string, optional)<br>network\_ip (string, optional)<br>nic\_type (string, optional, choose from ["GVNIC", "VIRTIO\_NET"])<br>stack\_type (string, optional, choose from ["IPV4\_ONLY", "IPV4\_IPV6"])<br>queue\_count (number, optional)<br>access\_config (object, optional)<br>ipv6\_access\_config (object, optional)<br>alias\_ip\_range (list(object), optional) | <pre>list(object({<br> network = string,<br> subnetwork = string,<br> subnetwork_project = string,<br> network_ip = string,<br> nic_type = string,<br> stack_type = string,<br> queue_count = number,<br> access_config = list(object({<br> nat_ip = string,<br> public_ptr_domain_name = string,<br> network_tier = string<br> })),<br> ipv6_access_config = list(object({<br> public_ptr_domain_name = string,<br> network_tier = string<br> })),<br> alias_ip_range = list(object({<br> ip_cidr_range = string,<br> subnetwork_range_name = string<br> }))<br> }))</pre> | `[]` | no |
| <a name="input_network_self_link"></a> [network\_self\_link](#input\_network\_self\_link) | The self link of the network to attach the VM. | `string` | `"default"` | no |
| <a name="input_network_self_link"></a> [network\_self\_link](#input\_network\_self\_link) | The self link of the network to attach the VM. Can use "default" for the default network. | `string` | `null` | no |
| <a name="input_network_storage"></a> [network\_storage](#input\_network\_storage) | An array of network attached storage mounts to be configured. | <pre>list(object({<br> server_ip = string,<br> remote_mount = string,<br> local_mount = string,<br> fs_type = string,<br> mount_options = string,<br> client_install_runner = map(string)<br> mount_runner = map(string)<br> }))</pre> | `[]` | no |
| <a name="input_on_host_maintenance"></a> [on\_host\_maintenance](#input\_on\_host\_maintenance) | Describes maintenance behavior for the instance. If left blank this will default to `MIGRATE` except for when `placement_policy`, spot provisioning, or GPUs require it to be `TERMINATE` | `string` | `null` | no |
| <a name="input_placement_policy"></a> [placement\_policy](#input\_placement\_policy) | Control where your VM instances are physically located relative to each other within a zone. | <pre>object({<br> vm_count = number,<br> availability_domain_count = number,<br> collocation = string,<br> })</pre> | `null` | no |
Expand Down
5 changes: 5 additions & 0 deletions modules/compute/vm-instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,10 @@ resource "google_compute_instance" "compute_vm" {
ignore_changes = [
metadata["ssh-keys"],
]

precondition {
condition = (length(var.network_interfaces) == 0) != (var.network_self_link == null && var.subnetwork_self_link == null)
error_message = "Exactly one of network_interfaces or network_self_link/subnetwork_self_link must be specified."
}
}
}
4 changes: 2 additions & 2 deletions modules/compute/vm-instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ variable "service_account" {
}

variable "network_self_link" {
description = "The self link of the network to attach the VM."
description = "The self link of the network to attach the VM. Can use \"default\" for the default network."
type = string
default = "default"
default = null
}

variable "subnetwork_self_link" {
Expand Down