Skip to content

Adapting for use with latest providers #144

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ crash.log
**/.kitchen
**/.kitchen.local.yml
**/Gemfile.lock
terraform.tfvars

test/fixtures/shared/terraform.tfvars

Expand Down
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Expand All @@ -8,6 +9,28 @@ Extending the adopted spec, each change should have a link to its corresponding

## [Unreleased]

### Added

* variable `initial_node_count` added to provide a mechanism to control the
default node pool's size. This replaces the cluster's inline `node_pool` block
as that block no longer works with recent provider versions.
**Note for admins of existing clusters:** depending on a cluster's state,
cluster admins may need to adjust this variable when upgrading this module and
provider to ensure clusters aren't deleted and recreated. Review the
`terraform plan` carefully!

### Changed

* `google_container_engine_versions` data lookups and cluster resources now use
the `location` attribute instead of `zone` or `region` (deprecated). This also
allowed 2 data lookups to collapse into one.
* updated `combine_docfiles.py` to match that of
[terraform-google-module-template](https://github.com/terraform-google-modules/terraform-google-module-template)
* `make` tasks and `generation` processes improved around the edges
* Documentation now adheres to markdownlint.
* jinja syntax now wrapped in tf comments making all files in `/autogen`
lintable.

## [v2.0.0] - 2019-04-12

### Added
Expand Down Expand Up @@ -40,7 +63,9 @@ Extending the adopted spec, each change should have a link to its corresponding
* Fix empty zone list. [#132]

## [v1.0.0] - 2019-03-25

### Added

* Allow creation of service accounts. [#80]
* Add support for private clusters via submodule. [#69]
* Add `remove_default_node_pool` set to `false` by default. Fixes [#15]. [#55]
Expand All @@ -59,25 +84,32 @@ Extending the adopted spec, each change should have a link to its corresponding
* Update the google and google-beta providers to v2.2 [#106]

### Fixed

* Zonal clusters can now accept a single zone. Fixes [#43]. [#50]
* Fix link to "configure a service account" [#73]
* Fix issue with regional cluster roll outs causing version skews [#108]
* Fix permanent metadata skew due to disable-legacy-endpoints keys [#114]

## [v0.4.0] - 2018-12-19

### Added

* Added support for testing with kitchen-terraform. [#33]
* Added support for preemptible nodes. [#38]

### Changed

* Updated default version to `1.10.6`. [#31]

### Fixed

* `region` argument on google_compute_subnetwork caused errors. [#22]
* Added check to wait for GKE cluster to be `READY` before completing. [#46]

## [v0.3.0] - 2018-10-10

### Changed

* Updated network/subnetwork lookup to use data source. [#16]
* Make zone configuration optional when creating a regional cluster. [#19]

Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ test_integration:
generate_docs:
@source test/make.sh && generate_docs

.PHONY: generate
generate:
.PHONY: generate_code
generate_code:
@source test/make.sh && generate

.PHONY: generate
generate: generate_code generate_docs

# Versioning
.PHONY: version
version:
Expand Down
96 changes: 55 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@

This module handles opinionated Google Cloud Platform Kubernetes Engine cluster creation and configuration with Node Pools, IP MASQ, Network Policy, etc.
The resources/services/activations/deletions that this module will create/trigger are:

- Create a GKE cluster with the provided addons
- Create GKE Node Pool(s) with provided configuration and attach to cluster
- Replace the default kube-dns configmap if `stub_domains` are provided
- Activate network policy if `network_policy` is true
- Add `ip-masq-agent` configmap with provided `non_masquerade_cidrs` if `network_policy` is true


## Usage

There are multiple examples included in the [examples](./examples/) folder but simple usage is as follows:

```hcl
provider "google" {
project = "<PROJECT ID>"
region = "us-central1"
version = "~> 2.5"
}

provider "google-beta" {
project = "<PROJECT ID>"
region = "us-central1"
version = "~> 2.5"
}

module "gke" {
source = "terraform-google-modules/kubernetes-engine/google"
project_id = "<PROJECT ID>"
Expand All @@ -26,6 +41,8 @@ module "gke" {
horizontal_pod_autoscaling = true
kubernetes_dashboard = true
network_policy = true
remove_default_node_pool = true
initial_node_count = 1

node_pools = [
{
Expand Down Expand Up @@ -53,19 +70,13 @@ module "gke" {
}

node_pools_labels = {
all = {}

default-node-pool = {
default-node-pool = "true"
}
all = {}
default-node-pool = {}
}

node_pools_metadata = {
all = {}

default-node-pool = {
node-pool-metadata-custom-value = "my-node-pool"
}
all = {}
default-node-pool = {}
}

node_pools_taints = {
Expand All @@ -81,11 +92,8 @@ module "gke" {
}

node_pools_tags = {
all = []

default-node-pool = [
"default-node-pool",
]
all = []
default-node-pool = []
}
}
```
Expand Down Expand Up @@ -120,6 +128,7 @@ In either case, upgrading to module version `v1.0.0` will trigger a recreation o
| disable\_legacy\_metadata\_endpoints | Disable the /0.1/ and /v1beta1/ metadata server endpoints on the node. Changing this value will cause all node pools to be recreated. | string | `"true"` | no |
| horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | string | `"true"` | no |
| http\_load\_balancing | Enable httpload balancer addon | string | `"true"` | no |
| initial\_node\_count | The initial size of the default cluster. Clusters having `remove_default_node_pool` set to `true` and any new clusters must specify this variable >= 1. | string | `"0"` | no |
| ip\_masq\_link\_local | Whether to masquerade traffic to the link-local prefix (169.254.0.0/16). | string | `"false"` | no |
| ip\_masq\_resync\_interval | The interval at which the agent attempts to sync its ConfigMap file from the disk. | string | `"60s"` | no |
| ip\_range\_pods | The _name_ of the secondary subnet ip range to use for pods | string | n/a | yes |
Expand Down Expand Up @@ -190,15 +199,21 @@ Before this module can be used on a project, you must ensure that the following
The [project factory](https://github.com/terraform-google-modules/terraform-google-project-factory) can be used to provision projects with the correct APIs active and the necessary Shared VPC connections.

### Software Dependencies

#### Kubectl

- [kubectl](https://github.com/kubernetes/kubernetes/releases) 1.9.x

#### Terraform and Plugins

- [Terraform](https://www.terraform.io/downloads.html) 0.11.x
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) v2.0.0
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) v2.5.0

### Configure a Service Account

In order to execute this module you must have a Service Account with the
following project roles:

- roles/compute.viewer
- roles/container.clusterAdmin
- roles/container.developer
Expand All @@ -207,12 +222,14 @@ following project roles:
- roles/resourcemanager.projectIamAdmin (only required if `service_account` is set to `create`)

### Enable APIs

In order to operate with the Service Account you must activate the following APIs on the project where the Service Account was created:

- Compute Engine API - compute.googleapis.com
- Kubernetes Engine API - container.googleapis.com

## File structure

The project has the following folders and files:

- /: root folder
Expand All @@ -233,17 +250,12 @@ The root module is generated by running `make generate`. Changes to this reposit

## Testing

### Requirements
### Dependent software

- [bundler](https://github.com/bundler/bundler)
- [gcloud](https://cloud.google.com/sdk/install)
- [terraform-docs](https://github.com/segmentio/terraform-docs/releases) 0.6.0

### Autogeneration of documentation from .tf files
Run
```
make generate_docs
```

### Integration test

Integration tests are run though [test-kitchen](https://github.com/test-kitchen/test-kitchen), [kitchen-terraform](https://github.com/newcontext-oss/kitchen-terraform), and [InSpec](https://github.com/inspec/inspec).
Expand All @@ -268,12 +280,13 @@ The test-kitchen instances in `test/fixtures/` wrap identically-named examples i
- Requires `roles/resourcemanager.projectIamAdmin` since service account creation is tested
3. Build the Docker container for testing:

```
make docker_build_kitchen_terraform
```
```bash
make docker_build_kitchen_terraform
```

4. Run the testing container in interactive mode:

```
```bash
make docker_run
```

Expand All @@ -292,7 +305,7 @@ If you wish to parallelize running the test suites, it is also possible to offlo

When running tests locally, you will need to use your own test project environment. You can configure your environment by setting all of the following variables:

```
```bash
export COMPUTE_ENGINE_SERVICE_ACCOUNT="<EXISTING_SERVICE_ACCOUNT>"
export PROJECT_ID="<PROJECT_TO_USE>"
export REGION="<REGION_TO_USE>"
Expand All @@ -311,26 +324,29 @@ Similarly, each test fixture has a `variables.tf` to define these variables, and
Each test-kitchen instance creates a GCP Network and Subnetwork fixture to house resources, and may create any other necessary fixture data as needed.

### Autogeneration of documentation from .tf files
Run
```

Run:

```bash
make generate_docs
```

### Linting

The makefile in this project will lint or sometimes just format any shell,
Python, golang, Terraform, or Dockerfiles. The linters will only be run if
the makefile finds files with the appropriate file extension.

All of the linter checks are in the default make target, so you just have to
run

```
```bash
make -s
```

The -s is for 'silent'. Successful output looks like this

```
```bash
Running shellcheck
Running flake8
Running go fmt and go vet
Expand All @@ -347,14 +363,12 @@ Checking file headers
The following lines have trailing whitespace
```

The linters
are as follows:
* Shell - shellcheck. Can be found in homebrew
* Python - flake8. Can be installed with 'pip install flake8'
* Golang - gofmt. gofmt comes with the standard golang installation. golang
is a compiled language so there is no standard linter.
* Terraform - terraform has a built-in linter in the 'terraform validate'
command.
* Dockerfiles - hadolint. Can be found in homebrew
The linters are as follows:

- Shell - shellcheck. Can be found in homebrew
- Python - flake8. Can be installed with 'pip3 install flake8'
- Golang - gofmt. gofmt comes with the standard golang installation.
- Terraform - terraform has a built-in linter in the 'terraform validate' command.
- Dockerfiles - hadolint. Can be found in homebrew

[upgrading-to-v2.0]: docs/upgrading_to_v2.0.md
2 changes: 1 addition & 1 deletion auth.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

// This file was automatically generated from a template in ./autogen
/* This file was automatically generated from a template in ./autogen */

/******************************************
Retrieve authentication token
Expand Down
Loading