2015-06-20 22:57:45 +00:00
---
layout: "google"
page_title: "Google: google_container_cluster"
2015-10-23 14:10:41 +00:00
sidebar_current: "docs-google-container-cluster"
2015-06-20 22:57:45 +00:00
description: |-
2017-11-29 23:40:27 +00:00
Creates a Google Kubernetes Engine (GKE) cluster.
2015-06-20 22:57:45 +00:00
---
# google\_container\_cluster
2019-01-31 21:37:33 +00:00
Manages a Google Kubernetes Engine (GKE) cluster. For more information see
2017-07-28 18:05:48 +00:00
[the official documentation ](https://cloud.google.com/container-engine/docs/clusters )
2019-01-31 21:37:33 +00:00
and [the API reference ](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1/projects.locations.clusters ).
2017-07-28 18:05:48 +00:00
2019-01-31 21:37:33 +00:00
~> **Note:** All arguments and attributes, including basic auth username and
passwords as well as certificate outputs will be stored in the raw state as
plaintext. [Read more about sensitive data in state ](/docs/state/sensitive-data.html ).
2017-03-29 09:37:36 +00:00
2019-01-31 21:37:33 +00:00
## Example Usage - with a separately managed node pool (recommended)
```hcl
resource "google_container_cluster" "primary" {
name = "my-gke-cluster"
region = "us-central1"
# We can't create a cluster with no node pool defined, but we want to only use
# separately managed node pools. So we create the smallest possible default
# node pool and immediately delete it.
remove_default_node_pool = true
initial_node_count = 1
# Setting an empty username and password explicitly disables basic auth
master_auth {
username = ""
password = ""
}
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
]
labels = {
foo = "bar"
}
tags = ["foo", "bar"]
}
}
resource "google_container_node_pool" "primary_preemptible_nodes" {
name = "my-node-pool"
region = "us-central1"
cluster = "${google_container_cluster.primary.name}"
node_count = 1
node_config {
preemptible = true
machine_type = "n1-standard-1"
oauth_scopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
]
}
}
# The following outputs allow authentication and connectivity to the GKE Cluster
# by using certificate-based authentication.
output "client_certificate" {
value = "${google_container_cluster.primary.master_auth.0.client_certificate}"
}
output "client_key" {
value = "${google_container_cluster.primary.master_auth.0.client_key}"
}
output "cluster_ca_certificate" {
value = "${google_container_cluster.primary.master_auth.0.cluster_ca_certificate}"
}
```
## Example Usage - with the default node pool
2015-06-20 22:57:45 +00:00
2017-04-17 10:17:54 +00:00
```hcl
2015-06-20 22:57:45 +00:00
resource "google_container_cluster" "primary" {
2017-02-18 22:48:50 +00:00
name = "marcellus-wallace"
zone = "us-central1-a"
2016-04-10 21:34:15 +00:00
initial_node_count = 3
2019-01-31 21:37:33 +00:00
# Setting an empty username and password explicitly disables basic auth
2016-04-10 21:34:15 +00:00
master_auth {
2019-01-31 21:37:33 +00:00
username = ""
password = ""
2016-04-10 21:34:15 +00:00
}
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
2017-02-18 22:48:50 +00:00
"https://www.googleapis.com/auth/monitoring",
2016-04-10 21:34:15 +00:00
]
2017-11-02 17:38:20 +00:00
2018-12-27 15:51:23 +00:00
labels = {
2017-06-17 19:07:10 +00:00
foo = "bar"
}
2017-11-02 17:38:20 +00:00
2017-06-17 19:07:10 +00:00
tags = ["foo", "bar"]
2016-04-10 21:34:15 +00:00
}
2019-02-01 21:26:59 +00:00
timeouts {
create = "30m"
update = "40m"
}
2015-06-20 22:57:45 +00:00
}
2017-11-02 17:11:12 +00:00
2019-01-31 21:37:33 +00:00
# The following outputs allow authentication and connectivity to the GKE Cluster
# by using certificate-based authentication.
2017-11-02 17:11:12 +00:00
output "client_certificate" {
value = "${google_container_cluster.primary.master_auth.0.client_certificate}"
}
output "client_key" {
value = "${google_container_cluster.primary.master_auth.0.client_key}"
}
output "cluster_ca_certificate" {
value = "${google_container_cluster.primary.master_auth.0.cluster_ca_certificate}"
}
2015-06-20 22:57:45 +00:00
```
## Argument Reference
2016-04-10 21:34:15 +00:00
* `name` - (Required) The name of the cluster, unique within the project and
zone.
- - -
2017-05-31 19:43:31 +00:00
2018-03-21 00:17:42 +00:00
* `zone` - (Optional) The zone that the master and the number of nodes specified
2018-04-05 21:51:35 +00:00
in `initial_node_count` should be created in. Only one of `zone` and `region`
may be set. If neither zone nor region are set, the provider zone is used.
2018-12-06 17:38:38 +00:00
* `region` (Optional)
2019-01-31 21:37:33 +00:00
The region to create the cluster in for
2018-04-05 21:51:35 +00:00
[Regional Clusters ](https://cloud.google.com/kubernetes-engine/docs/concepts/multi-zone-and-regional-clusters#regional ).
2018-12-12 18:04:34 +00:00
In a Regional Cluster, the number of nodes specified in `initial_node_count` is
2019-01-31 21:37:33 +00:00
created in each of three zones of the region (this can be changed by setting
`additional_zones` ).
2018-03-21 00:17:42 +00:00
2017-10-27 22:18:34 +00:00
* `additional_zones` - (Optional) The list of additional Google Compute Engine
locations in which the cluster's nodes should be located. If additional zones are
configured, the number of nodes specified in `initial_node_count` is created in
all specified zones.
2017-01-04 06:14:39 +00:00
2017-11-29 23:40:27 +00:00
* `addons_config` - (Optional) The configuration for addons supported by GKE.
Structure is documented below.
2016-04-10 21:34:15 +00:00
2017-11-29 23:40:27 +00:00
* `cluster_ipv4_cidr` - (Optional) The IP address range of the kubernetes pods in
2016-04-10 21:34:15 +00:00
this cluster. Default is an automatically assigned CIDR.
2018-11-15 20:35:41 +00:00
* `cluster_autoscaling` - (Optional, [Beta ](https://terraform.io/docs/providers/google/provider_versions.html ))
Configuration for cluster autoscaling (also called autoprovisioning), as described in
[the docs ](https://cloud.google.com/kubernetes-engine/docs/how-to/node-auto-provisioning ).
Structure is documented below.
2016-04-10 21:34:15 +00:00
* `description` - (Optional) Description of the cluster.
2018-11-14 18:59:58 +00:00
* `enable_binary_authorization` - (Optional, [Beta ](https://terraform.io/docs/providers/google/provider_versions.html )) Enable Binary Authorization for this cluster.
2018-08-17 00:51:03 +00:00
If enabled, all container images will be validated by Google Binary Authorization.
2017-10-31 23:38:18 +00:00
* `enable_kubernetes_alpha` - (Optional) 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.
2018-11-14 18:59:58 +00:00
* `enable_tpu` - (Optional, [Beta ](https://terraform.io/docs/providers/google/provider_versions.html )) Whether to enable Cloud TPU resources in this cluster.
2018-10-01 16:41:54 +00:00
See the [official documentation ](https://cloud.google.com/tpu/docs/kubernetes-engine-setup ).
2017-10-27 22:18:34 +00:00
* `enable_legacy_abac` - (Optional) Whether the ABAC authorizer is enabled for this cluster.
When enabled, identities in the system, including service accounts, nodes, and controllers,
will have statically granted permissions beyond those provided by the RBAC configuration or IAM.
2018-04-04 17:58:08 +00:00
Defaults to `false`
2018-06-19 22:57:25 +00:00
2017-10-27 22:18:34 +00:00
* `initial_node_count` - (Optional) The number of nodes to create in this
cluster (not including the Kubernetes master). Must be set if `node_pool` is not set.
2017-11-27 23:15:03 +00:00
* `ip_allocation_policy` - (Optional) Configuration for cluster IP allocation. As of now, only pre-allocated subnetworks (custom type with secondary ranges) are supported.
2018-03-08 17:08:14 +00:00
This will activate IP aliases. See the [official documentation ](https://cloud.google.com/kubernetes-engine/docs/how-to/ip-aliases )
Structure is documented below.
2017-11-27 23:15:03 +00:00
2016-04-10 21:34:15 +00:00
* `logging_service` - (Optional) The logging service that the cluster should
2018-06-04 22:09:52 +00:00
write logs to. Available options include `logging.googleapis.com` ,
`logging.googleapis.com/kubernetes` (beta), and `none` . Defaults to `logging.googleapis.com`
2016-04-10 21:34:15 +00:00
2017-11-27 23:15:03 +00:00
* `maintenance_policy` - (Optional) The maintenance policy to use for the cluster. Structure is
documented below.
2017-11-07 23:42:11 +00:00
2017-10-27 22:18:34 +00:00
* `master_auth` - (Optional) The authentication information for accessing the
Kubernetes master. Structure is documented below.
2017-11-02 17:38:20 +00:00
* `master_authorized_networks_config` - (Optional) The desired configuration options
for master authorized networks. Omit the nested `cidr_blocks` attribute to disallow
external access (except the cluster node IPs, which GKE automatically whitelists).
2017-10-12 18:21:33 +00:00
* `min_master_version` - (Optional) The minimum version of the master. GKE
will auto-update the master to new versions, so this does not guarantee the
current master version--use 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
2018-11-30 22:16:05 +00:00
official release (which is not necessarily the latest version). Most users will find
the `google_container_engine_versions` data source useful - it indicates which versions
are available. If you intend to specify versions manually, [the docs ](https://cloud.google.com/kubernetes-engine/versioning-and-upgrades#specifying_cluster_version )
describe the various acceptable formats for this field.
2017-10-12 18:21:33 +00:00
2018-11-13 19:01:00 +00:00
-> If you are using the `google_container_engine_versions` datasource with a regional cluster, ensure that you have provided a `region`
2018-12-12 18:04:34 +00:00
to the datasource. A `region` can have a different set of supported versions than its corresponding `zone` s, and not all `zone` s in a
2018-11-13 19:01:00 +00:00
`region` are guaranteed to support the same version.
2016-04-10 21:34:15 +00:00
* `monitoring_service` - (Optional) The monitoring service that the cluster
2018-06-15 20:21:51 +00:00
should write metrics to.
2018-03-08 17:08:14 +00:00
Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API.
VM metrics will be collected by Google Compute Engine regardless of this setting
Available options include
2018-06-04 22:09:52 +00:00
`monitoring.googleapis.com` , `monitoring.googleapis.com/kubernetes` (beta) and `none` .
Defaults to `monitoring.googleapis.com`
2016-04-10 21:34:15 +00:00
2016-11-14 23:49:43 +00:00
* `network` - (Optional) The name or self_link of the Google Compute Engine
2018-05-23 23:47:17 +00:00
network to which the cluster is connected. For Shared VPC, set this to the self link of the
shared network.
2016-04-10 21:34:15 +00:00
2017-11-27 20:40:07 +00:00
* `network_policy` - (Optional) Configuration options for the
[NetworkPolicy ](https://kubernetes.io/docs/concepts/services-networking/networkpolicies/ )
feature. Structure is documented below.
2017-10-27 22:18:34 +00:00
* `node_config` - (Optional) Parameters used in creating the cluster's nodes.
Structure is documented below.
2016-04-10 21:34:15 +00:00
2017-04-12 19:57:53 +00:00
* `node_pool` - (Optional) List of node pools associated with this cluster.
2017-10-27 22:18:34 +00:00
See [google_container_node_pool ](container_node_pool.html ) for schema.
2018-11-14 17:07:12 +00:00
**Warning:** node pools defined inside a cluster can't be changed (or added/removed) after
cluster creation without deleting and recreating the entire cluster. Unless you absolutely need the ability
to say "these are the _only_ node pools associated with this cluster", use the
[google_container_node_pool ](container_node_pool.html ) resource instead of this property.
2017-04-12 19:57:53 +00:00
2017-10-27 22:18:34 +00:00
* `node_version` - (Optional) The Kubernetes version on the nodes. Must either be unset
or set to the same value as `min_master_version` on create. Defaults to the default
2019-01-18 17:59:11 +00:00
version set by GKE which is not necessarily the latest version. This only affects
nodes in the default node pool. To update nodes in other node pools, use the `version`
attribute on the node pool.
2016-04-10 21:34:15 +00:00
2018-11-14 18:59:58 +00:00
* `pod_security_policy_config` - (Optional, [Beta ](https://terraform.io/docs/providers/google/provider_versions.html )) Configuration for the
2018-03-14 21:00:31 +00:00
[PodSecurityPolicy ](https://cloud.google.com/kubernetes-engine/docs/how-to/pod-security-policies ) feature.
Structure is documented below.
2018-12-06 17:38:38 +00:00
* `private_cluster_config` - (Optional) A set of options for creating
2018-10-05 20:19:06 +00:00
a private cluster. Structure is documented below.
2018-03-12 20:59:47 +00:00
* `project` - (Optional) The ID of the project in which the resource belongs. If it
2016-04-10 21:34:15 +00:00
is not provided, the provider project is used.
2015-06-20 22:57:45 +00:00
2018-03-23 00:22:44 +00:00
* `remove_default_node_pool` - (Optional) If true, deletes the default node pool upon cluster creation.
2018-06-25 08:55:27 +00:00
* `resource_labels` - (Optional) The GCE resource labels (a map of key/value pairs) to be applied to the cluster.
2018-06-15 10:10:25 +00:00
2018-05-23 23:47:17 +00:00
* `subnetwork` - (Optional) The name or self_link of the Google Compute Engine subnetwork in
2017-10-27 22:18:34 +00:00
which the cluster's instances are launched.
The `addons_config` block supports:
* `horizontal_pod_autoscaling` - (Optional) The status of the Horizontal Pod Autoscaling
addon, which increases or decreases the number of replica pods a replication controller
2018-06-15 20:21:51 +00:00
has based on the resource usage of the existing pods.
2018-03-08 17:08:14 +00:00
It ensures that a Heapster pod is running in the cluster, which is also used by the Cloud Monitoring service.
It is enabled by default;
2018-06-15 20:21:51 +00:00
set `disabled = true` to disable.
2019-01-31 21:37:33 +00:00
2017-10-27 22:18:34 +00:00
* `http_load_balancing` - (Optional) The status of the HTTP (L7) load balancing
controller addon, which makes it easy to set up HTTP load balancers for services in a
cluster. It is enabled by default; set `disabled = true` to disable.
2019-01-31 21:37:33 +00:00
2017-10-27 22:18:34 +00:00
* `kubernetes_dashboard` - (Optional) The status of the Kubernetes Dashboard
add-on, which controls whether the Kubernetes Dashboard is enabled for this cluster.
It is enabled by default; set `disabled = true` to disable.
2019-01-31 21:37:33 +00:00
2018-03-15 21:50:24 +00:00
* `network_policy_config` - (Optional) Whether we should enable the network policy addon
for the master. This must be enabled in order to enable network policy for the nodes.
It can only be disabled if the nodes already do not have network policies enabled.
Set `disabled = true` to disable.
2019-01-31 21:37:33 +00:00
2018-12-26 19:47:51 +00:00
* `istio_config` - (Optional, [Beta ](https://terraform.io/docs/providers/google/provider_versions.html )).
Structure is documented below.
2019-01-31 21:37:33 +00:00
2018-12-26 19:47:51 +00:00
* `cloudrun_config` - (Optional, [Beta ](https://terraform.io/docs/providers/google/provider_versions.html )).
The status of the CloudRun addon. It requires `istio_config` enabled. It is disabled by default.
Set `disabled = false` to enable. This addon can only be enabled at cluster creation time.
2016-04-14 23:30:39 +00:00
2017-10-27 22:18:34 +00:00
This example `addons_config` disables two addons:
```
addons_config {
http_load_balancing {
disabled = true
}
horizontal_pod_autoscaling {
disabled = true
}
}
```
2018-12-26 19:47:51 +00:00
The `istio_config` block supports:
* `disabled` - (Optional) The status of the Istio addon, which makes it easy to set up Istio for services in a
cluster. It is disabled by default. Set `disabled = false` to enable.
* `auth` - (Optional) The authentication type between services in Istio. Available options include `AUTH_MUTUAL_TLS` .
2018-11-15 20:35:41 +00:00
The `cluster_autoscaling` block supports:
* `enabled` - (Required) Whether cluster autoscaling (also called autoprovisioning) is
enabled. To set this to true, make sure your config meets the rest of the
requirements. Notably, you'll need `min_master_version` of at least `1.11.2` .
* `resource_limits` - (Optional) A list of limits on the autoprovisioning.
See [the docs ](https://cloud.google.com/kubernetes-engine/docs/how-to/node-auto-provisioning )
for an explanation of what options are available. If enabling autoprovisioning, make
sure to set at least `cpu` and `memory` . Structure is documented below.
The `resource_limits` block supports:
2019-01-31 21:37:33 +00:00
2018-11-15 20:35:41 +00:00
* `resource_type` - (Required) See [the docs ](https://cloud.google.com/kubernetes-engine/docs/how-to/node-auto-provisioning )
for a list of permitted types - `cpu` , `memory` , and others.
2019-01-31 21:37:33 +00:00
2018-11-15 20:35:41 +00:00
* `minimum` - (Optional) The minimum value for the resource type specified.
2019-01-31 21:37:33 +00:00
2018-11-15 20:35:41 +00:00
* `maximum` - (Optional) The maximum value for the resource type specified.
2017-11-07 23:42:11 +00:00
The `maintenance_policy` block supports:
* `daily_maintenance_window` - (Required) Time window specified for daily maintenance operations.
2017-11-27 23:15:03 +00:00
Specify `start_time` in [RFC3339 ](https://www.ietf.org/rfc/rfc3339.txt ) format "HH:MM”,
2017-11-07 23:42:11 +00:00
where HH : \[00-23\] and MM : \[00-59\] GMT. For example:
```
maintenance_policy {
daily_maintenance_window {
start_time = "03:00"
}
}
```
2017-11-27 23:15:03 +00:00
The `ip_allocation_policy` block supports:
* `cluster_secondary_range_name` - (Optional) The name of the secondary range to be
used as for the cluster CIDR block. The secondary range will be used for pod IP
addresses. This must be an existing secondary range associated with the cluster
subnetwork.
* `services_secondary_range_name` - (Optional) The name of the secondary range to be
used as for the services CIDR block. The secondary range will be used for service
ClusterIPs. This must be an existing secondary range associated with the cluster
subnetwork.
2018-09-05 16:52:06 +00:00
* `cluster_ipv4_cidr_block` - (Optional) 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)
2019-03-01 05:19:29 +00:00
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.
* `node_ipv4_cidr_block` - (Optional) The IP address range of the node IPs in this cluster.
Set to blank to have a range chosen with the default size. Set to /netmask (e.g. /14)
2018-09-05 16:52:06 +00:00
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.
* `services_ipv4_cidr_block` - (Optional) 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.
* `create_subnetwork` - (Optional) Whether a new subnetwork will be created automatically for the cluster.
* `subnetwork_name` - (Optional) A custom subnetwork name to be used if create_subnetwork is true.
If this field is empty, then an automatic name will be chosen for the new subnetwork.
2017-10-27 22:18:34 +00:00
The `master_auth` block supports:
2015-06-20 22:57:45 +00:00
2018-11-13 21:20:47 +00:00
* `password` - (Optional) The password to use for HTTP basic authentication when accessing
the Kubernetes master endpoint.
2016-04-10 21:34:15 +00:00
2018-11-13 21:20:47 +00:00
* `username` - (Optional) The username to use for HTTP basic authentication when accessing
the Kubernetes master endpoint. If not present basic auth will be disabled.
2015-06-20 22:57:45 +00:00
2018-06-19 22:57:25 +00:00
* `client_certificate_config` - (Optional) Whether client certificate authorization is enabled for this cluster. For example:
```
master_auth {
client_certificate_config {
issue_client_certificate = false
}
}
```
2018-01-17 20:54:42 +00:00
If this block is provided and both `username` and `password` are empty, basic authentication will be disabled.
2018-05-31 16:29:48 +00:00
This block also contains several computed attributes, documented below. If this block is not provided, GKE will generate a password for you with the username `admin` .
2018-01-17 20:54:42 +00:00
2017-11-02 17:38:20 +00:00
The `master_authorized_networks_config` block supports:
2018-07-05 20:10:17 +00:00
* `cidr_blocks` - (Optional) Defines up to 20 external networks that can access
2017-11-02 17:38:20 +00:00
Kubernetes master through HTTPS.
The `master_authorized_networks_config.cidr_blocks` block supports:
* `cidr_block` - (Optional) External network that can access Kubernetes master through HTTPS.
Must be specified in CIDR notation.
* `display_name` - (Optional) Field for users to identify CIDR blocks.
2017-11-27 20:40:07 +00:00
The `network_policy` block supports:
* `provider` - (Optional) The selected network policy provider. Defaults to PROVIDER_UNSPECIFIED.
* `enabled` - (Optional) Whether network policy is enabled on the cluster. Defaults to false.
2017-10-27 22:18:34 +00:00
The `node_config` block supports:
2016-04-10 21:34:15 +00:00
* `disk_size_gb` - (Optional) Size of the disk attached to each node, specified
in GB. The smallest allowed disk size is 10GB. Defaults to 100GB.
2018-06-15 20:21:51 +00:00
* `disk_type` - (Optional) Type of the disk attached to each node
(e.g. 'pd-standard' or 'pd-ssd'). If unspecified, the default disk type is 'pd-standard'
* `guest_accelerator` - (Optional) List of the type and count of accelerator cards attached to the instance.
2018-02-24 00:55:07 +00:00
Structure documented below.
2018-08-07 21:07:28 +00:00
* `image_type` - (Optional) The image type to use for this node. Note that changing the image type
will delete and recreate all nodes in the node pool.
2017-10-27 22:18:34 +00:00
* `labels` - (Optional) The Kubernetes labels (key/value pairs) to be applied to each node.
2017-02-27 15:25:27 +00:00
* `local_ssd_count` - (Optional) The amount of local SSD disks that will be
attached to each cluster node. Defaults to 0.
2017-10-27 22:18:34 +00:00
* `machine_type` - (Optional) The name of a Google Compute Engine machine type.
2018-05-15 23:10:04 +00:00
Defaults to `n1-standard-1` . To create a custom machine type, value should be set as specified
[here ](https://cloud.google.com/compute/docs/reference/latest/instances#machineType ).
2017-10-27 22:18:34 +00:00
* `metadata` - (Optional) The metadata key/value pairs assigned to instances in
the cluster.
* `min_cpu_platform` - (Optional) Minimum CPU platform to be used by this instance.
The instance may be scheduled on the specified or newer CPU platform. Applicable
values are the friendly names of CPU platforms, such as `Intel Haswell` . See the
[official documentation ](https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform )
for more information.
2016-04-10 21:34:15 +00:00
* `oauth_scopes` - (Optional) The set of Google API scopes to be made available
2016-11-14 23:50:24 +00:00
on all of the node VMs under the "default" service account. These can be
either FQDNs, or scope aliases. The following scopes are necessary to ensure
the correct functioning of the cluster:
* `compute-rw` (`https://www.googleapis.com/auth/compute`)
* `storage-ro` (`https://www.googleapis.com/auth/devstorage.read_only`)
* `logging-write` (`https://www.googleapis.com/auth/logging.write`),
if `logging_service` points to Google
* `monitoring` (`https://www.googleapis.com/auth/monitoring`),
if `monitoring_service` points to Google
2015-06-20 22:57:45 +00:00
2017-09-01 20:02:26 +00:00
* `preemptible` - (Optional) A boolean that represents whether or not the underlying node VMs
are preemptible. See the [official documentation ](https://cloud.google.com/container-engine/docs/preemptible-vm )
for more information. Defaults to false.
2017-10-27 22:18:34 +00:00
* `service_account` - (Optional) The service account to be used by the Node VMs.
If not specified, the "default" service account is used.
2018-11-13 22:42:16 +00:00
In order to use the configured `oauth_scopes` for logging and monitoring, the service account being used needs the
[roles/logging.logWriter ](https://cloud.google.com/iam/docs/understanding-roles#stackdriver_logging_roles ) and
[roles/monitoring.metricWriter ](https://cloud.google.com/iam/docs/understanding-roles#stackdriver_monitoring_roles ) roles.
-> Projects that enable the [Cloud Compute Engine API ](https://cloud.google.com/compute/ ) with Terraform may need these roles added manually to the service account. Projects that enable the API in the Cloud Console should have them added automatically.
2017-04-12 19:57:53 +00:00
2017-11-02 17:38:20 +00:00
* `tags` - (Optional) The list of instance tags applied to all nodes. Tags are used to identify
2017-10-27 22:18:34 +00:00
valid sources or targets for network firewalls.
2017-04-12 19:57:53 +00:00
2018-11-14 18:59:58 +00:00
* `taint` - (Optional, [Beta ](https://terraform.io/docs/providers/google/provider_versions.html )) List of
2018-03-27 21:55:42 +00:00
[kubernetes taints ](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ )
2018-11-14 18:59:58 +00:00
to apply to each node. Structure is documented below.
2018-03-27 21:55:42 +00:00
2018-11-14 18:59:58 +00:00
* `workload_metadata_config` - (Optional, [Beta ](https://terraform.io/docs/providers/google/provider_versions.html )) Metadata configuration to expose to workloads on the node pool.
Structure is documented below.
2018-03-15 20:28:30 +00:00
2018-02-24 00:55:07 +00:00
The `guest_accelerator` block supports:
* `type` (Required) - The accelerator type resource to expose to this instance. E.g. `nvidia-tesla-k80` .
* `count` (Required) - The number of the guest accelerator cards exposed to this instance.
2018-03-14 21:00:31 +00:00
The `pod_security_policy_config` block supports:
* `enabled` (Required) - Enable the PodSecurityPolicy controller for this cluster.
If enabled, pods must be valid under a PodSecurityPolicy to be created.
2018-10-05 20:19:06 +00:00
The `private_cluster_config` block supports:
* `enable_private_endpoint` (Optional) - Whether the master's internal IP address is used as the cluster endpoint.
* `enable_private_nodes` (Optional) - Whether nodes have internal IP addresses only. If enabled, all nodes are given only RFC 1918 private
addresses and communicate with the master via private networking.
* `master_ipv4_cidr_block` (Optional) - The IP range in CIDR notation to use for the hosted master network. This range will be used for
assigning internal IP addresses to the master or set of masters, as well as the ILB VIP. This range must not overlap with any other ranges
in use within the cluster's network.
In addition, the `private_cluster_config` allows access to the following read-only fields:
* `private_endpoint` - The internal IP address of this cluster's master endpoint.
* `public_endpoint` - The external IP address of this cluster's master endpoint.
2018-03-27 21:55:42 +00:00
The `taint` block supports:
* `key` (Required) Key for taint.
* `value` (Required) Value for taint.
* `effect` (Required) Effect for taint. Accepted values are `NO_SCHEDULE` , `PREFER_NO_SCHEDULE` , and `NO_EXECUTE` .
2018-03-15 20:28:30 +00:00
The `workload_metadata_config` block supports:
* `node_metadata` (Required) How to expose the node metadata to the workload running on the node.
Accepted values are:
* UNSPECIFIED: Not Set
* SECURE: Prevent workloads not in hostNetwork from accessing certain VM metadata, specifically kube-env, which contains Kubelet credentials, and the instance identity token. See [Metadata Concealment ](https://cloud.google.com/kubernetes-engine/docs/how-to/metadata-proxy ) documentation.
* EXPOSE: Expose all VM metadata to pods.
2015-06-20 22:57:45 +00:00
## Attributes Reference
2016-04-10 21:34:15 +00:00
In addition to the arguments listed above, the following computed attributes are
exported:
2017-10-27 22:18:34 +00:00
* `endpoint` - The IP address of this cluster's Kubernetes master.
2016-04-10 21:34:15 +00:00
* `instance_group_urls` - List of instance group URLs which have been assigned
2017-10-27 22:18:34 +00:00
to the cluster.
2016-04-10 21:34:15 +00:00
2017-11-07 23:42:11 +00:00
* `maintenance_policy.0.daily_maintenance_window.0.duration` - Duration of the time window, automatically chosen to be
2017-11-27 23:15:03 +00:00
smallest possible in the given scenario.
2017-11-07 23:42:11 +00:00
Duration will be in [RFC3339 ](https://www.ietf.org/rfc/rfc3339.txt ) format "PTnHnMnS".
2017-11-02 17:11:12 +00:00
* `master_auth.0.client_certificate` - Base64 encoded public certificate
2016-04-10 21:34:15 +00:00
used by clients to authenticate to the cluster endpoint.
2017-11-02 17:11:12 +00:00
* `master_auth.0.client_key` - Base64 encoded private key used by clients
2017-10-27 22:18:34 +00:00
to authenticate to the cluster endpoint.
2016-04-10 21:34:15 +00:00
2017-11-02 17:11:12 +00:00
* `master_auth.0.cluster_ca_certificate` - Base64 encoded public certificate
2017-10-27 22:18:34 +00:00
that is the root of trust for the cluster.
2017-06-28 08:22:31 +00:00
2017-10-12 18:21:33 +00:00
* `master_version` - The current version of the master in the cluster. This may
be different than the `min_master_version` set in the config if the master
has been updated by GKE.
2018-12-12 18:04:34 +00:00
* `tpu_ipv4_cidr_block` - ([Beta](https://terraform.io/docs/providers/google/provider_versions.html)) The IP address range of the Cloud TPUs in this cluster, in
2018-12-12 01:14:48 +00:00
[CIDR ](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing )
notation (e.g. `1.2.3.4/29` ).
2017-06-28 08:22:31 +00:00
< a id = "timeouts" > < / a >
## Timeouts
`google_container_cluster` provides the following
[Timeouts ](/docs/configuration/resources.html#timeouts ) configuration options:
- `create` - (Default `30 minutes` ) Used for clusters
2019-02-01 21:26:59 +00:00
- `update` - (Default `30 minutes` ) Used for updates to clusters
- `delete` - (Default `30 minutes` ) Used for destroying clusters.
2017-09-07 17:31:58 +00:00
## Import
2018-12-06 17:38:38 +00:00
GKE clusters can be imported using the `project` , `zone` or `region` , and `name` . If the project is omitted, the default
2018-10-04 20:20:35 +00:00
provider value will be used. Examples:
2017-09-07 17:31:58 +00:00
```
2018-04-03 20:39:28 +00:00
$ terraform import google_container_cluster.mycluster my-gcp-project/us-east1-a/my-cluster
2017-09-07 17:31:58 +00:00
$ terraform import google_container_cluster.mycluster us-east1-a/my-cluster
2017-11-02 17:11:12 +00:00
```
2019-02-28 21:08:55 +00:00
~> **Note:** This resource has several fields that control Terraform-specific behavior and aren't present in the API. If they are set in config and you import a cluster, Terraform may need to perform an update immediately after import. Some of these updates are no-ops, and some may modify your cluster.
For example:
- `min_master_version` will not be set on import and will show a no-op diff if set in config.
- `remove_default_node_pool` : If the default node pool exists at import, this value will be set to false in state (or true if non-existant). If set to true in config but the node pool exists, a follow-up diff/apply will delete the default node pool.