Skip to content

Commit 78e451f

Browse files
authored
Merge pull request #53 from ingwarr/master
Add support for Terraform 0.12 #52
2 parents 473212e + 2b581ff commit 78e451f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2527
-859
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1414

1515
### Changed
1616

17+
- Added support for Terraform 0.12 [#53]
1718
- the root module has been deprecated [#56]
1819

1920
### Fixed
@@ -42,4 +43,5 @@ project adheres to [Semantic Versioning](http://semver.org/).
4243

4344
[#61]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/61
4445
[#56]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/56
46+
[#53]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/53
4547
[#43]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/43

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source "https://rubygems.org/"
22

3-
gem "kitchen-terraform", "~> 4.0"
3+
gem "kitchen-terraform", "~> 4.9"
44
gem "test-kitchen"
55
gem 'kitchen-inspec'

Makefile

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 Google LLC
1+
# Copyright 2019 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,26 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# Please note that this file was generated from [terraform-google-module-template](https://github.com/terraform-google-modules/terraform-google-module-template).
16-
# Please make sure to contribute relevant changes upstream!
17-
18-
# Make will use bash instead of sh
1915
SHELL := /usr/bin/env bash
2016

21-
# Docker build config variables
22-
CREDENTIALS_PATH ?= /cft/workdir/credentials.json
23-
24-
25-
# Docker build config variables
17+
CREDENTIALS_PATH ?= /cft/workdir/credentials.json
2618
DOCKER_ORG := gcr.io/cloud-foundation-cicd
27-
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 1.0.1
19+
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 2.3.0
2820
DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCKER_TAG_BASE_KITCHEN_TERRAFORM}
2921

3022
# All is the first target in the file so it will get picked up when you just run 'make' on its own
23+
.PHONY: all
3124
all: check generate_docs
3225

3326
# Run all available linters
34-
check: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace
27+
.PHONY: check
28+
check: check_shell check_python check_golang check_terraform check_base_files test_check_headers check_headers check_trailing_whitespace
3529

3630
# The .PHONY directive tells make that this isn't a real target and so
3731
# the presence of a file named 'check_shell' won't cause this target to stop
@@ -146,4 +140,4 @@ test_integration_docker:
146140
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
147141
-v $(CURDIR):/cft/workdir \
148142
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
149-
make test_integration
143+
/bin/bash -c "source test/ci_integration.sh && setup_environment && make test_integration"

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ This module consists of the following submodules:
88

99
See more details in each module's README.
1010

11+
## Compatibility
12+
13+
This module is meant for use with Terraform 0.12. If you haven't
14+
[upgraded](https://www.terraform.io/upgrade-guides/0-12.html)
15+
and need a Terraform 0.11.x-compatible version of this module, the last
16+
released version intended for Terraform 0.11.x is
17+
[v1.2.0](https://registry.terraform.io/modules/GoogleCloudPlatform/sql-db/google/1.2.0).
18+
1119
## Root module
1220

1321
The root module has been deprecated. Please switch to using one of the submodules.
@@ -16,8 +24,8 @@ The root module has been deprecated. Please switch to using one of the submodule
1624

1725
### Installation Dependencies
1826

19-
- [terraform](https://www.terraform.io/downloads.html) 0.11.x
20-
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) plugin v1.12.x
27+
- [terraform](https://www.terraform.io/downloads.html) 0.12.x
28+
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) plugin v2.5.x
2129

2230
### Configure a Service Account
2331

@@ -123,7 +131,6 @@ Running flake8
123131
Running go fmt and go vet
124132
Running terraform validate
125133
Running terraform fmt
126-
Running hadolint on Dockerfiles
127134
Checking for required files
128135
The following lines have trailing whitespace
129136
Generating markdown docs with terraform-docs
Lines changed: 58 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/*
2-
* Copyright 2017 Google Inc.
1+
/**
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,54 +14,29 @@
1414
* limitations under the License.
1515
*/
1616

17-
variable "region" {
18-
default = "us-central1"
19-
}
20-
21-
variable "network" {
22-
default = "default"
23-
}
24-
25-
variable "zone" {
26-
default = "us-central1-b"
27-
}
28-
29-
variable "mysql_version" {
30-
default = "MYSQL_5_6"
31-
}
32-
33-
variable "postgresql_version" {
34-
default = "POSTGRES_9_6"
35-
}
36-
3717
provider "google" {
38-
region = "${var.region}"
18+
region = var.region
3919
}
4020

4121
provider "google-beta" {
42-
region = "${var.region}"
22+
region = var.region
4323
}
4424

45-
variable "network_name" {
46-
default = "mysql-psql-example"
25+
data "google_client_config" "current" {
4726
}
4827

49-
data "google_client_config" "current" {}
50-
51-
variable "project_id" {}
52-
5328
resource "google_compute_network" "default" {
54-
project = "${var.project_id}"
55-
name = "${var.network_name}"
29+
project = var.project_id
30+
name = var.network_name
5631
auto_create_subnetworks = false
5732
}
5833

5934
resource "google_compute_subnetwork" "default" {
60-
project = "${var.project_id}"
61-
name = "${var.network_name}"
35+
project = var.project_id
36+
name = var.network_name
6237
ip_cidr_range = "10.127.0.0/20"
63-
network = "${google_compute_network.default.self_link}"
64-
region = "${var.region}"
38+
network = google_compute_network.default.self_link
39+
region = var.region
6540
private_ip_google_access = true
6641
}
6742

@@ -72,18 +47,22 @@ resource "random_id" "name" {
7247
module "mysql-db" {
7348
source = "../../modules/mysql"
7449
name = "example-mysql-${random_id.name.hex}"
75-
database_version = "${var.mysql_version}"
76-
project_id = "${var.project_id}"
50+
database_version = var.mysql_version
51+
project_id = var.project_id
7752
zone = "c"
7853

79-
ip_configuration = [{
80-
ipv4_enabled = true
54+
ip_configuration = {
55+
ipv4_enabled = true
56+
private_network = null
57+
require_ssl = true
58+
authorized_networks = [
59+
{
60+
name = var.network_name
61+
value = google_compute_subnetwork.default.ip_cidr_range
62+
},
63+
]
64+
}
8165

82-
authorized_networks = [{
83-
name = "${var.network_name}"
84-
value = "${google_compute_subnetwork.default.ip_cidr_range}"
85-
}]
86-
}]
8766

8867
database_flags = [
8968
{
@@ -96,72 +75,62 @@ module "mysql-db" {
9675
module "postgresql-db" {
9776
source = "../../modules/postgresql"
9877
name = "example-postgresql-${random_id.name.hex}"
99-
database_version = "${var.postgresql_version}"
100-
project_id = "${var.project_id}"
78+
database_version = var.postgresql_version
79+
project_id = var.project_id
10180
zone = "c"
10281

103-
ip_configuration = [{
104-
ipv4_enabled = true
105-
106-
authorized_networks = [{
107-
name = "${var.network_name}"
108-
value = "${google_compute_subnetwork.default.ip_cidr_range}"
109-
}]
110-
}]
82+
ip_configuration = {
83+
ipv4_enabled = true
84+
private_network = null
85+
require_ssl = true
86+
authorized_networks = [
87+
{
88+
name = var.network_name
89+
value = google_compute_subnetwork.default.ip_cidr_range
90+
},
91+
]
92+
}
11193
}
11294

11395
// We define a connection with the VPC of the Cloud SQL instance.
11496
module "private-service-access" {
11597
source = "../../modules/private_service_access"
116-
project_id = "${var.project_id}"
117-
vpc_network = "${google_compute_network.default.name}"
98+
project_id = var.project_id
99+
vpc_network = google_compute_network.default.name
118100
}
119101

120102
module "safer-mysql-db" {
121103
source = "../../modules/safer_mysql"
122104
name = "example-safer-mysql-${random_id.name.hex}"
123-
database_version = "${var.mysql_version}"
124-
project_id = "${var.project_id}"
125-
region = "${var.region}"
105+
database_version = var.mysql_version
106+
project_id = var.project_id
107+
region = var.region
126108
zone = "c"
127109

128110
# By default, all users will be permitted to connect only via the
129111
# Cloud SQL proxy.
130-
additional_users = [{
131-
name = "app"
132-
},
112+
additional_users = [
133113
{
134-
name = "readonly"
114+
project = var.project_id
115+
name = "app"
116+
password = "PaSsWoRd"
117+
host = "localhost"
118+
instance = module.safer-mysql-db.instance_name
119+
},
120+
{
121+
project = var.project_id
122+
name = "readonly"
123+
password = "PaSsWoRd"
124+
host = "localhost"
125+
instance = module.safer-mysql-db.instance_name
135126
},
136127
]
137128

138129
assign_public_ip = true
139-
vpc_network = "${google_compute_network.default.self_link}"
130+
vpc_network = google_compute_network.default.self_link
140131

141132
// Used to enforce ordering in the creation of resources.
142-
peering_completed = "${module.private-service-access.peering_completed}"
143-
}
144-
145-
output "mysql_conn" {
146-
value = "${module.mysql-db.instance_connection_name}"
147-
}
148-
149-
output "mysql_user_pass" {
150-
value = "${module.mysql-db.generated_user_password}"
133+
peering_completed = module.private-service-access.peering_completed
151134
}
152135

153-
output "psql_conn" {
154-
value = "${module.postgresql-db.instance_connection_name}"
155-
}
156-
157-
output "psql_user_pass" {
158-
value = "${module.postgresql-db.generated_user_password}"
159-
}
160136

161-
output "safer_mysql_conn" {
162-
value = "${module.safer-mysql-db.instance_connection_name}"
163-
}
164-
165-
output "safer_mysql_user_pass" {
166-
value = "${module.safer-mysql-db.generated_user_password}"
167-
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "mysql_conn" {
18+
value = module.mysql-db.instance_connection_name
19+
description = "The connection name of the master instance to be used in connection strings"
20+
}
21+
22+
output "mysql_user_pass" {
23+
value = module.mysql-db.generated_user_password
24+
description = "The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable."
25+
}
26+
27+
output "psql_conn" {
28+
value = module.postgresql-db.instance_connection_name
29+
description = "The connection name of the master instance to be used in connection strings"
30+
}
31+
32+
output "psql_user_pass" {
33+
value = module.postgresql-db.generated_user_password
34+
description = "The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable."
35+
}
36+
37+
output "safer_mysql_conn" {
38+
value = module.safer-mysql-db.instance_connection_name
39+
description = "The connection name of the master instance to be used in connection strings"
40+
}
41+
42+
output "safer_mysql_user_pass" {
43+
value = module.safer-mysql-db.generated_user_password
44+
description = "The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable."
45+
}

0 commit comments

Comments
 (0)