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

GKE stateful blueprints #2059

Merged
merged 137 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
7a74b28
var definitions
ludoo Jul 25, 2023
6556056
skeleton, untested
ludoo Jul 26, 2023
360555a
fix errors, test with existing cluster
ludoo Jul 27, 2023
929c9ea
test vpc creation, todo notes
ludoo Jul 27, 2023
1a499dd
Merge remote-tracking branch 'origin/master' into gke-blueprints/0-redis
ludoo Jul 27, 2023
a846ddc
initial variables for AR and image
ludoo Jul 27, 2023
ee4d17a
initial variables for AR and image
ludoo Jul 27, 2023
d58115f
Add support for remote repositories to artifact-registry
juliocc Jul 27, 2023
d0a5d86
Add support for virtual repositories to artifact-registry
juliocc Jul 27, 2023
885683a
Add support for extra config options to artifact-registry
juliocc Jul 27, 2023
3916a2e
artifact registry module: add validation and precondition, fix tests
ludoo Jul 27, 2023
80abf93
ar module id/name
ludoo Jul 28, 2023
32a677e
fix merge conflicts
ludoo Jul 28, 2023
11558d9
Merge remote-tracking branch 'origin/master' into gke-blueprints/0-redis
ludoo Jul 31, 2023
4c4f2b8
registry
ludoo Jul 31, 2023
daac844
Merge remote-tracking branch 'origin/master' into gke-blueprints/0-redis
ludoo Jul 31, 2023
f0ff47c
service accoutn and roles
ludoo Jul 31, 2023
1f82a76
fetch pods, remove image prefix
ludoo Jul 31, 2023
7b053e4
small changes
ludoo Aug 1, 2023
7311e7c
Merge remote-tracking branch 'origin/master' into gke-blueprints/0-redis
ludoo Aug 1, 2023
5fe8df1
use additive IAM at project level
ludoo Aug 1, 2023
53abfa7
use additive IAM at project level
ludoo Aug 1, 2023
601f00e
configmaps
ludoo Aug 1, 2023
68099fe
manifests
ludoo Aug 1, 2023
55e0386
fix statefulset manifest
ludoo Aug 1, 2023
41a023b
service manifest
ludoo Aug 1, 2023
6a0a434
fix configmap mode
ludoo Aug 1, 2023
b1e4dae
add todo
ludoo Aug 1, 2023
d978d6e
job (broken)
ludoo Aug 1, 2023
11b6f02
job
ludoo Aug 1, 2023
04a79ba
wait on manifest, endpoints datasource
ludoo Aug 1, 2023
e300ef9
fix job
ludoo Aug 1, 2023
c0dc921
Fix local
juliocc Aug 1, 2023
935d274
sa
ludoo Aug 1, 2023
c26a6e2
Update README.md
juliocc Aug 4, 2023
bbf398b
Merge remote-tracking branch 'origin/master' into gke-blueprints/0-redis
juliocc Aug 10, 2023
ba2be5f
Restructure gke bp
juliocc Aug 11, 2023
d719643
Merge remote-tracking branch 'origin/master' into gke-blueprints/0-redis
ludoo Aug 13, 2023
b2d643c
refactor tree and infra variables
ludoo Aug 13, 2023
9bcdda1
no create test
ludoo Aug 13, 2023
6c2e788
simplify cluster SA
ludoo Aug 13, 2023
043d83c
test cluster and vpc creation
ludoo Aug 13, 2023
a0633b8
Merge remote-tracking branch 'origin/master' into gke-blueprints/0-redis
ludoo Aug 14, 2023
ab1ad49
project creation fixes
ludoo Aug 14, 2023
0263f18
Merge remote-tracking branch 'origin/master' into gke-blueprints/0-redis
ludoo Aug 14, 2023
ff1a1bf
use iam_members variable
ludoo Aug 14, 2023
7ae9cce
nits
ludoo Aug 14, 2023
bb66f01
readme with examples
ludoo Aug 14, 2023
693f465
readme with examples
ludoo Aug 14, 2023
c3a33ff
outputs
ludoo Aug 14, 2023
b3020ee
variables, provider configuration
ludoo Aug 14, 2023
cec4959
variables, manifests
ludoo Aug 14, 2023
b3b634d
start cluster job
ludoo Aug 14, 2023
4f222f6
fix redis cluster creation
danielmarzini Aug 22, 2023
ffd35bb
Revert changes in autopilot cluster
juliocc Aug 23, 2023
10efffa
Default templates path, use namespace for node names
juliocc Aug 23, 2023
1724cbe
Merge branch 'master' into gke-blueprints/0-redis
juliocc Aug 31, 2023
a21d83e
Update readmes
juliocc Aug 31, 2023
b85d782
Fix IAM bindings
juliocc Sep 1, 2023
2eda48b
Make STABLE the default release channel
juliocc Sep 1, 2023
e29d707
Use Cloud DNS as default DNS provider
juliocc Sep 1, 2023
673b7c0
Allow optional Cloud NAT creation
juliocc Sep 1, 2023
00a3827
Allow backup agent and proxy only subnet
juliocc Sep 1, 2023
a6ed59d
Merge branch 'master' into gke-blueprints/0-redis
juliocc Sep 5, 2023
9d8bc14
Work around terraform not short-circuiting logical operators
juliocc Sep 5, 2023
6292e58
Rename create variables to be more consistent with other blueprints
juliocc Sep 5, 2023
c3b4f65
Add basic features
juliocc Sep 5, 2023
8f1bf53
Update variable names
juliocc Sep 5, 2023
7873340
Merge branch 'master' into gke-blueprints/0-redis
juliocc Sep 7, 2023
730a4fd
Initial kafka JS
juliocc Sep 7, 2023
ea7301b
Move providers to a new file
juliocc Sep 7, 2023
029c6e9
Kafka / Strimzi
danielmarzini Sep 12, 2023
5237bae
First possibily working version for MySQL (with a lot of todo's left)
wiktorn Sep 15, 2023
8508668
Explicitly use proxy repo + some other fixes
wiktorn Sep 18, 2023
74e0aca
Strimzi draft
danielmarzini Sep 18, 2023
ccd2b86
Merge branch 'gke-blueprints/0-redis' of https://github.com/GoogleClo…
danielmarzini Sep 18, 2023
a4f9d8f
Refactor variables, use CluterIP as pointer for mysql-router for boot…
wiktorn Sep 18, 2023
74de348
Validate number of replicas, autoscale required number of running nod…
wiktorn Sep 18, 2023
23ac522
Use seaprate service for bootstrap, do not recreate all resources on …
wiktorn Sep 19, 2023
a057705
Test dual chart kafka
juliocc Sep 19, 2023
c24e5df
Update chart for kafka
juliocc Sep 19, 2023
f26e14f
Expose basic kafka configuration options
juliocc Sep 19, 2023
0c2f8a2
Remove unused manifest
juliocc Sep 19, 2023
97e23ba
Added batch blueprint
apichick Sep 20, 2023
887144e
Merge remote-tracking branch 'upstream/gke-blueprints/0-redis' into g…
apichick Sep 20, 2023
9c576a7
Added README
apichick Sep 20, 2023
5de993b
switch to kubectl_manifest
danielmarzini Sep 20, 2023
78549b8
Add README and support for static IP address
wiktorn Sep 21, 2023
b00874e
Move namespace creation to helm
juliocc Sep 25, 2023
a599200
Interpolate kafka variables
juliocc Sep 25, 2023
c433259
Rename kafka-strimzi to kafka
juliocc Sep 25, 2023
b06a25e
Merge branch 'master' into gke-blueprints/0-redis
juliocc Sep 25, 2023
14a73df
Merge branch 'master' into gke-blueprints/0-redis
juliocc Jan 23, 2024
4dce5db
Added TUTORIAL for cloudshell for batch blueprint
apichick Feb 6, 2024
9f9afe2
Merge remote-tracking branch 'upstream/gke-blueprints/0-redis' into g…
apichick Feb 6, 2024
423d9ef
deleted tutorial
apichick Feb 6, 2024
802bb2d
Merge branch 'master' into gke-blueprints/0-redis
juliocc Feb 6, 2024
9b7fbff
Remove commented replace trigger
wiktorn Sep 26, 2023
c90c074
Move to helm chart
wiktorn Sep 28, 2023
aff968b
WIP of Cloud Shell tutorial for MySQL
wiktorn Feb 6, 2024
9a8693e
Rename folders
juliocc Feb 6, 2024
7457964
Fix rename
juliocc Feb 6, 2024
66c7146
Update paths
juliocc Feb 6, 2024
d997304
Unify styles
juliocc Feb 6, 2024
0ac8380
Update paths
juliocc Feb 7, 2024
2e38e6d
Add Readme links
juliocc Feb 7, 2024
510a14f
Update mysql tutorial
wiktorn Feb 7, 2024
b4eb7a2
Fix path according to self-link
wiktorn Feb 7, 2024
deee95a
Use relative path to cwd
wiktorn Feb 7, 2024
553455d
Fix service_account variable location
wiktorn Feb 7, 2024
2d8380e
Fix tfvars creation
wiktorn Feb 7, 2024
97d330b
Restore some fixes for helm deployment
wiktorn Feb 7, 2024
6d9f128
Add cluster deletion_prevention
wiktorn Feb 7, 2024
55d1c81
Fixes for tutorial
wiktorn Feb 7, 2024
e289a5a
Update cluster docs
juliocc Feb 8, 2024
fe7fa23
Fixes to batch tutorial
juliocc Feb 8, 2024
86f3c91
Bare bones readme for batch
juliocc Feb 8, 2024
b0226f4
Update batch readme
juliocc Feb 8, 2024
763fc0b
README fixes
juliocc Feb 8, 2024
37e5a71
Fix README title for redis
juliocc Feb 8, 2024
0c5e110
Fix Typos
juliocc Feb 8, 2024
b16a237
Make it easy to pass variables from autopilot-cluster to other modules
wiktorn Feb 8, 2024
a2f25c2
Add connectivity test and bastion host
wiktorn Feb 8, 2024
e75d8d6
updates to readme, and gpu fix
apichick Feb 8, 2024
65705e0
Add versions.tf and README updates
juliocc Feb 8, 2024
4537a30
Merge remote-tracking branch 'origin/gke-blueprints/0-redis' into gke…
juliocc Feb 8, 2024
bad8e1d
Fix typo
juliocc Feb 8, 2024
d3c5058
Kafka and Redis README updates
juliocc Feb 8, 2024
ff33488
Merge remote-tracking branch 'origin/master' into gke-blueprints/0-redis
juliocc Feb 8, 2024
756c983
Update versions.tf
juliocc Feb 8, 2024
010b067
Fixes
juliocc Feb 8, 2024
09316f3
Add boilerplate
juliocc Feb 8, 2024
3589b49
Fix linting
juliocc Feb 8, 2024
cbe4dc3
Move mysql to separate branch
juliocc Feb 8, 2024
3fd32ae
Update cloud shell links
juliocc Feb 8, 2024
889c2c6
Fix broken link
juliocc Feb 8, 2024
cd168cc
Fix all years
juliocc Feb 8, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ blueprints/gke/autopilot/ansible/gssh.sh
blueprints/gke/autopilot/ansible/vars/vars.yaml
blueprints/gke/autopilot/bundle/monitoring/kustomization.yaml
blueprints/gke/autopilot/bundle/locust/kustomization.yaml
blueprints/gke/autopilot/bundle.tar.gz
blueprints/gke/autopilot/bundle.tar.gz
blueprints/gke/patterns/batch/job-*.yaml
5 changes: 5 additions & 0 deletions blueprints/gke/patterns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# GKE Jumpstart Blueprints

This directory includes several blueprints related to Google Kubernetes Engine (GKE), following Google recommendations and best practices. The blueprints in this directory split the deployment process into two stages: an initial infrastructure stage that provisions the cluster, and additional workload stages that deploy specific types of applications/workloads.

As a design rule, all the blueprints in this directory provide sensible defaults for most variables while still providing an enterprise-grade deployment with secure defaults and the ability to use existing resources that are typically found in an enterprise-grade environment.
112 changes: 112 additions & 0 deletions blueprints/gke/patterns/autopilot-cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# GKE Autopilot Cluster Pattern

This blueprint illustrates how to use GKE features to deploy a secure cluster that meets Google's best practices. The cluster deployed by this blueprint can be used to deploy other blueprints such as [Redis](../redis-cluster), [Kafka](../kafka), [Kueue](../batch).

<!-- BEGIN TOC -->
- [Design Decisions](#design-decisions)
- [GKE Onboarding Best Practices](#gke-onboarding-best-practices)
- [Environment setup](#environment-setup)
- [Cluster configuration](#cluster-configuration)
- [Security](#security)
- [Networking](#networking)
- [Multitenancy](#multitenancy)
- [Monitoring](#monitoring)
- [Maintenance](#maintenance)
- [Variables](#variables)
- [Outputs](#outputs)
<!-- END TOC -->

## Design Decisions

The main purpose of this blueprint is to showcase how to use GKE features to deploy a secure Kubernetes cluster according to Google best practices, including:

- **No public IP addresses** both the control plane and the nodes use private IP addresses. To to simplify the deployment of workloads, we enable [Connect Gateway](https://cloud.google.com/anthos/multicluster-management/gateway) to securely access the control plane even from outside the cluster's VPC. We also use [Remote Repositories](https://cloud.google.com/artifact-registry/docs/repositories/remote-overview) to allow the download of container images by the cluster without requiring Internet egress configured in the clusters's VPC.

- We provide **reasonable but secure defaults** that the user can override. For example, by default we avoid deploying a Cloud NAT gatewayt, but it is possible to enable it with just a few changes to the configuration.

- **Bring your own infrastructure**: that larger organizations might have teams dedicated to the provisioning and management of centralized infrastructure. This blueprint can be deployed to create any required infrastructure (GCP project, VPC, Artifact Registry, etc), or you can leverage existing resources by setting the appropriate variables.

## GKE Onboarding Best Practices

This Terraform blueprint helps you quickly implement most of the [GKE oboarding best practices](https://cloud.google.com/kubernetes-engine/docs/best-practices/onboarding#set-up-terraform) as outlined in the official GKE documentation. In this section we describe the relevant the decisions this blueprint simplifies


### Environment setup
- Set up Terraform: you'll need to install Terraform to use this blueprint. Instructions are [available here](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started).
- Terraform state storage: this blueprint doesn't automate this step but can easily be done by specifying a [backend](https://developer.hashicorp.com/terraform/language/settings/backends/gcs).
- Create a metrics scope using Terraform: if you're creating a new project with this blueprint, you can enable metrics scope using the `metrics_scope` variable in the `project` module. Otherwise, metrics scope setup occurs outside this blueprint's scope.
- Set up Artifact Registry: by default a remote repository is created to allow downloading container images

### Cluster configuration
This blueprint by default deploys an Autopilot cluster with private nodes and private control plane. By using Autopilot, Google automatically handles node configuration, scaling, and security

- Choose a mode of operation: this blueprint uses Autopilot clusters
- Isolate your cluster: this blueprint deploys a private cluster, with private control plane
- Configure backup for GKE: not configured but can easily be enabled through the `backup_configs` in the `gke-cluster-autopilot` module.
- Use Container-Optimized OS node images: Autopilot cluster always user COS
- Enable node auto-provisioning: automatically managed by Autopilot
- Separate kube-system Pods: automatically managed by Autopilot

### Security
- Use the security posture dashboard: enabled by default in new clusters
- Use group authentication: not needed by this blueprint but can be enabled through the `enable_features.groups_for_rbac` variable of the `gke-cluster-autopilot` module.
- Use RBAC to restrict access to cluster resources: this blueprint deploys the underlying infrastructure, RBAC configuration is out of scope.
- Enable Shielded GKE Nodes: automatically managed by Autopilot
- Enable Workload Identity: automatically managed by Autopilot
- Enable security bulletin notifications: out of scope for this blueprint
- Use least privilege Google service accounts: this blueprint creates a new service account for the cluster
- Restrict network access to the control plane and nodes: this blueprint deploys a private cluster
- Use namespaces to restrict access to cluster resources: this blueprint deploys the underlying infrastructure, namespace handling is left to applications.

### Networking
- Create a custom mode VPC: this blueprint can optinally deploy a new custom VPC with a single subnet. Otherwise, an existing VPC and subnet can be used.
- Create a proxy-only subnet: the `vpc_create` variable allows the creation of proxy only subnet, if needed.
- Configure Shared VPC: by default a new VPC is created within the project, but a Shared VPC can be used when the blueprint handles project creation.
- Connect the cluster's VPC network to an on-premises network: skipped, out of scope for this blueprint
- Enable Cloud NAT: the `vpc_create` variable allows the creation of Cloud NAT, if needed.
- Configure Cloud DNS for GKE: not needed by this blueprint but can be enabled through the `enable_features.dns` variable of the `gke-cluster-autopilot` module.
- Configure NodeLocal DNSCache: not needed by this blueprint
- Create firewall rules: only the default rules created by GKE

### Multitenancy
For simplicity, multi-tenancy is not used in this blueprint.

### Monitoring
- Configure GKE alert policies: out of scope for this blueprint
- Enable Google Cloud Managed Service for Prometheus: automatically managed by Autopilot
- Configure control plane metrics: enabled by default
- Enable metrics packages: out of scope for this blueprint

### Maintenance
- Create environments: out of scope for this blueprint
- Subscribe to Pub/Sub events: out of scope for this blueprint
- Enroll in release channels: the REGULAR channel is used by default
- Configure maintenance windows: not configured but can be enabled through the `maintenance_config` in the `gke-cluster-autopilot` module.
- Set Compute Engine quotas: out of scope for this blueprint
- Configure cost controls: TBD
- Configure billing alerts: out of scope for this blueprint
<!-- BEGIN TFDOC -->
## Variables

| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
| [cluster_name](variables.tf#L42) | Name of new or existing cluster. | <code>string</code> | ✓ | |
| [project_id](variables.tf#L70) | Project id of existing or created project. | <code>string</code> | ✓ | |
| [region](variables.tf#L75) | Region used for cluster and network resources. | <code>string</code> | ✓ | |
| [cluster_create](variables.tf#L17) | Cluster configuration for newly created cluster. Set to null to use existing cluster, or create using defaults in new project. | <code title="object&#40;&#123;&#10; deletion_protection &#61; optional&#40;bool, true&#41;&#10; labels &#61; optional&#40;map&#40;string&#41;&#41;&#10; master_authorized_ranges &#61; optional&#40;map&#40;string&#41;, &#123;&#10; rfc-1918-10-8 &#61; &#34;10.0.0.0&#47;8&#34;&#10; &#125;&#41;&#10; master_ipv4_cidr_block &#61; optional&#40;string, &#34;172.16.255.0&#47;28&#34;&#41;&#10; vpc &#61; optional&#40;object&#40;&#123;&#10; id &#61; string&#10; subnet_id &#61; string&#10; secondary_range_names &#61; optional&#40;object&#40;&#123;&#10; pods &#61; optional&#40;string, &#34;pods&#34;&#41;&#10; services &#61; optional&#40;string, &#34;services&#34;&#41;&#10; &#125;&#41;, &#123;&#125;&#41;&#10; &#125;&#41;&#41;&#10; options &#61; optional&#40;object&#40;&#123;&#10; release_channel &#61; optional&#40;string, &#34;REGULAR&#34;&#41;&#10; enable_backup_agent &#61; optional&#40;bool, false&#41;&#10; &#125;&#41;, &#123;&#125;&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [fleet_project_id](variables.tf#L47) | GKE Fleet project id. If null cluster project will also be used for fleet. | <code>string</code> | | <code>null</code> |
| [prefix](variables.tf#L53) | Prefix used for resource names. | <code>string</code> | | <code>&#34;jump-0&#34;</code> |
| [project_create](variables.tf#L60) | Project configuration for newly created project. Leave null to use existing project. Project creation forces VPC and cluster creation. | <code title="object&#40;&#123;&#10; billing_account &#61; string&#10; parent &#61; optional&#40;string&#41;&#10; shared_vpc_host &#61; optional&#40;string&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [registry_create](variables.tf#L80) | Create remote Docker Artifact Registry. | <code>bool</code> | | <code>true</code> |
| [vpc_create](variables.tf#L86) | Project configuration for newly created VPC. Leave null to use existing VPC, or defaults when project creation is required. | <code title="object&#40;&#123;&#10; name &#61; optional&#40;string&#41;&#10; subnet_name &#61; optional&#40;string&#41;&#10; primary_range_nodes &#61; optional&#40;string, &#34;10.0.0.0&#47;24&#34;&#41;&#10; secondary_range_pods &#61; optional&#40;string, &#34;10.16.0.0&#47;20&#34;&#41;&#10; secondary_range_services &#61; optional&#40;string, &#34;10.32.0.0&#47;24&#34;&#41;&#10; enable_cloud_nat &#61; optional&#40;bool, false&#41;&#10; proxy_only_subnet &#61; optional&#40;string&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |

## Outputs

| name | description | sensitive |
|---|---|:---:|
| [created_resources](outputs.tf#L17) | IDs of the resources created, if any. | |
| [credentials_config](outputs.tf#L44) | Configure how Terraform authenticates to the cluster. | |
| [fleet_host](outputs.tf#L51) | Fleet Connect Gateway host that can be used to configure the GKE provider. | |
| [get_credentials](outputs.tf#L56) | Run one of these commands to get cluster credentials. Credentials via fleet allow reaching private clusters without no direct connectivity. | |
| [region](outputs.tf#L70) | Region used for cluster and network resources. | |
<!-- END TFDOC -->
134 changes: 134 additions & 0 deletions blueprints/gke/patterns/autopilot-cluster/cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* Copyright 2024 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.
*/

locals {
_cluster_sa = (
local.cluster_create
? module.cluster-service-account.0.email
: data.google_container_cluster.cluster.0.node_config.0.service_account
)
cluster_sa = (
local._cluster_sa == "default"
? module.project.service_accounts.default.compute
: local._cluster_sa
)
cluster_sa_roles = [
"roles/artifactregistry.reader",
"roles/logging.logWriter",
"roles/monitoring.metricWriter",
"roles/monitoring.viewer",
"roles/stackdriver.resourceMetadata.writer"
]
cluster_vpc = (
local.use_shared_vpc || !local.vpc_create
# cluster variable configures networking
? {
network = try(
var.cluster_create.vpc.id, null
)
secondary_range_names = try(
var.cluster_create.vpc.secondary_range_names, null
)
subnet = try(
var.cluster_create.vpc.subnet_id, null
)
}
# VPC creation configures networking
: {
network = module.vpc.0.id
secondary_range_names = { pods = "pods", services = "services" }
subnet = values(module.vpc.0.subnet_ids)[0]
}
)
}

data "google_container_cluster" "cluster" {
count = !local.cluster_create ? 1 : 0
project = var.project_id
location = var.region
name = var.cluster_name
}

module "cluster-service-account" {
source = "../../../../modules/iam-service-account"
count = local.cluster_create ? 1 : 0
project_id = module.project.project_id
name = var.prefix
}

module "cluster" {
source = "../../../../modules/gke-cluster-autopilot"
count = local.cluster_create ? 1 : 0
project_id = module.project.project_id
deletion_protection = var.cluster_create.deletion_protection
name = var.cluster_name
location = var.region
vpc_config = {
network = local.cluster_vpc.network
subnetwork = local.cluster_vpc.subnet
secondary_range_names = local.cluster_vpc.secondary_range_names
master_authorized_ranges = var.cluster_create.master_authorized_ranges
master_ipv4_cidr_block = var.cluster_create.master_ipv4_cidr_block
}
private_cluster_config = {
enable_private_endpoint = true
master_global_access = true
}
node_config = {
service_account = module.cluster-service-account.0.email
}
labels = var.cluster_create.labels
release_channel = var.cluster_create.options.release_channel
backup_configs = {
enable_backup_agent = var.cluster_create.options.enable_backup_agent
}
enable_features = {
dns = {
provider = "CLOUD_DNS"
scope = "CLUSTER_SCOPE"
domain = "cluster.local"
}
cost_management = true
gateway_api = true
}
monitoring_config = {
enable_api_server_metrics = true
enable_controller_manager_metrics = true
enable_scheduler_metrics = true
}
logging_config = {
enable_api_server_logs = true
enable_scheduler_logs = true
enable_controller_manager_logs = true
}
maintenance_config = {
daily_window_start_time = "01:00"
}
}

check "cluster_networking" {
assert {
condition = (
local.use_shared_vpc
? (
try(var.cluster_create.vpc.id, null) != null &&
try(var.cluster_create.vpc.subnet_id, null) != null
)
: true
)
error_message = "Cluster network and subnetwork are required in shared VPC mode."
}
}
Loading
Loading