Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 67d5537

Browse files
authored
Merge pull request #53 from dippynark/terraform-v0.12-support
Terraform v0.12 support
2 parents d85a81a + 8e1820a commit 67d5537

File tree

7 files changed

+147
-132
lines changed

7 files changed

+147
-132
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ It can be used directly from the Terraform Registry like so:
6666
```
6767
module "gke-cluster" {
6868
source = "jetstack/gke-cluster/google"
69-
version = "0.1.0"
69+
version = "0.2.0-alpha1"
7070
7171
# insert the 9 required variables here
7272
}

example/main.tf

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
# limitations under the License.
1414

1515
terraform {
16-
# This project requires a terraform version >= 0.11 but < 0.12. This is
17-
# because the module is only tested with 0.11 ,and has not yet been upgraded
18-
# to use the new 0.12 syntax.
19-
required_version = "~> 0.11"
16+
required_version = "~> 0.12"
2017

2118
# Use a GCS Bucket as a backend
2219
backend "gcs" {}
@@ -26,19 +23,19 @@ terraform {
2623
# times within a module. They are used here to determine the GCP region from
2724
# the given location, which can be either a region or zone.
2825
locals {
29-
gcp_location_parts = ["${split("-", var.gcp_location)}"]
30-
gcp_region = "${local.gcp_location_parts[0]}-${local.gcp_location_parts[1]}"
26+
gcp_location_parts = split("-", var.gcp_location)
27+
gcp_region = format("%s-%s", local.gcp_location_parts[0], local.gcp_location_parts[1])
3128
}
3229

3330
# https://www.terraform.io/docs/providers/google/index.html
3431
provider "google" {
3532
version = "2.5.1"
36-
project = "${var.gcp_project_id}"
37-
region = "${local.gcp_region}"
33+
project = var.gcp_project_id
34+
region = local.gcp_region
3835
}
3936

4037
resource "google_compute_network" "vpc_network" {
41-
name = "${var.vpc_network_name}"
38+
name = var.vpc_network_name
4239
auto_create_subnetworks = "false"
4340
}
4441

@@ -52,60 +49,58 @@ resource "google_compute_subnetwork" "vpc_subnetwork" {
5249
# a dash, lowercase letter, or digit, except the last character, which
5350
# cannot be a dash.
5451
#name = "default-${var.gcp_cluster_region}"
55-
name = "${var.vpc_subnetwork_name}"
52+
name = var.vpc_subnetwork_name
5653

57-
ip_cidr_range = "${var.vpc_subnetwork_cidr_range}"
54+
ip_cidr_range = var.vpc_subnetwork_cidr_range
5855

5956
# The network this subnet belongs to. Only networks that are in the
6057
# distributed mode can have subnetworks.
61-
network = "${var.vpc_network_name}"
58+
network = var.vpc_network_name
6259

63-
# An array of configurations for secondary IP ranges for VM instances
64-
# contained in this subnetwork. The primary IP of such VM must belong to the
65-
# primary ipCidrRange of the subnetwork. The alias IPs may belong to either
66-
# primary or secondary ranges.
67-
secondary_ip_range = [
68-
{
69-
range_name = "${var.cluster_secondary_range_name}"
70-
ip_cidr_range = "${var.cluster_secondary_range_cidr}"
71-
},
72-
{
73-
range_name = "${var.services_secondary_range_name}"
74-
ip_cidr_range = "${var.services_secondary_range_cidr}"
75-
},
76-
]
60+
# Configurations for secondary IP ranges for VM instances contained in this
61+
# subnetwork. The primary IP of such VM must belong to the primary ipCidrRange
62+
# of the subnetwork. The alias IPs may belong to either primary or secondary
63+
# ranges.
64+
secondary_ip_range {
65+
range_name = var.cluster_secondary_range_name
66+
ip_cidr_range = var.cluster_secondary_range_cidr
67+
}
68+
secondary_ip_range {
69+
range_name = var.services_secondary_range_name
70+
ip_cidr_range = var.services_secondary_range_cidr
71+
}
7772

7873
# When enabled, VMs in this subnetwork without external IP addresses can
7974
# access Google APIs and services by using Private Google Access. This is
8075
# set explicitly to prevent Google's default from fighting with Terraform.
8176
private_ip_google_access = true
8277

8378
depends_on = [
84-
"google_compute_network.vpc_network",
79+
google_compute_network.vpc_network,
8580
]
8681
}
8782

8883
module "cluster" {
8984
source = "jetstack/gke-cluster/google"
90-
version = "0.1.0"
85+
version = "0.2.0-alpha1"
9186

9287
# These values are set from the terrafrom.tfvas file
93-
gcp_project_id = "${var.gcp_project_id}"
94-
cluster_name = "${var.cluster_name}"
95-
gcp_location = "${var.gcp_location}"
96-
daily_maintenance_window_start_time = "${var.daily_maintenance_window_start_time}"
97-
node_pools = "${var.node_pools}"
98-
cluster_secondary_range_name = "${var.cluster_secondary_range_name}"
99-
services_secondary_range_name = "${var.services_secondary_range_name}"
100-
master_ipv4_cidr_block = "${var.master_ipv4_cidr_block}"
101-
access_private_images = "${var.access_private_images}"
102-
http_load_balancing_disabled = "${var.http_load_balancing_disabled}"
103-
master_authorized_networks_cidr_blocks = "${var.master_authorized_networks_cidr_blocks}"
88+
gcp_project_id = var.gcp_project_id
89+
cluster_name = var.cluster_name
90+
gcp_location = var.gcp_location
91+
daily_maintenance_window_start_time = var.daily_maintenance_window_start_time
92+
node_pools = var.node_pools
93+
cluster_secondary_range_name = var.cluster_secondary_range_name
94+
services_secondary_range_name = var.services_secondary_range_name
95+
master_ipv4_cidr_block = var.master_ipv4_cidr_block
96+
access_private_images = var.access_private_images
97+
http_load_balancing_disabled = var.http_load_balancing_disabled
98+
master_authorized_networks_cidr_blocks = var.master_authorized_networks_cidr_blocks
10499

105100
# Refer to the vpc-network and vpc-subnetwork by the name value on the
106101
# resource, rather than the variable used to assign the name, so that
107102
# Terraform knows they must be created before creating the cluster
108-
vpc_network_name = "${google_compute_network.vpc_network.name}"
109103

110-
vpc_subnetwork_name = "${google_compute_subnetwork.vpc_subnetwork.name}"
104+
vpc_network_name = google_compute_network.vpc_network.name
105+
vpc_subnetwork_name = google_compute_subnetwork.vpc_subnetwork.name
111106
}

example/variables.tf

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@
1313
# limitations under the License.
1414

1515
variable "gcp_project_id" {
16-
type = "string"
16+
type = string
1717

1818
description = <<EOF
1919
The ID of the project in which the resources belong.
2020
EOF
2121
}
2222

2323
variable "cluster_name" {
24-
type = "string"
24+
type = string
2525

2626
description = <<EOF
2727
The name of the cluster, unique within the project and zone.
2828
EOF
2929
}
3030

3131
variable "gcp_location" {
32-
type = "string"
32+
type = string
3333

3434
description = <<EOF
3535
The location (region or zone) in which the cluster master will be created,
@@ -46,7 +46,7 @@ EOF
4646
}
4747

4848
variable "daily_maintenance_window_start_time" {
49-
type = "string"
49+
type = string
5050

5151
description = <<EOF
5252
The start time of the 4 hour window for daily maintenance operations RFC3339
@@ -55,7 +55,7 @@ EOF
5555
}
5656

5757
variable "node_pools" {
58-
type = "list"
58+
type = list(map(string))
5959

6060
description = <<EOF
6161
The list of node pool configurations, each should include:
@@ -96,7 +96,7 @@ EOF
9696
}
9797

9898
variable "vpc_network_name" {
99-
type = "string"
99+
type = string
100100

101101
description = <<EOF
102102
The name of the Google Compute Engine network to which the cluster is
@@ -105,7 +105,7 @@ EOF
105105
}
106106

107107
variable "vpc_subnetwork_name" {
108-
type = "string"
108+
type = string
109109

110110
description = <<EOF
111111
The name of the Google Compute Engine subnetwork in which the cluster's
@@ -114,11 +114,11 @@ EOF
114114
}
115115

116116
variable "vpc_subnetwork_cidr_range" {
117-
type = "string"
117+
type = string
118118
}
119119

120120
variable "cluster_secondary_range_name" {
121-
type = "string"
121+
type = string
122122

123123
description = <<EOF
124124
The name of the secondary range to be used as for the cluster CIDR block.
@@ -128,11 +128,11 @@ EOF
128128
}
129129

130130
variable "cluster_secondary_range_cidr" {
131-
type = "string"
131+
type = string
132132
}
133133

134134
variable "services_secondary_range_name" {
135-
type = "string"
135+
type = string
136136

137137
description = <<EOF
138138
The name of the secondary range to be used as for the services CIDR block.
@@ -142,11 +142,11 @@ EOF
142142
}
143143

144144
variable "services_secondary_range_cidr" {
145-
type = "string"
145+
type = string
146146
}
147147

148148
variable "master_ipv4_cidr_block" {
149-
type = "string"
149+
type = string
150150
default = "172.16.0.0/28"
151151

152152
description = <<EOF
@@ -158,7 +158,7 @@ EOF
158158
}
159159

160160
variable "access_private_images" {
161-
type = "string"
161+
type = string
162162
default = "false"
163163

164164
description = <<EOF
@@ -168,7 +168,7 @@ EOF
168168
}
169169

170170
variable "http_load_balancing_disabled" {
171-
type = "string"
171+
type = string
172172
default = "false"
173173

174174
description = <<EOF
@@ -179,18 +179,19 @@ EOF
179179
}
180180

181181
variable "master_authorized_networks_cidr_blocks" {
182-
type = "list"
183-
184-
default = [{
185-
# External network that can access Kubernetes master through HTTPS. Must
186-
# be specified in CIDR notation. This block should allow access from any
187-
# address, but is given explicitly to prevernt Google's defaults from
188-
# fighting with Terraform.
189-
cidr_block = "0.0.0.0/0"
190-
191-
# Field for users to identify CIDR blocks.
192-
display_name = "default"
193-
}]
182+
type = list(map(string))
183+
184+
default = [
185+
{
186+
# External network that can access Kubernetes master through HTTPS. Must
187+
# be specified in CIDR notation. This block should allow access from any
188+
# address, but is given explicitly to prevernt Google's defaults from
189+
# fighting with Terraform.
190+
cidr_block = "0.0.0.0/0"
191+
# Field for users to identify CIDR blocks.
192+
display_name = "default"
193+
},
194+
]
194195

195196
description = <<EOF
196197
Defines up to 20 external networks that can access Kubernetes master

hack/verify.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null 2>&1 && pwd )"
2323

2424
# Make temporary directory to use for testing and enter it
2525
VERIFY_DIR="${REPO_ROOT}/verify"
26-
mkdir "$VERIFY_DIR"
26+
mkdir -p "$VERIFY_DIR"
2727
pushd "$VERIFY_DIR"
2828

2929
# Determine OS type and architecture to get the correct Terraform binary.
@@ -49,9 +49,7 @@ fi
4949

5050
# Checks the Terraform version used by the module, download the Terraform binary
5151
# for that version
52-
if grep "required_version.*0.11.*" "${REPO_ROOT}/main.tf"; then
53-
TERRAFORM_VERSION="0.11.14"
54-
elif grep "required_version.*0.12.*" "${REPO_ROOT}/main.tf"; then
52+
if grep "required_version.*0.12.*" "${REPO_ROOT}/main.tf"; then
5553
TERRAFORM_VERSION="0.12.4"
5654
else
5755
echo "Terraform version is not supported or could not be found."
@@ -81,7 +79,7 @@ cp "${REPO_ROOT}/example/terraform.tfvars.example" terraform.tfvars
8179
# Remove the requirement for a GCS backend so we can init and validate locally
8280
perl -i -0pe 's/(\s*)backend "gcs" \{\n?\s*\n?\s*\}/\1# GCS bucket not used for testing/gms' main.tf
8381
# Use the local version of the module, not the Terraform Registry version, and remove the version specification
84-
perl -i -0pe 's/(\s*)source*\s*= "jetstack\/gke-cluster\/google"\n\s*version = "0.1.0-beta2"/\1source = "..\/"/gms' main.tf
82+
perl -i -0pe 's/(\s*)source*\s*= "jetstack\/gke-cluster\/google"\n\s*version = "0.2.0-alpha1"/\1source = "..\/"/gms' main.tf
8583

8684
# Initialise and validate the generated test project
8785
$TERRAFORM init

iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ resource "google_project_iam_member" "monitoring-viewer" {
4444
}
4545

4646
resource "google_project_iam_member" "storage-object-viewer" {
47-
count = "${var.access_private_images == "true" ? 1 : 0}"
47+
count = var.access_private_images == "true" ? 1 : 0
4848
role = "roles/storage.objectViewer"
4949
member = "serviceAccount:${google_service_account.default.email}"
5050
}

0 commit comments

Comments
 (0)