Skip to content

Commit

Permalink
Updated: examples with random_instance_name
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantin-recurly committed May 28, 2020
1 parent 7c8c799 commit 9cfcd58
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 92 deletions.
24 changes: 6 additions & 18 deletions examples/mssql-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,11 @@ provider "google-beta" {
region = var.region
}

resource "random_id" "instance_name_suffix" {
byte_length = 5
}

locals {
/*
Random instance name needed because:
"You cannot reuse an instance name for up to a week after you have deleted an instance."
See https://cloud.google.com/sql/docs/mysql/delete-instance for details.
*/
instance_name = "${var.name}-${random_id.instance_name_suffix.hex}"
}

module "mssql" {
source = "../../modules/mssql"
name = local.instance_name
project_id = var.project_id
user_name = "simpleuser"
user_password = "foobar"
source = "../../modules/mssql"
name = var.name
random_instance_name = true
project_id = var.project_id
user_name = "simpleuser"
user_password = "foobar"
}
24 changes: 6 additions & 18 deletions examples/mysql-ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,13 @@ provider "random" {
version = "~> 2.2"
}

resource "random_id" "instance_name_suffix" {
byte_length = 5
}

locals {
/*
Random instance name needed because:
"You cannot reuse an instance name for up to a week after you have deleted an instance."
See https://cloud.google.com/sql/docs/mysql/delete-instance for details.
*/
instance_name = "${var.mysql_ha_name}-${random_id.instance_name_suffix.hex}"
}

module "mysql" {
source = "../../modules/mysql"
name = local.instance_name
project_id = var.project_id
database_version = "MYSQL_5_7"
region = "us-central1"
source = "../../modules/mysql"
name = var.mysql_ha_name
random_instance_name = true
project_id = var.project_id
database_version = "MYSQL_5_7"
region = "us-central1"

// Master configurations
tier = "db-n1-standard-1"
Expand Down
10 changes: 5 additions & 5 deletions examples/mysql-private/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ locals {
"You cannot reuse an instance name for up to a week after you have deleted an instance."
See https://cloud.google.com/sql/docs/mysql/delete-instance for details.
*/
instance_name = "${var.db_name}-${random_id.suffix.hex}"
network_name = "${var.network_name}-safer-${random_id.suffix.hex}"
network_name = "${var.network_name}-safer-${random_id.suffix.hex}"
}

module "network-safer-mysql-simple" {
Expand All @@ -61,9 +60,10 @@ module "private-service-access" {
}

module "safer-mysql-db" {
source = "../../modules/safer_mysql"
name = local.instance_name
project_id = var.project_id
source = "../../modules/safer_mysql"
name = var.db_name
random_instance_name = true
project_id = var.project_id

database_version = "MYSQL_5_6"
region = "us-central1"
Expand Down
15 changes: 8 additions & 7 deletions examples/mysql-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ locals {
}

module "mysql-db" {
source = "../../modules/mysql"
name = local.instance_name
database_version = "MYSQL_5_6"
project_id = var.project_id
zone = "c"
region = "us-central1"
tier = "db-n1-standard-1"
source = "../../modules/mysql"
name = var.db_name
random_instance_name = true
database_version = "MYSQL_5_6"
project_id = var.project_id
zone = "c"
region = "us-central1"
tier = "db-n1-standard-1"

ip_configuration = {
ipv4_enabled = true
Expand Down
23 changes: 6 additions & 17 deletions examples/postgresql-ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,14 @@ provider "random" {
version = "~> 2.2"
}

resource "random_id" "instance_name_suffix" {
byte_length = 5
}

locals {
/*
Random instance name needed because:
"You cannot reuse an instance name for up to a week after you have deleted an instance."
See https://cloud.google.com/sql/docs/mysql/delete-instance for details.
*/
instance_name = "${var.pg_ha_name}-${random_id.instance_name_suffix.hex}"
}

module "pg" {
source = "../../modules/postgresql"
name = local.instance_name
project_id = var.project_id
database_version = "POSTGRES_9_6"
region = "us-central1"
source = "../../modules/postgresql"
name = var.pg_ha_name
random_instance_name = true
project_id = var.project_id
database_version = "POSTGRES_9_6"
region = "us-central1"

// Master configurations
tier = "db-custom-2-13312"
Expand Down
29 changes: 8 additions & 21 deletions examples/postgresql-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,15 @@ provider "random" {
version = "~> 2.2"
}

resource "random_id" "name" {
byte_length = 2
}


locals {
/*
Random instance name needed because:
"You cannot reuse an instance name for up to a week after you have deleted an instance."
See https://cloud.google.com/sql/docs/mysql/delete-instance for details.
*/
instance_name = "${var.db_name}-${random_id.name.hex}"
}

module "postgresql-db" {
source = "../../modules/postgresql"
name = local.instance_name
database_version = "POSTGRES_9_6"
project_id = var.project_id
zone = "c"
region = "us-central1"
tier = "db-f1-micro"
source = "../../modules/postgresql"
name = var.db_name
random_instance_name = true
database_version = "POSTGRES_9_6"
project_id = var.project_id
zone = "c"
region = "us-central1"
tier = "db-f1-micro"

ip_configuration = {
ipv4_enabled = true
Expand Down
8 changes: 2 additions & 6 deletions modules/safer_mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
resource "random_id" "suffix" {
count = var.random_instance_name ? 1 : 0

byte_length = 4
}

module "safer_mysql" {
source = "../mysql"
project_id = var.project_id
name = var.random_instance_name ? "${var.name}-${random_id.suffix[0].hex}" : var.name
name = var.name
random_instance_name = true
database_version = var.database_version
region = var.region
zone = var.zone
Expand Down

0 comments on commit 9cfcd58

Please sign in to comment.