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

Commit 3b18b91

Browse files
authored
Merge pull request #38 from gruntwork-io/tf12
Upgrade to Terraform 0.12
2 parents 6aebe49 + cb93ed3 commit 3b18b91

37 files changed

+1016
-446
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defaults: &defaults
44
GRUNTWORK_INSTALLER_VERSION: v0.0.21
55
TERRATEST_LOG_PARSER_VERSION: v0.13.24
66
MODULE_CI_VERSION: v0.13.3
7-
TERRAFORM_VERSION: 0.11.8
7+
TERRAFORM_VERSION: 0.12.2
88
TERRAGRUNT_VERSION: NONE
99
PACKER_VERSION: NONE
1010
GOLANG_VERSION: 1.11.2
@@ -99,4 +99,4 @@ workflows:
9999
- build
100100
- test:
101101
requires:
102-
- build
102+
- build

README.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![Maintained by Gruntwork.io](https://img.shields.io/badge/maintained%20by-gruntwork.io-%235849a6.svg)](https://gruntwork.io/?ref=repo_google_cloudsql)
22
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gruntwork-io/terraform-google-sql.svg?label=latest)](http://github.com/gruntwork-io/terraform-google-sql/releases/latest)
3+
![Terraform Version](https://img.shields.io/badge/tf-%3E%3D0.12.0-blue.svg)
34

45
# Cloud SQL Modules
56

@@ -20,33 +21,33 @@ for instructions.
2021

2122
This repo has the following folder structure:
2223

23-
* [root](https://github.com/gruntwork-io/terraform-google-sql/tree/master): The root folder contains an example of how
24+
- [root](https://github.com/gruntwork-io/terraform-google-sql/tree/master): The root folder contains an example of how
2425
to deploy a private PostgreSQL instance in Cloud SQL. See [postgres-private-ip](https://github.com/gruntwork-io/terraform-google-sql/blob/master/examples/postgres-private-ip)
2526
for the documentation.
2627

27-
* [modules](https://github.com/gruntwork-io/terraform-google-sql/tree/master/modules): This folder contains the
28+
- [modules](https://github.com/gruntwork-io/terraform-google-sql/tree/master/modules): This folder contains the
2829
main implementation code for this Module, broken down into multiple standalone submodules.
2930

3031
The primary module is:
3132

32-
* [cloud-sql](https://github.com/gruntwork-io/terraform-google-sql/tree/master/modules/cloud-sql): Deploy a Cloud SQL [MySQL](https://cloud.google.com/sql/docs/mysql/) or
33+
- [cloud-sql](https://github.com/gruntwork-io/terraform-google-sql/tree/master/modules/cloud-sql): Deploy a Cloud SQL [MySQL](https://cloud.google.com/sql/docs/mysql/) or
3334
[PostgreSQL](https://cloud.google.com/sql/docs/postgres/) database.
3435

35-
* [examples](https://github.com/gruntwork-io/terraform-google-sql/tree/master/examples): This folder contains
36+
- [examples](https://github.com/gruntwork-io/terraform-google-sql/tree/master/examples): This folder contains
3637
examples of how to use the submodules.
3738

38-
* [test](https://github.com/gruntwork-io/terraform-google-sql/tree/master/test): Automated tests for the submodules
39+
- [test](https://github.com/gruntwork-io/terraform-google-sql/tree/master/test): Automated tests for the submodules
3940
and examples.
4041

4142
## What is Cloud SQL?
4243

43-
Cloud SQL is Google's fully-managed database service that makes it easy to set up, maintain, manage, and administer
44-
your relational databases on Google Cloud Platform. Cloud SQL automatically includes:
44+
Cloud SQL is Google's fully-managed database service that makes it easy to set up, maintain, manage, and administer
45+
your relational databases on Google Cloud Platform. Cloud SQL automatically includes:
4546

46-
* Data replication between multiple zones with automatic failover.
47-
* Automated and on-demand backups, and point-in-time recovery.
48-
* Data encryption on networks, database tables, temporary files, and backups.
49-
* Secure external connections with the [Cloud SQL Proxy](https://cloud.google.com/sql/docs/mysql/sql-proxy) or with the SSL/TLS protocol.
47+
- Data replication between multiple zones with automatic failover.
48+
- Automated and on-demand backups, and point-in-time recovery.
49+
- Data encryption on networks, database tables, temporary files, and backups.
50+
- Secure external connections with the [Cloud SQL Proxy](https://cloud.google.com/sql/docs/mysql/sql-proxy) or with the SSL/TLS protocol.
5051

5152
You can learn more about Cloud SQL from [the official documentation](https://cloud.google.com/sql/docs/).
5253

@@ -70,18 +71,16 @@ commercial support, send an email to
7071

7172
Gruntwork can help with:
7273

73-
* Setup, customization, and support for this Module.
74-
* Modules and submodules for other types of infrastructure, such as VPCs, Docker clusters, databases, and continuous
74+
- Setup, customization, and support for this Module.
75+
- Modules and submodules for other types of infrastructure, such as VPCs, Docker clusters, databases, and continuous
7576
integration.
76-
* Modules and Submodules that meet compliance requirements, such as HIPAA.
77-
* Consulting & Training on GCP, AWS, Terraform, and DevOps.
78-
77+
- Modules and Submodules that meet compliance requirements, such as HIPAA.
78+
- Consulting & Training on GCP, AWS, Terraform, and DevOps.
7979

8080
## How do I contribute to this Module?
8181

8282
Contributions are very welcome! Check out the [Contribution Guidelines](https://github.com/gruntwork-io/terraform-google-sql/blob/master/CONTRIBUTING.md) for instructions.
8383

84-
8584
## How is this Module versioned?
8685

8786
This Module follows the principles of [Semantic Versioning](http://semver.org/). You can find each new release, along
@@ -91,7 +90,6 @@ During initial development, the major version will be 0 (e.g., `0.x.y`), which i
9190
stable API. Once we hit `1.0.0`, we will make every effort to maintain a backwards compatible API and use the MAJOR,
9291
MINOR, and PATCH versions on each release to indicate any incompatibilities.
9392

94-
9593
## License
9694

9795
Please see [LICENSE](https://github.com/gruntwork-io/terraform-google-sql/blob/master/LICENSE.txt) for how the code in this repo is licensed.

examples/client-certificate/main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
provider "google-beta" {
1010
version = "~> 2.7.0"
11-
region = "${var.region}"
12-
project = "${var.project}"
11+
project = var.project
12+
region = var.region
1313
}
1414

15-
# Use Terraform 0.10.x so that we can take advantage of Terraform GCP functionality as a separate provider via
16-
# https://github.com/terraform-providers/terraform-provider-google
1715
terraform {
18-
required_version = ">= 0.10.3"
16+
# The modules used in this example have been updated with 0.12 syntax, which means the example is no longer
17+
# compatible with any versions below 0.12.
18+
required_version = ">= 0.12"
1919
}
2020

2121
# ------------------------------------------------------------------------------
@@ -24,6 +24,6 @@ terraform {
2424

2525
resource "google_sql_ssl_cert" "client_cert" {
2626
provider = "google-beta"
27-
common_name = "${var.common_name}"
28-
instance = "${var.database_instance_name}"
27+
common_name = var.common_name
28+
instance = var.database_instance_name
2929
}

examples/client-certificate/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
output "client_ca_cert" {
66
description = "Certificate data for the client certificate."
7-
value = "${google_sql_ssl_cert.client_cert.cert}"
7+
value = google_sql_ssl_cert.client_cert.cert
88
}
99

1010
# In real-world cases, the output for the private key should always be encrypted
1111
output "client_private_key" {
1212
description = "Private key associated with the client certificate."
13-
value = "${google_sql_ssl_cert.client_cert.private_key}"
13+
value = google_sql_ssl_cert.client_cert.private_key
1414
}

examples/client-certificate/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55

66
variable "project" {
77
description = "The project ID to host the database in."
8+
type = string
89
}
910

1011
variable "region" {
1112
description = "The region to host the database in."
13+
type = string
1214
}
1315

1416
# Note, after a name db instance is used, it cannot be reused for up to one week.
1517
variable "common_name" {
1618
description = "The common name to be used in the certificate to identify the client. Constrained to [a-zA-Z.-_ ]+. Changing this forces a new resource to be created."
19+
type = string
1720
}
1821

1922
variable "database_instance_name" {
2023
description = "The name of the Cloud SQL instance. Changing this forces a new resource to be created."
24+
type = string
2125
}

examples/mysql-private-ip/main.tf

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
provider "google-beta" {
1010
version = "~> 2.7.0"
11-
region = "${var.region}"
12-
project = "${var.project}"
11+
project = var.project
12+
region = var.region
1313
}
1414

15-
# Use Terraform 0.10.x so that we can take advantage of Terraform GCP functionality as a separate provider via
16-
# https://github.com/terraform-providers/terraform-provider-google
1715
terraform {
18-
required_version = ">= 0.10.3"
16+
# The modules used in this example have been updated with 0.12 syntax, which means the example is no longer
17+
# compatible with any versions below 0.12.
18+
required_version = ">= 0.12"
1919
}
2020

2121
# ------------------------------------------------------------------------------
@@ -28,7 +28,7 @@ resource "random_id" "name" {
2828

2929
locals {
3030
# If name_override is specified, use that - otherwise use the name_prefix with a random string
31-
instance_name = "${length(var.name_override) == 0 ? format("%s-%s", var.name_prefix, random_id.name.hex) : var.name_override}"
31+
instance_name = var.name_override == null ? format("%s-%s", var.name_prefix, random_id.name.hex) : var.name_override
3232
private_network_name = "private-network-${random_id.name.hex}"
3333
private_ip_name = "private-ip-${random_id.name.hex}"
3434
}
@@ -40,25 +40,25 @@ locals {
4040
# Simple network, auto-creates subnetworks
4141
resource "google_compute_network" "private_network" {
4242
provider = "google-beta"
43-
name = "${local.private_network_name}"
43+
name = local.private_network_name
4444
}
4545

4646
# Reserve global internal address range for the peering
4747
resource "google_compute_global_address" "private_ip_address" {
4848
provider = "google-beta"
49-
name = "${local.private_ip_name}"
49+
name = local.private_ip_name
5050
purpose = "VPC_PEERING"
5151
address_type = "INTERNAL"
5252
prefix_length = 16
53-
network = "${google_compute_network.private_network.self_link}"
53+
network = google_compute_network.private_network.self_link
5454
}
5555

5656
# Establish VPC network peering connection using the reserved address range
5757
resource "google_service_networking_connection" "private_vpc_connection" {
5858
provider = "google-beta"
59-
network = "${google_compute_network.private_network.self_link}"
59+
network = google_compute_network.private_network.self_link
6060
service = "servicenetworking.googleapis.com"
61-
reserved_peering_ranges = ["${google_compute_global_address.private_ip_address.name}"]
61+
reserved_peering_ranges = [google_compute_global_address.private_ip_address.name]
6262
}
6363

6464
# ------------------------------------------------------------------------------
@@ -68,31 +68,31 @@ resource "google_service_networking_connection" "private_vpc_connection" {
6868
module "mysql" {
6969
# When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you
7070
# to a specific version of the modules, such as the following example:
71-
# source = "github.com/gruntwork-io/terraform-google-sql.git//modules/cloud-sql?ref=v0.1.1"
71+
# source = "github.com/gruntwork-io/terraform-google-sql.git//modules/cloud-sql?ref=v0.2.0"
7272
source = "../../modules/cloud-sql"
7373

74-
project = "${var.project}"
75-
region = "${var.region}"
76-
name = "${local.instance_name}"
77-
db_name = "${var.db_name}"
74+
project = var.project
75+
region = var.region
76+
name = local.instance_name
77+
db_name = var.db_name
7878

79-
engine = "${var.mysql_version}"
80-
machine_type = "${var.machine_type}"
79+
engine = var.mysql_version
80+
machine_type = var.machine_type
8181

8282
# These together will construct the master_user privileges, i.e.
8383
# 'master_user_name'@'master_user_host' IDENTIFIED BY 'master_user_password'.
8484
# These should typically be set as the environment variable TF_VAR_master_user_password, etc.
8585
# so you don't check these into source control."
86-
master_user_password = "${var.master_user_password}"
86+
master_user_password = var.master_user_password
8787

88-
master_user_name = "${var.master_user_name}"
88+
master_user_name = var.master_user_name
8989
master_user_host = "%"
9090

9191
# Pass the private network link to the module
92-
private_network = "${google_compute_network.private_network.self_link}"
92+
private_network = google_compute_network.private_network.self_link
9393

9494
# Wait for the vpc connection to complete
95-
dependencies = ["${google_service_networking_connection.private_vpc_connection.network}"]
95+
dependencies = [google_service_networking_connection.private_vpc_connection.network]
9696

9797
# Set auto-increment flags to test the
9898
# feature during automated testing

examples/mysql-private-ip/outputs.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44

55
output "master_instance_name" {
66
description = "The name of the database instance"
7-
value = "${module.mysql.master_instance_name}"
7+
value = module.mysql.master_instance_name
88
}
99

1010
output "master_ip_addresses" {
1111
description = "All IP addresses of the instance as list of maps, see https://www.terraform.io/docs/providers/google/r/sql_database_instance.html#ip_address-0-ip_address"
12-
value = "${module.mysql.master_ip_addresses}"
12+
value = module.mysql.master_ip_addresses
1313
}
1414

1515
output "master_private_ip" {
1616
description = "The private IPv4 address of the master instance."
17-
value = "${module.mysql.master_private_ip_address}"
17+
value = module.mysql.master_private_ip_address
1818
}
1919

2020
output "master_instance" {
2121
description = "Self link to the master instance"
22-
value = "${module.mysql.master_instance}"
22+
value = module.mysql.master_instance
2323
}
2424

2525
output "master_proxy_connection" {
2626
description = "Instance path for connecting with Cloud SQL Proxy. Read more at https://cloud.google.com/sql/docs/mysql/sql-proxy"
27-
value = "${module.mysql.master_proxy_connection}"
27+
value = module.mysql.master_proxy_connection
2828
}
2929

3030
# ------------------------------------------------------------------------------
@@ -33,10 +33,10 @@ output "master_proxy_connection" {
3333

3434
output "db_name" {
3535
description = "Name of the default database"
36-
value = "${module.mysql.db_name}"
36+
value = module.mysql.db_name
3737
}
3838

3939
output "db" {
4040
description = "Self link to the default database"
41-
value = "${module.mysql.db}"
41+
value = module.mysql.db
4242
}

examples/mysql-private-ip/variables.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,55 @@
55

66
variable "project" {
77
description = "The project ID to host the database in."
8+
type = string
89
}
910

1011
variable "region" {
1112
description = "The region to host the database in."
13+
type = string
1214
}
1315

1416
# Note, after a name db instance is used, it cannot be reused for up to one week.
1517
variable "name_prefix" {
1618
description = "The name prefix for the database instance. Will be appended with a random string. Use lowercase letters, numbers, and hyphens. Start with a letter."
19+
type = string
1720
}
1821

1922
variable "master_user_name" {
2023
description = "The username part for the default user credentials, i.e. 'master_user_name'@'master_user_host' IDENTIFIED BY 'master_user_password'. This should typically be set as the environment variable TF_VAR_master_user_name so you don't check it into source control."
24+
type = string
2125
}
2226

2327
variable "master_user_password" {
2428
description = "The password part for the default user credentials, i.e. 'master_user_name'@'master_user_host' IDENTIFIED BY 'master_user_password'. This should typically be set as the environment variable TF_VAR_master_user_password so you don't check it into source control."
29+
type = string
2530
}
2631

2732
# ---------------------------------------------------------------------------------------------------------------------
2833
# OPTIONAL PARAMETERS
2934
# Generally, these values won't need to be changed.
3035
# ---------------------------------------------------------------------------------------------------------------------
36+
3137
variable "mysql_version" {
3238
description = "The engine version of the database, e.g. `MYSQL_5_6` or `MYSQL_5_7`. See https://cloud.google.com/sql/docs/features for supported versions."
39+
type = string
3340
default = "MYSQL_5_7"
3441
}
3542

3643
variable "machine_type" {
3744
description = "The machine type to use, see https://cloud.google.com/sql/pricing for more details"
45+
type = string
3846
default = "db-f1-micro"
3947
}
4048

4149
variable "db_name" {
4250
description = "Name for the db"
51+
type = string
4352
default = "default"
4453
}
4554

4655
variable "name_override" {
4756
description = "You may optionally override the name_prefix + random string by specifying an override"
48-
default = ""
57+
type = string
58+
default = null
4959
}

0 commit comments

Comments
 (0)