Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
- Removed trailing whitespaces
- Migrated to 0.12 TF syntax in README
- Corrected shell variables
- Moved ouptus and variables into separated files as discussed terraform-google-modules#52 (comment)
- Simplified firewall rules logic as discussed terraform-google-modules#52 (comment)
- Adjusted provider configuration as discussed terraform-google-modules#52 (comment)
- Replaced not migrated module call with local_exec in null_resource as discussed terraform-google-modules#52 (comment)
- Re-formatted main module output as discussed terraform-google-modules#52 (comment)
- Re-named https-gke example input variable as discussed terraform-google-modules#52 (comment)
  • Loading branch information
ivankorn committed Sep 20, 2019
1 parent 85f8204 commit 01cd4b7
Show file tree
Hide file tree
Showing 28 changed files with 401 additions and 282 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Modular Global HTTP Load Balancer for GCE using forwarding rules.

## Usage

```ruby
```HCL
module "gce-lb-http" {
source = "GoogleCloudPlatform/lb-http/google"
name = "group-http-lb"
target_tags = ["${module.mig1.target_tags}", "${module.mig2.target_tags}"]
target_tags = [module.mig1.target_tags, module.mig2.target_tags]
backends = {
"0" = [
{ group = "${module.mig1.instance_group}" },
{ group = "${module.mig2.instance_group}" }
{ group = module.mig1.instance_group },
{ group = module.mig2.instance_group }
],
}
backend_params = [
Expand Down
15 changes: 7 additions & 8 deletions examples/https-gke/gke-node-port/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ resource "google_compute_subnetwork" "default" {
}

data "google_container_engine_versions" "default" {
location = var.zone
location = var.location
}

resource "google_container_cluster" "default" {
name = var.network_name
location = var.zone
location = var.location
initial_node_count = 3
min_master_version = data.google_container_engine_versions.default.latest_master_version
network = google_compute_subnetwork.default.name
Expand All @@ -62,12 +62,11 @@ provider "kubernetes" {
cluster_ca_certificate = base64decode(google_container_cluster.default.master_auth.0.cluster_ca_certificate)
}

module "named-port" {
# this module is not migrated to HCL2 / TF 0.12 syntax
source = "github.com/danisla/terraform-google-named-ports"
instance_group = google_container_cluster.default.instance_group_urls[0]
name = var.port_name
port = var.node_port
resource "null_resource" "default" {

provisioner "local-exec" {
command = "gcloud compute instance-groups set-named-ports ${google_container_cluster.default.instance_group_urls[0]} --named-ports=${var.port_name}:${var.node_port} --format=json"
}
}

resource "kubernetes_service" "nginx" {
Expand Down
2 changes: 1 addition & 1 deletion examples/https-gke/gke-node-port/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -x
set -x
set -e

EXP_NAME=$(terraform output port_name)
Expand Down
3 changes: 1 addition & 2 deletions examples/https-gke/gke-node-port/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ variable "region" {
default = "us-central1"
}

variable "zone" {
# this variable is deprecated in resources, new name for it is `location`
variable "location" {
default = "us-central1-f"
}

Expand Down
56 changes: 2 additions & 54 deletions examples/https-gke/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,16 @@
* limitations under the License.
*/

variable "name" {
default = "tf-lb-https-gke"
}

variable "service_port" {
default = "30000"
}

variable "service_port_name" {
default = "http"
}

variable "target_tags" {
default = "tf-lb-https-gke"
}

variable "backend" {}

data "google_client_config" "current" {}

variable "region" {
default = "us-central1"
}

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

variable "network_name" {
default = "default"
}

variable "service_account" {
type = object({
email = string,
scopes = list(string)
})
default = {
email = ""
scopes = [
"cloud-platform"]
}
}

variable "project" {
type = string
}

provider "google" {
project = var.project
version = "~> 2.7.0"
}

provider "google-beta" {
project = var.project
version = "~> 2.7.0"
}

data "google_client_config" "current" {}

module "gce-lb-https" {
project = var.project
source = "../../"
Expand Down Expand Up @@ -169,7 +121,3 @@ resource "google_storage_object_acl" "image-acl" {
object = google_storage_bucket_object.image.name
predefined_acl = "publicRead"
}

output "load-balancer-ip" {
value = module.gce-lb-https.external_ip
}
19 changes: 19 additions & 0 deletions examples/https-gke/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/

output "load-balancer-ip" {
value = module.gce-lb-https.external_ip
}
6 changes: 3 additions & 3 deletions examples/https-gke/test.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env bash

set -x
set -x
set -e

URL="https://$(terraform output load-balancer-ip)"
status=0
count=0
while [[ $count -lt 720 && $status -ne 200 ]]; do
while [[ ${count} -lt 720 && ${status} -ne 200 ]]; do
echo "INFO: Waiting for load balancer..."
status=$(curl -sfk -m 5 -o /dev/null -w "%{http_code}" "${URL}" || true)
((count=count+1))
sleep 5
done
if [[ $count -lt 720 ]]; then
if [[ ${count} -lt 720 ]]; then
echo "INFO: PASS. Load balancer is ready."
else
echo "ERROR: Failed. Load balancer never became ready."
Expand Down
62 changes: 62 additions & 0 deletions examples/https-gke/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 "name" {
default = "tf-lb-https-gke"
}

variable "service_port" {
default = "30000"
}

variable "service_port_name" {
default = "http"
}

variable "target_tags" {
default = "tf-lb-https-gke"
}

variable "backend" {}

variable "region" {
default = "us-central1"
}

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

variable "network_name" {
default = "default"
}

variable "service_account" {
type = object({
email = string,
scopes = list(string)
})
default = {
email = ""
scopes = [
"cloud-platform"]
}
}

variable "project" {
type = string
}
36 changes: 1 addition & 35 deletions examples/mig-nat-http-lb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,17 @@
* limitations under the License.
*/

variable "region" {
default = "us-west1"
}

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

variable "network_name" {
default = "tf-lb-http-mig-nat"
}

variable "service_account" {
type = object({
email = string,
scopes = list(string)
})
default = {
email = ""
scopes = [
"cloud-platform"]
}
}

variable "project" {
type = string
}

provider "google" {
project = var.project
version = "~> 2.7.0"
}

provider "google-beta" {
project = var.project
version = "~> 2.7.0"
}

resource "google_compute_network" "default" {
name = var.network_name
auto_create_subnetworks = "false"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "default" {
Expand Down Expand Up @@ -139,7 +109,3 @@ module "gce-lb-http" {
"/,http,80,10",
]
}

output "load-balancer-ip" {
value = module.gce-lb-http.external_ip
}
23 changes: 23 additions & 0 deletions examples/mig-nat-http-lb/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/

output "load-balancer-ip" {
value = module.gce-lb-http.external_ip
}

output "backend_services" {
value = module.gce-lb-http.backend_services
}
6 changes: 3 additions & 3 deletions examples/mig-nat-http-lb/test.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env bash

set -x
set -x
set -e

URL="http://$(terraform output load-balancer-ip)"
status=0
count=0
while [[ $count -lt 720 && $status -ne 200 ]]; do
while [[ ${count} -lt 720 && ${status} -ne 200 ]]; do
echo "INFO: Waiting for load balancer..."
status=$(curl -sf -m 5 -o /dev/null -w "%{http_code}" "${URL}" || true)
((count=count+1))
sleep 5
done
if [[ $count -lt 720 ]]; then
if [[ ${count} -lt 720 ]]; then
echo "INFO: PASS"
else
echo "ERROR: Failed"
Expand Down
43 changes: 43 additions & 0 deletions examples/mig-nat-http-lb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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" {
default = "us-west1"
}

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

variable "network_name" {
default = "tf-lb-http-mig-nat"
}

variable "service_account" {
type = object({
email = string,
scopes = list(string)
})
default = {
email = ""
scopes = [
"cloud-platform"]
}
}

variable "project" {
type = string
}
Loading

0 comments on commit 01cd4b7

Please sign in to comment.