-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from bharathkkb/feature/gke-safe-cluster
Safer Cluster module
- Loading branch information
Showing
60 changed files
with
1,610 additions
and
80 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
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
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 @@ | ||
# Safer GKE Cluster | ||
|
||
This example illustrates how to instantiate the opinionated Safer Cluster module. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|:----:|:-----:|:-----:| | ||
| compute\_engine\_service\_account | Service account to associate to the nodes in the cluster | string | n/a | yes | | ||
| project\_id | The project ID to host the cluster in | string | n/a | yes | | ||
| region | The region to host the cluster in | string | `"us-central1"` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| ca\_certificate | The cluster ca certificate (base64 encoded) | | ||
| client\_token | The bearer token for auth | | ||
| cluster\_name | Cluster name | | ||
| kubernetes\_endpoint | The cluster endpoint | | ||
| location | | | ||
| master\_kubernetes\_version | Kubernetes version of the master | | ||
| network\_name | The name of the VPC being created | | ||
| project\_id | The project ID the cluster is in | | ||
| region | The region in which the cluster resides | | ||
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. | | ||
| subnet\_names | The names of the subnet being created | | ||
| zones | List of zones in which the cluster resides | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
To provision this example, run the following from within this directory: | ||
- `terraform init` to get the plugins | ||
- `terraform plan` to see the infrastructure plan | ||
- `terraform apply` to apply the infrastructure build | ||
- `terraform destroy` to destroy the built infrastructure |
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,68 @@ | ||
/** | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
resource "random_string" "suffix" { | ||
length = 4 | ||
special = false | ||
upper = false | ||
} | ||
|
||
locals { | ||
cluster_type = "safer-cluster" | ||
network_name = "safer-cluster-network-${random_string.suffix.result}" | ||
subnet_name = "safer-cluster-subnet-${random_string.suffix.result}" | ||
master_auth_subnetwork = "safer-cluster-master-subnet-${random_string.suffix.result}" | ||
pods_range_name = "ip-range-pods-${random_string.suffix.result}" | ||
svc_range_name = "ip-range-svc-${random_string.suffix.result}" | ||
} | ||
|
||
provider "google" { | ||
version = "~> 2.18.0" | ||
} | ||
|
||
provider "google-beta" { | ||
version = "~> 2.18.0" | ||
} | ||
|
||
module "gke" { | ||
source = "../../modules/safer-cluster/" | ||
project_id = var.project_id | ||
name = "${local.cluster_type}-cluster-${random_string.suffix.result}" | ||
regional = true | ||
region = var.region | ||
network = module.gcp-network.network_name | ||
subnetwork = module.gcp-network.subnets_names[0] | ||
ip_range_pods = local.pods_range_name | ||
ip_range_services = local.svc_range_name | ||
compute_engine_service_account = var.compute_engine_service_account | ||
master_ipv4_cidr_block = "172.16.0.0/28" | ||
master_authorized_networks_config = [ | ||
{ | ||
cidr_blocks = [ | ||
{ | ||
cidr_block = "10.60.0.0/17" | ||
display_name = "VPC" | ||
}, | ||
] | ||
}, | ||
] | ||
istio = true | ||
cloudrun = true | ||
} | ||
|
||
data "google_client_config" "default" { | ||
} | ||
|
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,48 @@ | ||
/** | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
module "gcp-network" { | ||
source = "terraform-google-modules/network/google" | ||
version = "~> 1.4.0" | ||
project_id = var.project_id | ||
network_name = local.network_name | ||
|
||
subnets = [ | ||
{ | ||
subnet_name = local.subnet_name | ||
subnet_ip = "10.0.0.0/17" | ||
subnet_region = var.region | ||
}, | ||
{ | ||
subnet_name = local.master_auth_subnetwork | ||
subnet_ip = "10.60.0.0/17" | ||
subnet_region = var.region | ||
}, | ||
] | ||
|
||
secondary_ranges = { | ||
"${local.subnet_name}" = [ | ||
{ | ||
range_name = local.pods_range_name | ||
ip_cidr_range = "192.168.0.0/18" | ||
}, | ||
{ | ||
range_name = local.svc_range_name | ||
ip_cidr_range = "192.168.64.0/18" | ||
}, | ||
] | ||
} | ||
} |
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,76 @@ | ||
/** | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
output "kubernetes_endpoint" { | ||
description = "The cluster endpoint" | ||
sensitive = true | ||
value = module.gke.endpoint | ||
} | ||
|
||
output "cluster_name" { | ||
description = "Cluster name" | ||
value = module.gke.name | ||
} | ||
|
||
output "location" { | ||
value = module.gke.location | ||
} | ||
|
||
output "master_kubernetes_version" { | ||
description = "Kubernetes version of the master" | ||
value = module.gke.master_version | ||
} | ||
|
||
output "client_token" { | ||
description = "The bearer token for auth" | ||
sensitive = true | ||
value = base64encode(data.google_client_config.default.access_token) | ||
} | ||
|
||
output "ca_certificate" { | ||
description = "The cluster ca certificate (base64 encoded)" | ||
value = module.gke.ca_certificate | ||
} | ||
|
||
output "service_account" { | ||
description = "The service account to default running nodes as if not overridden in `node_pools`." | ||
value = module.gke.service_account | ||
} | ||
|
||
output "network_name" { | ||
description = "The name of the VPC being created" | ||
value = module.gcp-network.network_name | ||
} | ||
|
||
output "subnet_names" { | ||
description = "The names of the subnet being created" | ||
value = module.gcp-network.subnets_names | ||
} | ||
|
||
output "region" { | ||
description = "The region in which the cluster resides" | ||
value = module.gke.region | ||
} | ||
|
||
output "zones" { | ||
description = "List of zones in which the cluster resides" | ||
value = module.gke.zones | ||
} | ||
|
||
output "project_id" { | ||
description = "The project ID the cluster is in" | ||
value = var.project_id | ||
} |
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,31 @@ | ||
/** | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
variable "project_id" { | ||
type = string | ||
description = "The project ID to host the cluster in" | ||
} | ||
|
||
variable "region" { | ||
type = string | ||
description = "The region to host the cluster in" | ||
default = "us-central1" | ||
} | ||
|
||
variable "compute_engine_service_account" { | ||
type = string | ||
description = "Service account to associate to the nodes in the cluster" | ||
} |
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,19 @@ | ||
/** | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
terraform { | ||
required_version = ">= 0.12" | ||
} |
Oops, something went wrong.