Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Terraform 0.12 #52 #53

Merged
merged 5 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Changed

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

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

[#61]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/61
[#56]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/56
[#53]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/53
[#43]: https://github.com/terraform-google-modules/terraform-google-sql-db/pull/43
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source "https://rubygems.org/"

gem "kitchen-terraform", "~> 4.0"
gem "kitchen-terraform", "~> 4.9"
gem "test-kitchen"
gem 'kitchen-inspec'
20 changes: 7 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018 Google LLC
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,26 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Please note that this file was generated from [terraform-google-module-template](https://github.com/terraform-google-modules/terraform-google-module-template).
# Please make sure to contribute relevant changes upstream!

# Make will use bash instead of sh
SHELL := /usr/bin/env bash

# Docker build config variables
CREDENTIALS_PATH ?= /cft/workdir/credentials.json


# Docker build config variables
CREDENTIALS_PATH ?= /cft/workdir/credentials.json
DOCKER_ORG := gcr.io/cloud-foundation-cicd
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 1.0.1
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 2.3.0
DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCKER_TAG_BASE_KITCHEN_TERRAFORM}

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

# Run all available linters
check: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace
.PHONY: check
check: check_shell check_python check_golang check_terraform check_base_files test_check_headers check_headers check_trailing_whitespace

# The .PHONY directive tells make that this isn't a real target and so
# the presence of a file named 'check_shell' won't cause this target to stop
Expand Down Expand Up @@ -146,4 +140,4 @@ test_integration_docker:
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
-v $(CURDIR):/cft/workdir \
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
make test_integration
/bin/bash -c "source test/ci_integration.sh && setup_environment && make test_integration"
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ This module consists of the following submodules:

See more details in each module's README.

## Compatibility

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

## Root module

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

### Installation Dependencies

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

### Configure a Service Account

Expand Down Expand Up @@ -123,7 +131,6 @@ Running flake8
Running go fmt and go vet
Running terraform validate
Running terraform fmt
Running hadolint on Dockerfiles
Checking for required files
The following lines have trailing whitespace
Generating markdown docs with terraform-docs
Expand Down
147 changes: 58 additions & 89 deletions examples/mysql-and-postgres/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2017 Google Inc.
/**
* Copyright 2019 Google LLC
*
* 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
* 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,
Expand All @@ -14,54 +14,29 @@
* limitations under the License.
*/

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

variable "network" {
default = "default"
}

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

variable "mysql_version" {
default = "MYSQL_5_6"
}

variable "postgresql_version" {
default = "POSTGRES_9_6"
}

provider "google" {
ingwarr marked this conversation as resolved.
Show resolved Hide resolved
region = "${var.region}"
region = var.region
}

provider "google-beta" {
region = "${var.region}"
region = var.region
ingwarr marked this conversation as resolved.
Show resolved Hide resolved
}

variable "network_name" {
default = "mysql-psql-example"
data "google_client_config" "current" {
}

data "google_client_config" "current" {}

variable "project_id" {}

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

resource "google_compute_subnetwork" "default" {
project = "${var.project_id}"
name = "${var.network_name}"
project = var.project_id
name = var.network_name
ip_cidr_range = "10.127.0.0/20"
network = "${google_compute_network.default.self_link}"
region = "${var.region}"
network = google_compute_network.default.self_link
region = var.region
private_ip_google_access = true
}

Expand All @@ -72,18 +47,22 @@ resource "random_id" "name" {
module "mysql-db" {
source = "../../modules/mysql"
name = "example-mysql-${random_id.name.hex}"
database_version = "${var.mysql_version}"
project_id = "${var.project_id}"
database_version = var.mysql_version
project_id = var.project_id
zone = "c"

ip_configuration = [{
ipv4_enabled = true
ip_configuration = {
ipv4_enabled = true
private_network = null
require_ssl = true
authorized_networks = [
{
name = var.network_name
value = google_compute_subnetwork.default.ip_cidr_range
},
]
}

authorized_networks = [{
name = "${var.network_name}"
value = "${google_compute_subnetwork.default.ip_cidr_range}"
}]
}]

database_flags = [
{
Expand All @@ -96,72 +75,62 @@ module "mysql-db" {
module "postgresql-db" {
source = "../../modules/postgresql"
name = "example-postgresql-${random_id.name.hex}"
database_version = "${var.postgresql_version}"
project_id = "${var.project_id}"
database_version = var.postgresql_version
project_id = var.project_id
zone = "c"

ip_configuration = [{
ipv4_enabled = true

authorized_networks = [{
name = "${var.network_name}"
value = "${google_compute_subnetwork.default.ip_cidr_range}"
}]
}]
ip_configuration = {
ipv4_enabled = true
private_network = null
require_ssl = true
authorized_networks = [
{
name = var.network_name
value = google_compute_subnetwork.default.ip_cidr_range
},
]
}
}

// We define a connection with the VPC of the Cloud SQL instance.
module "private-service-access" {
source = "../../modules/private_service_access"
project_id = "${var.project_id}"
vpc_network = "${google_compute_network.default.name}"
project_id = var.project_id
vpc_network = google_compute_network.default.name
}

module "safer-mysql-db" {
source = "../../modules/safer_mysql"
name = "example-safer-mysql-${random_id.name.hex}"
database_version = "${var.mysql_version}"
project_id = "${var.project_id}"
region = "${var.region}"
database_version = var.mysql_version
project_id = var.project_id
region = var.region
zone = "c"

# By default, all users will be permitted to connect only via the
# Cloud SQL proxy.
additional_users = [{
name = "app"
},
additional_users = [
{
name = "readonly"
project = var.project_id
name = "app"
password = "PaSsWoRd"
host = "localhost"
instance = module.safer-mysql-db.instance_name
},
{
project = var.project_id
name = "readonly"
password = "PaSsWoRd"
host = "localhost"
instance = module.safer-mysql-db.instance_name
},
]

assign_public_ip = true
vpc_network = "${google_compute_network.default.self_link}"
vpc_network = google_compute_network.default.self_link

// Used to enforce ordering in the creation of resources.
peering_completed = "${module.private-service-access.peering_completed}"
}

output "mysql_conn" {
value = "${module.mysql-db.instance_connection_name}"
}

output "mysql_user_pass" {
value = "${module.mysql-db.generated_user_password}"
peering_completed = module.private-service-access.peering_completed
}

output "psql_conn" {
value = "${module.postgresql-db.instance_connection_name}"
}

output "psql_user_pass" {
value = "${module.postgresql-db.generated_user_password}"
}

output "safer_mysql_conn" {
value = "${module.safer-mysql-db.instance_connection_name}"
}

output "safer_mysql_user_pass" {
value = "${module.safer-mysql-db.generated_user_password}"
}
45 changes: 45 additions & 0 deletions examples/mysql-and-postgres/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright 2019 Google LLC
*
* 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 "mysql_conn" {
value = module.mysql-db.instance_connection_name
description = "The connection name of the master instance to be used in connection strings"
}

output "mysql_user_pass" {
value = module.mysql-db.generated_user_password
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."
}

output "psql_conn" {
value = module.postgresql-db.instance_connection_name
description = "The connection name of the master instance to be used in connection strings"
}

output "psql_user_pass" {
value = module.postgresql-db.generated_user_password
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."
}

output "safer_mysql_conn" {
value = module.safer-mysql-db.instance_connection_name
description = "The connection name of the master instance to be used in connection strings"
}

output "safer_mysql_user_pass" {
value = module.safer-mysql-db.generated_user_password
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."
}
Loading