gruntwork-io / terraform-google-sql

Terraform modules for deploying Google Cloud SQL (e.g. MySQL, PostgreSQL) in GCP
https://gruntwork.io
Apache License 2.0
92 stars 103 forks source link

Not able to create failover replica for master db instance. #78

Closed ghost closed 1 year ago

ghost commented 2 years ago

Hi guys,

I really need help in solving this issue. I am trying to create a failOver replica for my project. I am facing the error " Error, failed to create instance postgres-failover: googleapi: Error 400: The incoming request contained invalid data., invalidRequest".

my provider block is `terraform { required_version = ">= 0.12.26"

required_providers { google-beta = { source = "hashicorp/google-beta" version = "~> 3.57.0" } } }` also sharing the master db instance terraform script.

`resource "google_sql_database_instance" "master" {

depends_on = [ resource.google_compute_network.private_network, resource.google_service_networking_connection.private_vpc_connection, ]

provider = google-beta name = var.db_name project = var.project_name region = var.region database_version = var.database_version

deletion_protection = var.deletion_protection

settings { tier = var.machine_type activation_policy = var.activation_policy disk_autoresize = var.disk_autoresize

ip_configuration {
  dynamic "authorized_networks" {
    for_each = var.authorized_networks
    content {
      name  = lookup(authorized_networks.value, "name", null)
      value = authorized_networks.value.value
    }
  }

  ipv4_enabled    = var.enable_public_internet_access
  private_network = "projects/${var.project_name}/global/networks/${var.private_network_name}"
}

dynamic "location_preference" {
  for_each = var.master_zone == null ? [] : [var.master_zone]

  content {
    zone = location_preference.value
  }
}

backup_configuration {
  enabled                        = var.backup_enabled
}

disk_size         = var.disk_size
disk_type         = var.disk_type
availability_type = var.actual_availability_type

dynamic "database_flags" {
  for_each = var.database_flags
  content {
    name  = database_flags.value.name
    value = database_flags.value.value
  }
}

}

timeouts { create = var.resource_timeout delete = var.resource_timeout update = var.resource_timeout } }`

failover replica script :

`resource "google_sql_database_instance" "read_replica" { count = var.num_read_replicas

depends_on = [ resource.google_sql_database_instance.master, ]

provider = google-beta name = "${var.db_name}-failover" project = var.project_name region = var.region database_version = var.database_version

master_instance_name = resource.google_sql_database_instance.master.name

deletion_protection = var.deletion_protection

replica_configuration { failover_target = true }

settings { tier = var.machine_type disk_autoresize = var.disk_autoresize

ip_configuration {
   dynamic "authorized_networks" {
     for_each = var.authorized_networks_1
     content {
       name  = authorized_networks.value.name
       value = authorized_networks.value.value
     }
   }

  ipv4_enabled    = var.enable_public_internet_access
  private_network = "projects/${var.project_name}/global/networks/${var.private_network_name}"
}

dynamic "location_preference" {
  for_each = var.master_zone == null ? [] : [var.master_zone]

  content {
    zone = location_preference.value
  }
}

 backup_configuration {
   enabled                        = var.backup_enabled
 }

disk_size = var.disk_size
disk_type = var.disk_type
availability_type = var.actual_availability_type

dynamic "database_flags" {
  for_each = var.database_flags
  content {
    name  = database_flags.value.name
    value = database_flags.value.value
  }
}

} timeouts { create = var.resource_timeout delete = var.resource_timeout update = var.resource_timeout } }`.

My vars.tf file is : `variable "project_name" { default = "dasari-postsql" }

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

variable "private_network_name" { default = "my-private-vpc" }

variable "private_ip_name" { default = "peering-ip" }

variable "db_name" { default = "postgres" }

variable "database_version" { default = "POSTGRES_14" }

variable "deletion_protection" { default = true type = bool }

variable "machine_type" { description = "The machine type to use, see https://cloud.google.com/sql/pricing for more details" default = "db-f1-micro" }

variable "disk_autoresize" { type = bool default = true }

variable "activation_policy" { default = "ALWAYS" }

variable "authorized_networks" { description = "A list of authorized CIDR-formatted IP address ranges that can connect to this DB. Only applies to public IP instances." type = list(map(string)) default = [ { name = "all-inbound" # optional value = "0.0.0.0/0" } ] }

variable "enable_public_internet_access" { type = bool default = true }

variable "master_zone" { description = "Preferred zone for the master instance (e.g. 'us-central1-a'). 'region'. If null, Google will auto-assign a zone." type = string default = "us-central1-a" }

variable "replica_zone" { description = "Preferred zone for the master instance (e.g. 'us-central1-a'). 'region'. If null, Google will auto-assign a zone." type = string default = "us-east1-a" }

variable "backup_enabled" { type = bool default = true }

variable "disk_size" { default = "20" }

variable "disk_type" { default = "PD_SSD" }

variable "actual_availability_type" { default = "REGIONAL" }

variable "database_flags" { description = "List of Cloud SQL flags that are applied to the database server" type = list(any) default = [ { name = "cloudsql.iam_authentication" value = "on" } ] }

variable "num_read_replicas" { default = "1" }

variable "resource_timeout" { description = "Timeout for creating, updating and deleting database instances. Valid units of time are s, m, h." type = string default = "60m" }`..

Please help me on this. Screenshot (39)

ghost commented 2 years ago

@autero1, any idea on resolving this issue?

Etiene commented 2 years ago

Hello @dasari97,

As seen on the readme of this repo, we have currently suspended maintaince of it. See below for more info:

Sunset notice

We believe there is an opportunity to create a truly outstanding developer experience for deploying to the cloud, however developing this vision requires that we temporarily limit our focus to just one cloud. Gruntwork has hundreds of customers currently using AWS, so we have temporarily suspended our maintenance efforts on this repo. Once we have implemented and validated our vision for the developer experience on the cloud, we look forward to picking this up. In the meantime, you are welcome to use this code in accordance with the open source license, however we will not be responding to GitHub Issues or Pull Requests.

If you wish to be the maintainer for this project, we are open to considering that. Please contact us at support@gruntwork.io.

ghost commented 2 years ago

@Etiene okay. Thanks for the information.

Etiene commented 2 years ago

No worries!

eak12913 commented 1 year ago

Closing due to repo sunset