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

Upgrade to Terraform 0.12. Add health_check parameter. #12

Merged
merged 12 commits into from
Nov 4, 2019
Merged
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
47 changes: 47 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# OSX leaves these everywhere on SMB shares
._*

# OSX trash
.DS_Store

# Python
*.pyc

# Emacs save files
*~
\#*\#
.\#*

# Vim-related files
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist

### https://raw.github.com/github/gitignore/90f149de451a5433aebd94d02d11b0e28843a1af/Terraform.gitignore

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Kitchen files
**/inspec.lock
**/.kitchen
**/.kitchen.local.yml
**/Gemfile.lock

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars
test/fixtures/shared/terraform.tfvars

credentials.json
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ Write changes to the files:

```
hclfmt -w *.tf
```
```
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ 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.
limitations under the License.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

Modular Internal Load Balancer for GCE using forwarding rules.

## Upgrading

The current version is 2.X. The following guides are available to assist with upgrades:

- [1.X -> 2.0](./docs/upgrading_to_lb_internal_v2.0.md)

## Usage

```ruby
```hcl
module "gce-ilb" {
source = "GoogleCloudPlatform/lb-internal/google"
region = "${var.region}"
name = "group2-ilb"
ports = ["${module.mig2.service_port}"]
health_port = "${module.mig2.service_port}"
source_tags = ["${module.mig1.target_tags}"]
target_tags = ["${module.mig2.target_tags}","${module.mig3.target_tags}"]
backends = [
{ group = "${module.mig2.instance_group}" },
{ group = "${module.mig3.instance_group}" },
source = "terraform-google-modules/lb-internal/google"
version = "~> 2.0"
region = var.region
name = "group2-ilb"
ports = ["80"]
health_check = var.health_check
source_tags = ["allow-group1"]
target_tags = ["allow-group2", "allow-group3"]
backends = [
{ group = module.mig2.instance_group, description = "" },
{ group = module.mig3.instance_group, description = "" },
]
}
```
Expand Down
24 changes: 24 additions & 0 deletions build/lint.cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2019 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.

steps:
- name: 'gcr.io/cloud-foundation-cicd/cft/developer-tools:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
id: 'lint'
args: ['/usr/local/bin/test_lint.sh']
tags:
- 'ci'
- 'lint'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.4.7'
59 changes: 59 additions & 0 deletions docs/upgrading_to_lb_internal_v2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Upgrading to Load Balancer Internal v2.0 (from v1.X)

The v2.0 release of Load Balancer Internal is a backwards incompatible release. The string `health_port` and boolean `http_health_check` arguments were replaced with the new object type parameter called `health_check`

## Migration Instructions

### Health Port and HTTP Health Check Arguments Changes

Version 1.X of Load Balancer Internal used the required `health_port` string variable defining a port to perform health checks on and an optional `http_health_check` boolean variable to set whether the health checks should be performed via HTTP or TCP

```hcl
module "gce-ilb" {
source = "GoogleCloudPlatform/lb-internal/google"
version = "~> 1.0"
region = "${var.region}"
name = "group2-ilb"
ports = ["80"]
health_port = "80"
http_health_check = "true"
source_tags = ["allow-group1"]
target_tags = ["allow-group2", "allow-group3"]
backends = [
{ group = "${module.mig2.instance_group}", description = "" },
{ group = "${module.mig3.instance_group}", description = "" },
]
}
```

Version 2.X of Load Balancer Internal uses the new parameter named `health_check`:

```hcl
module "gce-ilb" {
source = "terraform-google-modules/lb-internal/google"
version = "~> 2.0"
region = var.region
name = "group2-ilb"
ports = ["80"]
health_check = {
type = "http"
check_interval_sec = 1
healthy_threshold = 4
timeout_sec = 1
unhealthy_threshold = 5
response = "I AM HEALTHY"
proxy_header = "NONE"
port = 80
port_name = "health-check-port"
request_path = "/mypath"
host = "1.2.3.4"
}
source_tags = ["allow-group1"]
target_tags = ["allow-group2", "allow-group3"]
backends = [
{ group = module.mig2.instance_group, description = "" },
{ group = module.mig3.instance_group, description = "" },
]
}
```

2 changes: 1 addition & 1 deletion examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/.terraform
**/terraform.tfstate*
**/terraform.tfstate*
6 changes: 3 additions & 3 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ This example creates 3 instance groups. The first group is in us-central1-b and

## Set up the environment

```
```shell
gcloud auth application-default login
export GOOGLE_PROJECT=$(gcloud config get-value project)
```

## Run Terraform

```
```shell
terraform init
terraform plan
terraform apply
```

Open URL of load balancer in browser:

```
```shell
EXTERNAL_IP=$(terraform output -module gce-lb-fr external_ip)
open http://${EXTERNAL_IP}
```
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/gceme.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ sudo mv /var/www/html/index.html /var/www/html/index.html.old
[[ -n "${PROXY_PATH}" ]] && mkdir -p /var/www/html/${PROXY_PATH} && cp /var/www/html/index.php /var/www/html/${PROXY_PATH}/index.php

systemctl enable apache2
systemctl restart apache2
systemctl restart apache2
35 changes: 35 additions & 0 deletions examples/simple/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2019 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 {
named_ports = [{
name = "http"
port = 80
}]
health_check = {
type = "http"
check_interval_sec = 1
healthy_threshold = 4
timeout_sec = 1
unhealthy_threshold = 5
response = "I AM HEALTHY"
proxy_header = "NONE"
port = 80
port_name = "health-check-port"
request_path = "/mypath"
host = "1.2.3.4"
}
}
53 changes: 22 additions & 31 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2017 Google Inc.
/**
* Copyright 2019 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
* 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,
Expand All @@ -14,47 +14,38 @@
* limitations under the License.
*/

variable region {
default = "us-central1"
}

variable network {
default = "default"
}

variable zone {
default = "us-central1-b"
}

provider google {
region = "${var.region}"
provider "google" {
region = var.region
}

module "gce-lb-fr" {
source = "GoogleCloudPlatform/lb/google"
version = "1.0.2"
region = "${var.region}"
network = "${var.network}"
version = "~> 2.0"
region = var.region
network = var.network
project = var.project
name = "group1-lb"
service_port = "${module.mig1.service_port}"
target_tags = ["${module.mig1.target_tags}"]
service_port = local.named_ports[0].port
target_tags = ["allow-group1"]
}

module "gce-ilb" {
source = "../../"
region = "${var.region}"
name = "group-ilb"
ports = ["${module.mig2.service_port}"]
health_port = "${module.mig2.service_port}"
source_tags = ["${module.mig1.target_tags}"]
target_tags = ["${module.mig2.target_tags}", "${module.mig3.target_tags}"]
source = "../../"
region = var.region
name = "group-ilb"
ports = [local.named_ports[0].port]
source_tags = ["allow-group1"]
target_tags = ["allow-group2", "allow-group3"]
health_check = local.health_check

backends = [
{
group = "${module.mig2.instance_group}"
group = module.mig2.instance_group
description = ""
},
{
group = "${module.mig3.instance_group}"
group = module.mig3.instance_group
description = ""
},
]
}
Loading