google_database_migration_service_connection_profile

A connection profile definition.

To get more information about ConnectionProfile, see:

Open in Cloud Shell

Example Usage - Database Migration Service Connection Profile Cloudsql

data "google_project" "project" {
}

resource "google_sql_database_instance" "cloudsqldb" {
  name             = "my-database"
  database_version = "MYSQL_5_7"
  settings {
    tier = "db-n1-standard-1"
    deletion_protection_enabled = false
  }
  deletion_protection = false
}

resource "google_sql_ssl_cert" "sql_client_cert" {
  common_name = "my-cert"
  instance    = google_sql_database_instance.cloudsqldb.name

  depends_on = [google_sql_database_instance.cloudsqldb]
}

resource "google_sql_user" "sqldb_user" {
  name     = "my-username"
  instance = google_sql_database_instance.cloudsqldb.name
  password = "my-password"

  depends_on = [google_sql_ssl_cert.sql_client_cert]
}



resource "google_database_migration_service_connection_profile" "cloudsqlprofile" {
  location              = "us-central1"
  connection_profile_id = "my-fromprofileid"
  display_name          = "my-fromprofileid_display"
  labels = { 
    foo = "bar"
  }
  mysql {
    host     = google_sql_database_instance.cloudsqldb.ip_address.0.ip_address
    port     = 3306
    username = google_sql_user.sqldb_user.name
    password = google_sql_user.sqldb_user.password
    ssl {
      client_key         = google_sql_ssl_cert.sql_client_cert.private_key
      client_certificate = google_sql_ssl_cert.sql_client_cert.cert
      ca_certificate     = google_sql_ssl_cert.sql_client_cert.server_ca_cert
    }
    cloud_sql_id = "my-database"
  }

  depends_on = [google_sql_user.sqldb_user]
}


resource "google_database_migration_service_connection_profile" "cloudsqlprofile_destination" {
  location              = "us-central1"
  connection_profile_id = "my-toprofileid"
  display_name          = "my-toprofileid_displayname"
  labels = { 
    foo = "bar"
  }
  cloudsql {
    settings {
      database_version = "MYSQL_5_7"
      user_labels = { 
        cloudfoo = "cloudbar"
      }
      tier                      = "db-n1-standard-1"
      edition                   = "ENTERPRISE"
      storage_auto_resize_limit = "0"
      activation_policy         = "ALWAYS"
      ip_config {
        enable_ipv4 = true
        require_ssl = true
      }
      auto_storage_increase = true
      data_disk_type        = "PD_HDD"
      data_disk_size_gb     = "11"
      zone                  = "us-central1-b"
      source_id             = "projects/${data.google_project.project.project_id}/locations/us-central1/connectionProfiles/my-fromprofileid"
      root_password         = "testpasscloudsql"
    }
  }
  depends_on = [google_database_migration_service_connection_profile.cloudsqlprofile]
}
Open in Cloud Shell

Example Usage - Database Migration Service Connection Profile Postgres

resource "google_sql_database_instance" "postgresqldb" {
  name             = "my-database"
  database_version = "POSTGRES_12"
  settings {
    tier = "db-custom-2-13312"
  }
  deletion_protection = false
}

resource "google_sql_ssl_cert" "sql_client_cert" {
  common_name = "my-cert"
  instance    = google_sql_database_instance.postgresqldb.name

  depends_on = [google_sql_database_instance.postgresqldb]
}

resource "google_sql_user" "sqldb_user" {
  name     = "my-username"
  instance = google_sql_database_instance.postgresqldb.name
  password = "my-password"


  depends_on = [google_sql_ssl_cert.sql_client_cert]
}

resource "google_database_migration_service_connection_profile" "postgresprofile" {
  location = "us-central1"
  connection_profile_id = "my-profileid"
  display_name = "my-profileid_display"
  labels = { 
    foo = "bar" 
  }
  postgresql {
    host = google_sql_database_instance.postgresqldb.ip_address.0.ip_address
    port = 5432
    username = google_sql_user.sqldb_user.name
    password = google_sql_user.sqldb_user.password
    ssl {
      client_key = google_sql_ssl_cert.sql_client_cert.private_key
      client_certificate = google_sql_ssl_cert.sql_client_cert.cert
      ca_certificate = google_sql_ssl_cert.sql_client_cert.server_ca_cert
    }
    cloud_sql_id = "my-database"
  }
  depends_on = [google_sql_user.sqldb_user]
}

Example Usage - Database Migration Service Connection Profile Oracle

resource "google_database_migration_service_connection_profile" "oracleprofile" {
  location = "us-central1"
  connection_profile_id = "my-profileid"
  display_name = "my-profileid_display"
  labels = { 
    foo = "bar" 
  }
  oracle {
    host = "host"
    port = 1521
    username = "username"
    password = "password"
    database_service = "dbprovider"
    static_service_ip_connectivity {}
  }
}

Example Usage - Database Migration Service Connection Profile Alloydb

data "google_project" "project" {
}

resource "google_compute_network" "default" {
  name = "vpc-network"
}

resource "google_compute_global_address" "private_ip_alloc" {
  name          =  "private-ip-alloc"
  address_type  = "INTERNAL"
  purpose       = "VPC_PEERING"
  prefix_length = 16
  network       = google_compute_network.default.id
}

resource "google_service_networking_connection" "vpc_connection" {
  network                 = google_compute_network.default.id
  service                 = "servicenetworking.googleapis.com"
  reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}


resource "google_database_migration_service_connection_profile" "alloydbprofile" {
  location = "us-central1"
  connection_profile_id = "my-profileid"
  display_name = "my-profileid_display"
  labels = { 
    foo = "bar" 
  }
  alloydb {
    cluster_id = "tf-test-dbmsalloycluster%{random_suffix}"
    settings {
      initial_user {
        user = "alloyuser%{random_suffix}"
        password = "alloypass%{random_suffix}"
      }
      vpc_network = google_compute_network.default.id
      labels  = { 
        alloyfoo = "alloybar" 
      }
      primary_instance_settings {
        id = "priminstid"
        machine_config {
          cpu_count = 2
        }
        database_flags = { 
        }
        labels = { 
          alloysinstfoo = "allowinstbar" 
        }
      }
    }
  }

  depends_on = [google_service_networking_connection.vpc_connection]
}

Argument Reference

The following arguments are supported:


The mysql block supports:

The ssl block supports:

The postgresql block supports:

The ssl block supports:

The oracle block supports:

The ssl block supports:

The forward_ssh_connectivity block supports:

The private_connectivity block supports:

The cloudsql block supports:

The settings block supports:

The ip_config block supports:

The authorized_networks block supports:

The alloydb block supports:

The settings block supports:

The initial_user block supports:

The primary_instance_settings block supports:

The machine_config block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

The error block contains:

Timeouts

This resource provides the following Timeouts configuration options:

Import

ConnectionProfile can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import ConnectionProfile using one of the formats above. For example:

import {
  id = "projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}}"
  to = google_database_migration_service_connection_profile.default
}

When using the terraform import command, ConnectionProfile can be imported using one of the formats above. For example:

$ terraform import google_database_migration_service_connection_profile.default projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}}
$ terraform import google_database_migration_service_connection_profile.default {{project}}/{{location}}/{{connection_profile_id}}
$ terraform import google_database_migration_service_connection_profile.default {{location}}/{{connection_profile_id}}

User Project Overrides

This resource supports User Project Overrides.