A Terraform module to create a Google Network Subnet on Google Cloud Services (GCP).
This module supports Terraform version 1 and is compatible with the Terraform Google Provider version 4.
This module is part of our Infrastructure as Code (IaC) framework that enables our users and customers to easily deploy and manage reusable, secure, and production-grade cloud infrastructure.
- Module Features
- Getting Started
- Module Argument Reference
- Module Outputs
- External Documentation
- Module Versioning
- About Mineiros
- Reporting Issues
- Contributing
- Makefile Targets
- License
This module implements the following Terraform resources:
google_compute_subnetwork
and supports additional features of the following modules:
Most common usage of the module:
module "terraform-google-subnetwork" {
source = "github.com/mineiros-io/terraform-google-subnetwork.git?ref=v0.0.1"
network = google_compute_network.custom-test.id
name = "test-subnetwork"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
secondary_ip_ranges = [
{
range_name = "kubernetes-pods"
ip_cidr_range = "10.10.0.0/20"
}
]
}
See variables.tf and examples/ for details and use-cases.
-
project
: (Optionalstring
)The ID of the project in which the resources belong. If it is not set, the provider project is used.
-
network
: (Requiredstring
)The ID of the VPC network the subnets belong to. Only networks that are in the distributed mode can have subnetworks.
-
name
: (Requiredstring
)The name of this subnetwork, provided by the client when initially creating the resource. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression
[a-z]([-a-z0-9]*[a-z0-9])?
which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash. -
description
: (Optionalstring
)An optional description of this subnetwork. Provide this property when you create the resource. This field can be set only at resource creation time.
-
region
: (Requiredstring
)The GCP region for this subnetwork.
-
private_ip_google_access
: (Optionalbool
)When enabled, VMs in this subnetwork without external IP addresses can access Google APIs and services by using Private Google Access.
Default is
true
. -
ip_cidr_range
: (Requiredstring
)The range of internal addresses that are owned by this subnetwork. Provide this property when you create the subnetwork. For example, 10.0.0.0/8 or 192.168.0.0/16. Ranges must be unique and non-overlapping within a network. Only IPv4 is supported.
-
secondary_ip_ranges
: (Optionallist(secondary_ip_range)
)An array of configurations for secondary IP ranges for VM instances contained in this subnetwork. The primary IP of such VM must belong to the primary ipCidrRange of the subnetwork. The alias IPs may belong to either primary or secondary ranges.
Example:
secondary_ip_range { range_name = "tf-test-secondary-range-update1" ip_cidr_range = "192.168.10.0/24" }
Each
secondary_ip_range
object in the list accepts the following attributes:-
range_name
: (Requiredstring
)The name associated with this subnetwork secondary range, used when adding an alias IP range to a VM instance. The name must be 1-63 characters long, and comply with RFC1035. The name must be unique within the subnetwork.
-
ip_cidr_range
: (Requiredstring
)The range of IP addresses belonging to this subnetwork secondary range. Provide this property when you create the subnetwork. Ranges must be unique and non-overlapping with all primary and secondary IP ranges within a network. Only
IPv4
is supported.
-
-
log_config
: (Optionalobject(log_config)
)Logging options for the subnetwork flow logs. Setting this value to 'null' will disable them. See https://www.terraform.io/docs/providers/google/r/compute_subnetwork.html for more information and examples.
Example:
log_config { aggregation_interval = "INTERVAL_10_MIN" flow_sampling = 0.5 metadata = "INCLUDE_ALL_METADATA" metadata_fields = "CUSTOM_METADATA" filter_expr = true }
The
log_config
object accepts the following attributes:-
aggregation_interval
: (Optionalstring
)Can only be specified if VPC flow logging for this subnetwork is enabled. Toggles the aggregation interval for collecting flow logs. Increasing the interval time will reduce the amount of generated flow logs for long lasting connections. Default is an interval of
5 seconds
per connection. Possible values areINTERVAL_5_SEC
,INTERVAL_30_SEC
,INTERVAL_1_MIN
,INTERVAL_5_MIN
,INTERVAL_10_MIN
, andINTERVAL_15_MIN
. -
flow_sampling
: (Optionalnumber
)Can only be specified if VPC flow logging for this subnetwork is enabled. The value of the field must be in
[0, 1]
. Set the sampling rate of VPC flow logs within the subnetwork where1.0
means all collected logs are reported and0.0
means no logs are reported. -
metadata
: (Optionalstring
)Can only be specified if VPC flow logging for this subnetwork is
enabled
. Configures whether metadata fields should be added to the reported VPC flow logs. Possible values areEXCLUDE_ALL_METADATA
,INCLUDE_ALL_METADATA
, andCUSTOM_METADATA
. -
metadata_fields
: (Optionallist(string)
)List of metadata fields that should be added to reported logs. Can only be specified if VPC flow logs for this subnetwork is
enabled
and"metadata"
is set toCUSTOM_METADATA
. -
filter_expr
: (Optionalstring
)Export filter used to define which VPC flow logs should be logged, as as CEL expression. See https://cloud.google.com/vpc/docs/flow-logs#filtering for details on how to format this field.
-
-
iam
: (Optionallist(iam)
)A list of IAM access.
Example:
iam = [{ role = "roles/compute.networkUser" members = ["user:[email protected]"] authoritative = false }]
Each
iam
object in the list accepts the following attributes:-
members
: (Optionalset(string)
)Identities that will be granted the privilege in role. Each entry can have one of the following values:
allUsers
: A special identifier that represents anyone who is on the internet; with or without a Google account.allAuthenticatedUsers
: A special identifier that represents anyone who is authenticated with a Google account or a service account.user:{emailid}
: An email address that represents a specific Google account. For example, [email protected] or [email protected].serviceAccount:{emailid}
: An email address that represents a service account. For example, [email protected].group:{emailid}
: An email address that represents a Google group. For example, [email protected].domain:{domain}
: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com.projectOwner:projectid
: Owners of the given project. For example,projectOwner:my-example-project
projectEditor:projectid
: Editors of the given project. For example,projectEditor:my-example-project
projectViewer:projectid
: Viewers of the given project. For example,projectViewer:my-example-project
Default is
[]
. -
role
: (Optionalstring
)The role that should be applied. Note that custom roles must be of the format
[projects|organizations]/{parent-name}/roles/{role-name}
. -
authoritative
: (Optionalbool
)Whether to exclusively set (authoritative mode) or add (non-authoritative/additive mode) members to the role.
Default is
true
.
-
-
policy_bindings
: (Optionallist(policy_binding)
)A list of IAM policy bindings.
Example:
policy_bindings = [{ role = "roles/compute.networkUser" members = ["user:[email protected]"] condition = { title = "expires_after_2021_12_31" description = "Expiring at midnight of 2021-12-31" expression = "request.time < timestamp(\"2022-01-01T00:00:00Z\")" } }]
Each
policy_binding
object in the list accepts the following attributes:-
role
: (Requiredstring
)The role that should be applied.
-
members
: (Optionalset(string)
)Identities that will be granted the privilege in
role
.Default is
var.members
. -
condition
: (Optionalobject(condition)
)An IAM Condition for a given binding.
Example:
condition = { expression = "request.time < timestamp(\"2022-01-01T00:00:00Z\")" title = "expires_after_2021_12_31" }
The
condition
object accepts the following attributes:-
expression
: (Requiredstring
)Textual representation of an expression in Common Expression Language syntax.
You can find more information about the usage of Common Expression Language for IAM conditions in the official IAM Conditions documentation.
-
title
: (Requiredstring
)A title for the expression, i.e. a short string describing its purpose.
-
description
: (Optionalstring
)An optional description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI.
-
-
-
module_enabled
: (Optionalbool
)Specifies whether resources in the module will be created.
Default is
true
. -
module_timeouts
: (Optionalmap(timeout)
)A map of timeout objects that is keyed by Terraform resource name defining timeouts for
create
,update
anddelete
Terraform operations.Supported resources are:
google_compute_subnetwork
,Example:
module_timeouts = { null_resource = { create = "4m" update = "4m" delete = "4m" } }
Each
timeout
object in the map accepts the following attributes: -
module_depends_on
: (Optionallist(dependency)
)A list of dependencies. Any object can be assigned to this list to define a hidden external dependency.
Default is
[]
.Example:
module_depends_on = [ null_resource.name ]
The following attributes are exported in the outputs of the module:
-
module_enabled
: (bool
)Whether this module is enabled.
-
module_tags
: (map(string)
)The map of tags that are being applied to all created resources that accept tags.
-
subnetwork
: (map(subnetwork)
)The created subnet resource.
- Configuring Private Google Access: https://cloud.google.com/vpc/docs/configure-private-google-access
- Using VPC networks: https://cloud.google.com/vpc/docs/using-vpc
This Module follows the principles of Semantic Versioning (SemVer).
Given a version number MAJOR.MINOR.PATCH
, we increment the:
MAJOR
version when we make incompatible changes,MINOR
version when we add functionality in a backwards compatible manner, andPATCH
version when we make backwards compatible bug fixes.
- Backwards compatibility in versions
0.0.z
is not guaranteed whenz
is increased. (Initial development) - Backwards compatibility in versions
0.y.z
is not guaranteed wheny
is increased. (Pre-release)
Mineiros is a remote-first company headquartered in Berlin, Germany that solves development, automation and security challenges in cloud infrastructure.
Our vision is to massively reduce time and overhead for teams to manage and deploy production-grade and secure cloud infrastructure.
We offer commercial support for all of our modules and encourage you to reach out if you have any questions or need help. Feel free to email us at [email protected] or join our Community Slack channel.
We use GitHub Issues to track community reported issues and missing features.
Contributions are always encouraged and welcome! For the process of accepting changes, we use Pull Requests. If you'd like more information, please see our Contribution Guidelines.
This repository comes with a handy Makefile.
Run make help
to see details on each available target.
This module is licensed under the Apache License Version 2.0, January 2004. Please see LICENSE for full details.
Copyright © 2020-2022 Mineiros GmbH