A Terraform module to create and manage a Google Kubernetes Engine (GKE) cluster with autopilot enabled.
This module supports Terraform version 1 and is compatible with the Terraform Google Provider Beta version ~> 4.34
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_container_cluster
Note: This module comes without support for the default node pool or its autoscaling since it can't be managed properly with Terraform. Please use our terraform-google-gke-node-pool module instead for deploying and managing node groups for your clusters.
Most common usage of the module:
module "terraform-google-gke-autopilot-cluster" {
source = "git@github.com:mineiros-io/terraform-google-gke-autopilot-cluster.git?ref=v0.1.0"
name = "gke-example"
network = "vpc_self_link"
subnetwork = "subnetwork_self_link"
master_ipv4_cidr_block = "10.4.96.0/28"
ip_allocation_policy = {
cluster_secondary_range_name = "pod_range_name"
services_secondary_range_name = "services_range_name"
}
}
See variables.tf and examples/ for details and use-cases.
-
name
: (Requiredstring
)The name of the cluster.
-
location
: (Optionalstring
)The location region in which the cluster master will be created. Please note that autopilot only supports regional clusters.
-
network
: (Optionalstring
)The name or
self_link
of the Google Compute Engine network to which the cluster is connected.Note: For Shared VPC, set this to the self link of the shared network.
-
subnetwork
: (Optionalstring
)The name or
self_link
of the Google Compute Engine subnetwork in which the cluster's instances are launched. -
networking_mode
: (Optionalstring
)Determines whether alias IPs or routes will be used for pod IPs in the cluster.
Options are
VPC_NATIVE
orROUTES
.VPC_NATIVE
enables IP aliasing, and requires theip_allocation_policy
block to be defined.Using a VPC-native cluster is the recommended approach by Google. For an overview of benefits of VPC-native clusters, please see https://cloud.google.com/kubernetes-engine/docs/concepts/alias-ips#benefits
Default is
"VPC_NATIVE"
. -
project
: (Optionalstring
)The ID of the project in which the resource belongs. If it is not set, the provider project is used.
-
rbac_security_identity_group
: (Optionalstring
)The name of the RBAC security identity group for use with Google security groups in Kubernetes RBAC. Group name must be in format
gke-security-groups@yourdomain.com
. For details please see https://cloud.google.com/kubernetes-engine/docs/how-to/google-groups-rbac -
min_master_version
: (Optionalstring
)The minimum version of the Kubernetes master. GKE will auto-update the master to new versions, so this does not guarantee the current master version uses the read-only
master_version
field to obtain that. If unset, the cluster's version will be set by GKE to the version of the most recent official release. -
cluster_ipv4_cidr
: (Optionalstring
)The IP address range of the Kubernetes pods in this cluster in CIDR notation (e.g.
10.96.0.0/14
). Leave blank to have one automatically chosen or specify a/14
block in10.0.0.0/8
.Note: This field will only work for routes-based clusters, where
ip_allocation_policy
is not defined. -
enable_kubernetes_alpha
: (Optionalbool
)Whether to enable Kubernetes Alpha features for this cluster. Note that when this option is enabled, the cluster cannot be upgraded and will be automatically deleted after 30 days.
Default is
false
. -
addon_horizontal_pod_autoscaling
: (Optionalbool
)Whether to enable the horizontal pod autoscaling addon.
Default is
true
. -
addon_http_load_balancing
: (Optionalbool
)Whether to enable the httpload balancer addon.
Default is
true
. -
ip_allocation_policy
: (Optionalobject(ip_allocation_policy)
)Configuration of cluster IP allocation for VPC-native clusters.
Note: This field will only work for VPC-native clusters.
Example:
readme_example = { cluster_ipv4_cidr_block = "10.4.128.0/17" services_ipv4_cidr_block = "10.4.112.0/20" }
The
ip_allocation_policy
object accepts the following attributes:-
cluster_ipv4_cidr_block
: (Optionalstring
)The IP address range for the cluster pod IPs. Set to blank to have a range chosen with the default size. Set to /netmask (e.g.
/14
) to have a range chosen with a specific netmask. Set to a CIDR notation (e.g.10.96.0.0/14
) from the RFC-1918 private networks (e.g.10.0.0.0/8
,172.16.0.0/12
,192.168.0.0/16
) to pick a specific range to use. Conflicts withcluster_secondary_range_name
. -
services_ipv4_cidr_block
: (Optionalstring
)The IP address range of the services IPs in this cluster. Set to blank to have a range chosen with the default size. Set to /netmask (e.g.
/14
) to have a range chosen with a specific netmask. Set to a CIDR notation (e.g.10.96.0.0/14
) from the RFC-1918 private networks (e.g.10.0.0.0/8
,172.16.0.0/12
,192.168.0.0/16
) to pick a specific range to use. Conflicts withcluster_secondary_range_name
. -
cluster_secondary_range_name
: (Optionalstring
)The name of the existing secondary range in the cluster's subnetwork to use for pod IP addresses. Alternatively,
cluster_ipv4_cidr_block
can be used to automatically create a GKE-managed one. Conflicts withcluster_ipv4_cidr_block
. -
services_secondary_range_name
: (Optionalstring
)The name of the existing secondary range in the cluster's subnetwork to use for service
ClusterIPs
. Alternatively,services_ipv4_cidr_block
can be used to automatically create a GKE-managed one. Conflicts withservices_ipv4_cidr_block
.
-
-
description
: (Optionalstring
)The description of the cluster.
Default is
""
. -
master_authorized_networks_config
: (Optionalobject(master_authorized_networks_config)
)Configuration for handling external access control plane of the cluster.
Example:
master_authorized_networks_config = { cidr_blocks = [ { display_name = "Berlin Office" cidr_block = "10.4.112.0/20" } ] }
The
master_authorized_networks_config
object accepts the following attributes:-
cidr_blocks
: (Optionallist(cidr_block)
)Set of master authorized networks. If none are provided, disallow external access (except the cluster node IPs, which GKE automatically whitelists).
Default is
[]
.Each
cidr_block
object in the list accepts the following attributes:-
cidr_block
: (Requiredstring
)External network that can access Kubernetes master through HTTPS. Must be specified in CIDR notation.
-
display_name
: (Optionalstring
)Field for users to identify CIDR blocks.
-
-
-
maintenance_policy
: (Optionalobject(maintenance_policy)
)The maintenance windows and maintenance exclusions, which provide control over when cluster maintenance such as auto-upgrades can and cannot occur on your cluster.
For details please see https://cloud.google.com/kubernetes-engine/docs/concepts/maintenance-windows-and-exclusions
The
maintenance_policy
object accepts the following attributes:-
daily_maintenance_window
: (Optionalobject(daily_maintenance_window)
)Time window specified for daily maintenance operations.
For details please see https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster#daily_maintenance_window
Example:
maintenance_policy = { daily_maintenance_window = { start_time = "03:00" } }
The
daily_maintenance_window
object accepts the following attributes:-
start_time
: (Requiredstring
)Specify the
start_time
for a daily maintenance window in RFC3339 formatHH:MM
, where HH : [00-23] and MM : [00-59] GMT.
-
-
recurring_window
: (Optionalobject(recurring_window)
)Time window specified for recurring maintenance operations.
For details please see https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster#recurring_window
Example:
maintenance_policy = { recurring_window = { start_time = "2022-01-01T09:00:00Z" end_time = "2022-01-01T17:00:00Z" recurrence = "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR" } }
The
recurring_window
object accepts the following attributes:-
start_time
: (Requiredstring
)Specify
start_time
and in RFC3339 "Zulu" date format. The start time's date is the initial date that the window starts. -
end_time
: (Requiredstring
)Specify
end_time
in RFC3339 "Zulu" date format. The end time is used for calculating duration. -
recurrence
: (Requiredstring
)Specify recurrence in RFC5545 RRULE format, to specify when this maintenance window recurs.
-
-
maintenance_exclusion
: (Optionallist(maintenance_exclusion)
)Exceptions to maintenance window. Non-emergency maintenance should not occur in these windows. A cluster can have up to three maintenance exclusions at a time.
For details please see https://cloud.google.com/kubernetes-engine/docs/concepts/maintenance-windows-and-exclusions
Example:
maintenance_policy = { recurring_window = { start_time = "2022-01-01T00:00:00Z" end_time = "2022-01-02T00:00:00Z" recurrence = "FREQ=DAILY" } maintenance_exclusion = { exclusion_name = "batch job" start_time = "2022-01-01T00:00:00Z" end_time = "2022-01-02T00:00:00Z" } maintenance_exclusion = { exclusion_name = "holiday data load" start_time = "2022-05-01T00:00:00Z" end_time = "2022-05-02T00:00:00Z" } }
Each
maintenance_exclusion
object in the list accepts the following attributes:-
exclusion_name
: (Requiredstring
)The name of the maintenance exclusion window.
-
start_time
: (Requiredstring
)Specify
start_time
and in RFC3339 "Zulu" date format. The start time's date is the initial date that the window starts. -
end_time
: (Requiredstring
)Specify
end_time
in RFC3339 "Zulu" date format. The end time is used for calculating duration.
-
-
-
resource_usage_export_bigquery_dataset_id
: (Optionalstring
)The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export. Needs to be configured when using egress metering and/or resource consumption metering.
-
enable_network_egress_metering
: (Optionalbool
)Whether to enable network egress metering for this cluster. If enabled, a daemonset will be created in the cluster to meter network egress traffic. When enabling the network egress metering, a BigQuery Dataset needs to be configured as the destination using the
resource_usage_export_bigquery_dataset_id
variable.Note: You cannot use Shared VPCs or VPC peering with network egress metering.
For details please see https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-usage-metering
Default is
false
. -
enable_resource_consumption_metering
: (Optionalbool
)Whether to enable resource consumption metering on this cluster. When enabled, a table will be created in the resource export BigQuery dataset that needs to be configured in
resource_usage_export_bigquery_dataset_id
to store resource consumption data. The resulting table can be joined with the resource usage table or with BigQuery billing export.For details please see https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-usage-metering
Default is
true
. -
logging_enable_components
: (Optionalset(string)
)A list of GKE components exposing logs. Supported values include:
SYSTEM_COMPONENTS
andWORKLOADS
. -
logging_service
: (Optionalstring
)The logging service that the cluster should write logs to. Available options include
logging.googleapis.com
, andnone
.Default is
"logging.googleapis.com/kubernetes"
. -
monitoring_config
: (Optionalobject(monitoring_config)
)A block for configuring monitoring for the GKE cluster. Contains
enable_components
andmanaged_prometheus
.Example:
monitoring_config = { enable_components = ["SYSTEM_COMPONENTS", "WORKLOADS"] managed_prometheus = { enabled = false } }
The
monitoring_config
object accepts the following attributes:-
enable_components
: (Optionallist(string)
)The GKE components exposing metrics. Supported values include: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, and SCHEDULER. In beta provider, WORKLOADS is supported on top of those 4 values. (WORKLOADS is deprecated and removed in GKE 1.24.)
-
managed_prometheus
: (Optionalobject(managed_prometheus)
)Configures managed Prometheus for this cluster.
The
managed_prometheus
object accepts the following attributes:-
enabled
: (Optionalbool
)Specifies whether managed Prometheus is enabled.
-
-
-
monitoring_service
: (Optionalstring
)The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Comput Engine regardless of this setting Available options include
monitoring.googleapis.com
, andnone
.Default is
"monitoring.googleapis.com/kubernetes"
. -
resource_labels
: (Optionalmap(string)
)The GCE resource labels (a map of key/value pairs) to be applied to the cluster.
For details please see https://cloud.google.com/kubernetes-engine/docs/how-to/creating-managing-labels
Default is
{}
. -
enable_private_endpoint
: (Optionalbool
)Whether the master's internal IP address is used as the cluster endpoint.
Default is
false
. -
enable_private_nodes
: (Optionalbool
)Whether nodes have internal IP addresses only.
Default is
true
. -
private_ipv6_google_access
: (Optionalstring
)Configures the IPv6 connectivity to Google Services. By default, no private IPv6 access to or from Google Services is enabled (all access will be via IPv4). Accepted values are
PRIVATE_IPV6_GOOGLE_ACCESS_UNSPECIFIED
,INHERIT_FROM_SUBNETWORK
,OUTBOUND
, andBIDIRECTIONAL
. -
master_ipv4_cidr_block
: (Optionalstring
)The IP range in CIDR notation to use for the hosted master network.
-
database_encryption_key_name
: (Optionalstring
)The name of a CloudKMS key to enable application-layer secrets encryption settings. If non-null the state will be set to:
ENCRYPTED
elseDECRYPTED
. -
release_channel
: (Optionalstring
)The release channel of this cluster. Accepted values are
RAPID
,REGULAR
andSTABLE
.Default is
"STABLE"
. -
node_pool_auto_config
: (Optionalobject(node_pool_auto_config)
)Node pool configs that apply to auto-provisioned node pools in autopilot clusters and node auto-provisioning-enabled clusters.
Default is
null
.Example:
node_pool_auto_config = { network_tags = { tags = ["foo", "bar"] } }
The
node_pool_auto_config
object accepts the following attributes:-
network_tags
: (Optionalobject(network_tags)
)Configures network tags on cluster
The
network_tags
object accepts the following attributes:-
tags
: (Optionallist(string)
)List of tags to apply for all nodes managed by autopilot
-
-
-
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_container_cluster
, ...Example:
module_timeouts = { google_container_cluster = { create = "60m" update = "60m" delete = "60m" } }
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:
-
name
: (string
)The name of the cluster.
-
cluster
: (object(cluster)
)All arguments in
google_container_cluster
.
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 hello@mineiros.io 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