Skip to content

Commit

Permalink
Upgrade to Terraform 0.12. Fix terraform-google-modules#10. Add healt…
Browse files Browse the repository at this point in the history
…h_check parameter. Fix terraform-google-modules#3. Remove http_health_check, health_port inputs. Modify example. Fix terraform-google-modules#9.
  • Loading branch information
omazin committed Oct 23, 2019
1 parent 7fbcf27 commit 3a8b439
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 160 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ Modular Internal Load Balancer for GCE using forwarding rules.

## 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 = "GoogleCloudPlatform/lb-internal/google"
region = var.region
name = "group2-ilb"
ports = [var.service_port]
health_check = var.health_check
source_tags = var.source_tags
target_tags = var.target_tags
backends = [
{ group = module.mig2.instance_group },
{ group = module.mig3.instance_group },
]
}
```
Expand Down
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
Binary file modified examples/simple/diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 18 additions & 29 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Google Inc.
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,47 +14,36 @@
* 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 = var.service_port
target_tags = var.target_tags
}

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 = [var.service_port]
source_tags = var.source_tags
target_tags = var.target_tags
health_check = var.health_check

backends = [
{
group = "${module.mig2.instance_group}"
group = module.mig2.instance_group
},
{
group = "${module.mig3.instance_group}"
group = module.mig3.instance_group
},
]
}
86 changes: 34 additions & 52 deletions examples/simple/mig.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Google Inc.
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,66 +14,48 @@
* limitations under the License.
*/

data "template_file" "group1-startup-script" {
template = "${file("${format("%s/nginx_upstream.sh.tpl", path.module)}")}"

vars {
UPSTREAM = "${module.gce-ilb.ip_address}"
}
module "instance_template1" {
source = "terraform-google-modules/vm/google//modules/instance_template"
project_id = var.project
subnetwork = var.subnetwork
subnetwork_project = var.subnetwork_project
service_account = var.service_account
startup_script = templatefile("${path.module}/nginx_upstream.sh.tpl", { UPSTREAM = module.gce-ilb.ip_address })
}

data "template_file" "group2-startup-script" {
template = "${file("${format("%s/gceme.sh.tpl", path.module)}")}"

vars {
PROXY_PATH = ""
}
}

data "template_file" "group3-startup-script" {
template = "${file("${format("%s/gceme.sh.tpl", path.module)}")}"

vars {
PROXY_PATH = ""
}
module "instance_template2" {
source = "terraform-google-modules/vm/google//modules/instance_template"
project_id = var.project
subnetwork = var.subnetwork
subnetwork_project = var.subnetwork_project
service_account = var.service_account
startup_script = templatefile("${path.module}/gceme.sh.tpl", { PROXY_PATH = "" })
}

module "mig1" {
source = "GoogleCloudPlatform/managed-instance-group/google"
version = "1.1.13"
region = "${var.region}"
zone = "${var.zone}"
name = "group1"
size = 2
target_tags = ["allow-group1"]
target_pools = ["${module.gce-lb-fr.target_pool}"]
service_port = 80
service_port_name = "http"
startup_script = "${data.template_file.group1-startup-script.rendered}"
source = "terraform-google-modules/vm/google//modules/mig"
project_id = var.project
subnetwork_project = var.subnetwork_project
region = var.region
target_pools = [module.gce-lb-fr.target_pool]
instance_template = module.instance_template1.self_link
hostname = "mig1"
}

module "mig2" {
source = "GoogleCloudPlatform/managed-instance-group/google"
version = "1.1.13"
region = "${var.region}"
zone = "us-central1-c"
name = "group2"
size = 2
target_tags = ["allow-group2"]
service_port = 80
service_port_name = "http"
startup_script = "${data.template_file.group2-startup-script.rendered}"
source = "terraform-google-modules/vm/google//modules/mig"
project_id = var.project
subnetwork_project = var.subnetwork_project
region = var.region
hostname = "mig2"
instance_template = module.instance_template2.self_link
}

module "mig3" {
source = "GoogleCloudPlatform/managed-instance-group/google"
version = "1.1.13"
region = "${var.region}"
zone = "us-central1-f"
name = "group3"
size = 2
target_tags = ["allow-group3"]
service_port = 80
service_port_name = "http"
startup_script = "${data.template_file.group3-startup-script.rendered}"
source = "terraform-google-modules/vm/google//modules/mig"
project_id = var.project
subnetwork_project = var.subnetwork_project
region = var.region
hostname = "mig3"
instance_template = module.instance_template2.self_link
}
76 changes: 76 additions & 0 deletions examples/simple/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2019 Google Inc.
*
* 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 "region" {
type = "string"
}

variable "network" {
type = "string"
}

variable "zone" {
type = "string"
}

variable "service_port" {
type = "string"
}

variable "target_tags" {
type = list(string)
default = []
}

variable "source_tags" {
type = list(string)
default = []
}

variable "subnetwork" {
type = "string"
}

variable "service_account" {
type = object({
email = string
scopes = set(string)
})
}

variable "subnetwork_project" {
type = "string"
}

variable "project" {
type = "string"
}

variable "health_check" {
type = object({
type = string
check_interval_sec = number
healthy_threshold = number
timeout_sec = number
unhealthy_threshold = number
response = string
proxy_header = string
health_port = number
port_name = string
request_path = string
host = string
})
}
3 changes: 3 additions & 0 deletions examples/simple/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = ">= 0.12"
}
Loading

0 comments on commit 3a8b439

Please sign in to comment.