-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
317 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
solutions_builder/modules/terraform_gke_autopilot/.sb/module_answers/{{component_name}}.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Changes here will be overwritten by Copier | ||
{{_copier_answers|to_nice_yaml -}} |
55 changes: 55 additions & 0 deletions
55
solutions_builder/modules/terraform_gke_autopilot/copier.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
_metadata: | ||
module_name: terraform_gke | ||
version: 1.0.0 | ||
destination_path: . | ||
|
||
# questions | ||
component_name: | ||
type: str | ||
help: What is the name of this component (snake_case)? | ||
default: terraform_gke | ||
|
||
terraform_stage_name: | ||
type: str | ||
help: Terraform stage name? | ||
default: 3-gke-autopilot | ||
|
||
gcp_region: | ||
type: str | ||
help: Which Google Cloud region? | ||
default: us-central1 | ||
|
||
cluster_name: | ||
type: str | ||
help: GKE cluster name? | ||
default: main-cluster | ||
|
||
kubernetes_version: | ||
type: str | ||
help: Kubernetes version? | ||
default: latest | ||
# See https://cloud.google.com/kubernetes-engine/docs/release-notes-stable | ||
|
||
_answers_file: ".st/module_answers/{{component_name}}.yaml" | ||
|
||
_templates_suffix: "" | ||
|
||
_patch: [] | ||
|
||
_exclude: | ||
- "README.md" | ||
- "copier.yaml" | ||
- "copier_extensions" | ||
- ".terraform*" | ||
- ".tmp" | ||
- ".venv" | ||
- ".pytest_cache" | ||
- "__pycache__" | ||
- "*-debug.log" | ||
- ".skip" | ||
- "README.md" | ||
|
||
_jinja_extensions: | ||
- jinja2_time.TimeExtension | ||
- copier_templates_extensions.TemplateExtensionLoader | ||
- ../../copier_extensions/sb_helpers.py:SolutionsTemplateHelpersExtension |
37 changes: 37 additions & 0 deletions
37
...s_builder/modules/terraform_gke_autopilot/docs/components/{{component_name}}.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Module: Terraform GKE Stage | ||
|
||
This module defines a Terraform GKE setup stage named "3-gke-autopillot". | ||
|
||
Main components after setup: | ||
- ./terraform/stage/3-gke-autopillot | ||
|
||
## Setup | ||
|
||
Run `st components add [COMPONENT_NAME]` to add this module. | ||
``` | ||
cd my-solution-folder | ||
sb components add terraform_gke_autopilot | ||
``` | ||
|
||
Fill in the variables. | ||
``` | ||
🎤 What is the name of this terraform stage? | ||
3-gke-autopillot | ||
🎤 Which Google Cloud region? | ||
us-central1 | ||
... | ||
Complete. Component terraform_gke added to solution at . | ||
``` | ||
|
||
Initialize the terraform stage using `st init --stage=[STAGE_NAME]` | ||
``` | ||
sb init --stage=3-gke | ||
``` | ||
|
||
## Development | ||
|
||
## FAQ | ||
|
||
|
23 changes: 23 additions & 0 deletions
23
...lder/modules/terraform_gke_autopilot/terraform/stages/{{terraform_stage_name}}/backend.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright 2023 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 | ||
* | ||
* https://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. | ||
* | ||
*/ | ||
|
||
terraform { | ||
backend "gcs" { | ||
bucket = "{{project_id}}-tfstate" # sb-var:project_id:{{project_id}}-tfstate | ||
prefix = "stage/{{terraform_stage_name}}" | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
..._builder/modules/terraform_gke_autopilot/terraform/stages/{{terraform_stage_name}}/iam.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright 2023 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 | ||
* | ||
* https://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 { | ||
# TODO: Add users to your project below. | ||
role_members = { | ||
admin = [ | ||
# "user:[email protected]", | ||
] | ||
breakglass = [ | ||
# "user:[email protected]", | ||
] | ||
editor = [ | ||
# "user:[email protected]", | ||
] | ||
viewer = [ | ||
# "user:[email protected]", | ||
] | ||
} | ||
} | ||
|
||
# Additive IAM bindings. Must not conflict with authoritative bindings below. | ||
module "projects_iam_bindings" { | ||
source = "terraform-google-modules/iam/google//modules/projects_iam" | ||
version = "7.4.1" | ||
|
||
projects = [var.project_id] | ||
mode = "additive" | ||
|
||
bindings = { | ||
"roles/owner" = flatten([ | ||
local.role_members.admin, | ||
]) | ||
"roles/editor" = flatten([ | ||
local.role_members.breakglass, | ||
local.role_members.editor, | ||
]) | ||
"roles/viewer" = flatten([ | ||
local.role_members.viewer | ||
]) | ||
"roles/resourcemanager.projectIamAdmin" = flatten([ | ||
local.role_members.breakglass, | ||
local.role_members.admin, | ||
]) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...builder/modules/terraform_gke_autopilot/terraform/stages/{{terraform_stage_name}}/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2023 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 | ||
* | ||
* https://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. | ||
* | ||
*/ | ||
|
||
# project-specific locals | ||
locals { | ||
vpc_network = data.terraform_remote_state.foundation.outputs.vpc_network | ||
vpc_subnetwork = data.terraform_remote_state.foundation.outputs.vpc_subnetwork | ||
service_account_name = "gke-sa" | ||
default_namespace = "default" | ||
} | ||
|
||
data "google_project" "project" {} | ||
|
||
data "terraform_remote_state" "foundation" { | ||
backend = "gcs" | ||
config = { | ||
bucket = "${var.project_id}-tfstate" | ||
prefix = "stage/2-foundation" | ||
} | ||
} | ||
|
||
resource "google_container_cluster" "primary" { | ||
name = var.cluster_name | ||
location = var.region | ||
|
||
network = local.vpc_network | ||
subnetwork = local.vpc_subnetwork | ||
|
||
# Enabling Autopilot for this cluster | ||
enable_autopilot = true | ||
deletion_protection = false | ||
} | ||
|
||
resource "google_service_account" "service_account" { | ||
account_id = local.service_account_name | ||
display_name = "Service Account for GKE" | ||
} |
40 changes: 40 additions & 0 deletions
40
...er/modules/terraform_gke_autopilot/terraform/stages/{{terraform_stage_name}}/providers.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright 2023 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 | ||
* | ||
* https://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. | ||
* | ||
*/ | ||
|
||
# Terraform Block | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = ">= 4.50.0" | ||
} | ||
kubectl = { | ||
source = "gavinbunney/kubectl" | ||
version = ">= 1.14.0" | ||
} | ||
helm = { | ||
source = "hashicorp/helm" | ||
version = ">= 2.7.0" | ||
} | ||
} | ||
} | ||
|
||
provider "google" { | ||
project = var.project_id | ||
} | ||
|
||
data "google_client_config" "default" {} |
4 changes: 4 additions & 0 deletions
4
...odules/terraform_gke_autopilot/terraform/stages/{{terraform_stage_name}}/terraform.tfvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
project_id = "{{project_id}}" # sb-var:project_id | ||
region = "{{gcp_region}}" # sb-var:gcp_region | ||
kubernetes_version = "{{kubernetes_version}}" | ||
cluster_name = "{{cluster_name}}" |
42 changes: 42 additions & 0 deletions
42
...er/modules/terraform_gke_autopilot/terraform/stages/{{terraform_stage_name}}/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright 2023 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 | ||
* | ||
* https://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. | ||
* | ||
*/ | ||
|
||
variable "project_id" { | ||
type = string | ||
description = "GCP Project ID" | ||
|
||
validation { | ||
condition = length(var.project_id) > 0 | ||
error_message = "The project_id value must be an non-empty string." | ||
} | ||
} | ||
|
||
variable "region" { | ||
type = string | ||
description = "Default GCP region" | ||
default = "us-central1" | ||
|
||
validation { | ||
condition = length(var.region) > 0 | ||
error_message = "The region value must be an non-empty string." | ||
} | ||
} | ||
|
||
variable "cluster_name" { | ||
type = string | ||
default = "main-cluster" | ||
} |