README.md

May 24, 2022 ยท View on GitHub

Description

This module creates a new VPC network along with a cloud NAT, Router and common firewall rules. This module is based on submodules defined by the Cloud Foundation Toolkit.

The created cloud NAT (Network Address Translation) allows virtual machines without external IP addresses to create outbound connections to the internet. For more information see the docs.

The following firewall rules are created with the VPC network:

  • Allow SSH access from the Cloud Console ("35.235.240.0/20").
  • Allow traffic between nodes within the VPC

Primary and additional subnetworks

This module will, at minimum, provision a "primary" subnetwork in which most resources are expected to be provisioned. These are controlled by the following input variables:

  • var.subnetwork_name and var.subnetwork_size
  • var.primary_subnetwork
  • var.additional_subnetworks

Both var.primary_subnetwork and var.additional_subnetworks behave identically to the Cloud Foundation Toolkit subnets module with the lone exception that the IP range for each subnet is constructed automatically by calculating the most compact set of subnetworks. The size of each individual subnetwork is specified with the new_bits key and the base of the global VPC network is specified using var.network_address_range.

If explicitly supplied, var.primary_subnetwork defines all properties of the primary subnetwork. If var.primary_subnetwork is left at its default value of null, then a default primary subnetwork will be constructed from var.subnetwork_name and var.subnetwork_size. If no value is supplied for var.subnetwork_name, a default value is constructed from var.deployment_name.

Additional subnetworks are optionally supplied explicitly with var.additional_subnetworks.

Example

- source: modules/network/vpc
  kind: terraform
  id: network1
  settings:
  - deployment_name: $(vars.deployment_name)

This creates a new VPC network named based on the deployment_name variable with _net appended. network_name can be set manually as well as part of the settings.

NOTE: deployment_name does not need to be set explicitly here. It would typically be inferred from the deployment variable of the same name. It is included here for clarity.

License

Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Requirements

NameVersion
terraform>= 0.14.0

Providers

No providers.

Modules

NameSourceVersion
cloud_routerterraform-google-modules/cloud-router/google~> 1.3
firewall_rulesterraform-google-modules/network/google//modules/firewall-rules~> 5.0
nat_ip_addressesterraform-google-modules/address/google~> 3.1
vpcterraform-google-modules/network/google~> 5.0

Resources

No resources.

Inputs

NameDescriptionTypeDefaultRequired
additional_subnetworksList of additional subnetworks in which to create resources.

subnet_name (string, required, Name of subnet; will be replaced by var.subnetwork_name or its default value)
subnet_region (string, required, will be replaced by var.region)
new_bits (number, required, Additional CIDR bits to determine subnetwork size)
subnet_private_access (bool, optional, Enable Private Access on subnetwork)
subnet_flow_logs (map(string), optional, Configure Flow Logs see terraform-google-network module)
description (string, optional, Description of Network)
purpose (string, optional, related to Load Balancing)
role (string, optional, related to Load Balancing)
list(map(string))[]no
delete_default_internet_gateway_routesIf set, ensure that all routes within the network specified whose names begin with 'default-route' and with a next hop of 'default-internet-gateway' are deletedboolfalseno
deployment_nameThe name of the current deploymentstringn/ayes
ips_per_natThe number of IP addresses to allocate for each regional Cloud NAT (set to 0 to disable NAT)number2no
network_address_rangeIP address range (CIDR) for global networkstring"10.0.0.0/9"no
network_descriptionAn optional description of this resource (changes will trigger resource destroy/create)string""no
network_nameThe name of the network to be created (if unsupplied, will default to "{deployment_name}-net")stringnullno
network_routing_modeThe network routing mode (default "GLOBAL")string"GLOBAL"no
primary_subnetworkPrimary (default) subnetwork in which to create resources. If null, a default value will be constructed.

subnet_name (string, required, Name of subnet; will be replaced by var.subnetwork_name or its default value)
subnet_region (string, required, will be replaced by var.region)
new_bits (number, optional, Additional CIDR bits to determine subnetwork size; will default to var.subnetwork_size)
subnet_private_access (bool, optional, Enable Private Access on subnetwork)
subnet_flow_logs (map(string), optional, Configure Flow Logs see terraform-google-network module)
description (string, optional, Description of Network)
purpose (string, optional, related to Load Balancing)
role (string, optional, related to Load Balancing)
map(string)nullno
project_idProject in which the HPC deployment will be createdstringn/ayes
regionThe default region for Cloud resourcesstringn/ayes
shared_vpc_hostMakes this project a Shared VPC host if 'true' (default 'false')boolfalseno
subnetwork_nameThe name of the network to be created (if unsupplied, will default to "{deployment_name}-primary-subnet")stringnullno
subnetwork_sizeThe size, in CIDR bits, of the primary subnetwork unless explicitly supplied in var.primary_subnetworknumber15no

Outputs

NameDescription
nat_ipsthe external IPs assigned to the NAT
network_nameThe name of the network created
network_self_linkThe URI of the VPC being created
subnetworkThe primary subnetwork object created by the input variable primary_subnetwork
subnetwork_addressThe address range of the primary subnetwork
subnetwork_nameThe name of the primary subnetwork
subnetwork_self_linkThe self-link to the primary subnetwork
subnetworksAll subnetwork resources created by this module