hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.36k stars 1.75k forks source link

SQL Server support for google_database_migration_service_connection_profile is missing #19721

Open mariusmitrofan opened 1 month ago

mariusmitrofan commented 1 month ago

Community Note

Description

The resource google_database_migration_service_connection_profile is missing support for the SQL Server connection.

The API is already live - https://cloud.google.com/database-migration/docs/reference/rest/v1/projects.locations.connectionProfiles#sqlserverconnectionprofile

New or Affected Resource(s)

Potential Terraform Configuration

resource "google_database_migration_service_connection_profile" "destination" {
  location                      = var.gcp_region
  connection_profile_id = "${var.gcp_sql_identifier}-destination"
  display_name              = "${var.gcp_sql_identifier}-destination"

  sqlserver {
    host         = data.google_sql_database_instance.destination.ip_address.0.ip_address
    port         = 1433
    username     = google_sql_user.destination.name
    password     = google_sql_user.destination.password
    cloud_sql_id = data.google_sql_database_instance.destination.name
    ssl {
      client_key         = google_sql_ssl_cert.destination.private_key
      client_certificate = google_sql_ssl_cert.destination.cert
      ca_certificate     = google_sql_ssl_cert.destination.server_ca_cert
    }
    backups {
      gcs_bucket = google_storage_bucket.gcp_sql_dump_bucket.name
      gcs_prefix = ""
    }
  }

  labels = var.labels
}

References

https://cloud.google.com/database-migration/docs/reference/rest/v1/projects.locations.connectionProfiles#sqlserverconnectionprofile

b/372208238

SarahFrench commented 1 month ago

Note from triage: We should add support for the sqlserver field in the resource and make sure that it conflicts with the other possible settings for Union field connection_profile.

mariusmitrofan commented 1 month ago

Amendment connection profile id sugestion for source and destination based on official API description:

# SOURCE
resource "google_database_migration_service_connection_profile" "source" {
  location                      = var.gcp_region
  connection_profile_id = "${var.gcp_sql_identifier}-source"
  display_name              = "${var.gcp_sql_identifier}-source"

  sqlserver {
    backups {
      gcs_bucket = google_storage_bucket.gcp_sql_dump_bucket.name
      gcs_prefix = ""
    }
  }

  labels = var.labels
}
# DESTINATION
resource "google_database_migration_service_connection_profile" "destination" {
  location                      = var.gcp_region
  connection_profile_id = "${var.gcp_sql_identifier}-destination"
  display_name              = "${var.gcp_sql_identifier}-destination"

  sqlserver {
    host         = data.google_sql_database_instance.destination.ip_address.0.ip_address
    port         = 1433
    username     = google_sql_user.destination.name
    password     = google_sql_user.destination.password
    cloud_sql_id = data.google_sql_database_instance.destination.name
    ssl {
      client_key         = google_sql_ssl_cert.destination.private_key
      client_certificate = google_sql_ssl_cert.destination.cert
      ca_certificate     = google_sql_ssl_cert.destination.server_ca_cert
    }
  }

  labels = var.labels
}

Here is also a migration job possible logic:

resource "google_database_migration_service_migration_job" "sqlserver" {
  location          = var.gcp_region
  migration_job_id  = "${var.gcp_sql_identifier}-migration-job"
  display_name      = "${var.gcp_sql_identifier}-migration-job"

  source          = google_database_migration_service_connection_profile.source.name
  destination     = google_database_migration_service_connection_profile.destination.name
  type            = "CONTINUOUS"

  sqlserver_config {
    diff_backup   = true
    database_list = "db1,db2"
  }

  labels = var.labels
}