diff --git a/mmv1/products/databasemigrationservice/MigrationJob.yaml b/mmv1/products/databasemigrationservice/MigrationJob.yaml new file mode 100644 index 000000000000..53f8b87e1165 --- /dev/null +++ b/mmv1/products/databasemigrationservice/MigrationJob.yaml @@ -0,0 +1,285 @@ +# Copyright 2024 Google Inc. +# 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. + +--- !ruby/object:Api::Resource +name: 'MigrationJob' +self_link: 'projects/{{project}}/locations/{{location}}/migrationJobs/{{migration_job_id}}' +import_format: + [ + 'projects/{{project}}/locations/{{location}}/migrationJobs/{{migration_job_id}}', + ] +base_url: 'projects/{{project}}/locations/{{location}}/migrationJobs' +create_url: 'projects/{{project}}/locations/{{location}}/migrationJobs?migrationJobId={{migration_job_id}}' +update_verb: :PATCH +update_mask: true +description: 'A migration job definition.' +references: !ruby/object:Api::Resource::ReferenceLinks + guides: + 'Database Migration': 'https://cloud.google.com/database-migration/docs/' + api: 'https://cloud.google.com/database-migration/docs/reference/rest/v1/projects.locations.migrationJobs/create' +async: !ruby/object:Api::OpAsync + operation: !ruby/object:Api::OpAsync::Operation + path: 'name' + base_url: '{{op_id}}' + wait_ms: 1000 + timeouts: !ruby/object:Api::Timeouts + insert_minutes: 60 + update_minutes: 60 + delete_minutes: 60 + result: !ruby/object:Api::OpAsync::Result + path: 'response' + status: !ruby/object:Api::OpAsync::Status + path: 'done' + complete: true + allowed: + - true + - false + error: !ruby/object:Api::OpAsync::Error + path: 'error' + message: 'message' +autogen_async: true +examples: + - !ruby/object:Provider::Terraform::Examples + name: 'database_migration_service_migration_job_mysql_to_mysql' + primary_resource_id: 'mysqltomysql' + vars: + migration_id: 'my-migrationid' + source_csql: 'source-csql' + source_sqldb_cert: 'cert' + source_sqldb_user: 'username' + source_sqldb_pass: 'password' + source_cp: 'source-cp' + destination_csql: 'destination-csql' + destination_cp: 'destination-cp' + - !ruby/object:Provider::Terraform::Examples + name: 'database_migration_service_migration_job_postgres_to_postgres' + primary_resource_id: 'psqltopsql' + vars: + migration_id: 'my-migrationid' + source_csql: 'source-csql' + source_sqldb_cert: 'cert' + source_sqldb_user: 'username' + source_sqldb_pass: 'password' + source_cp: 'source-cp' + destination_csql: 'destination-csql' + destination_cp: 'destination-cp' + - !ruby/object:Provider::Terraform::Examples + name: 'database_migration_service_migration_job_postgres_to_alloydb' + primary_resource_id: 'psqltoalloydb' + vars: + migration_id: 'my-migrationid' + source_csql: 'source-csql' + source_sqldb_cert: 'cert' + source_sqldb_user: 'username' + source_sqldb_pass: 'password' + source_cp: 'source-cp' + destination_alloydb: 'destination-alloydb' + destination_cp: 'destination-cp' +parameters: + - !ruby/object:Api::Type::String + name: 'migrationJobId' + required: true + immutable: true + url_param_only: true + description: | + The ID of the migration job. + - !ruby/object:Api::Type::String + name: 'location' + immutable: true + url_param_only: true + description: | + The location where the migration job should reside. +properties: + - !ruby/object:Api::Type::String + name: 'name' + output: true + description: | + The name of this migration job resource in the form of projects/{project}/locations/{location}/migrationJobs/{migrationJob}. + - !ruby/object:Api::Type::String + name: 'displayName' + description: | + The migration job display name. + - !ruby/object:Api::Type::Time + name: 'createTime' + output: true + description: | + Output only. The timestamp when the resource was created. A timestamp in RFC3339 UTC 'Zulu' format, accurate to nanoseconds. Example: '2014-10-02T15:01:23.045123456Z'. + - !ruby/object:Api::Type::KeyValueLabels + name: 'labels' + description: | + The resource labels for migration job to use to annotate any related underlying resources such as Compute Engine VMs. + - !ruby/object:Api::Type::Enum + name: 'state' + output: true + description: | + The current migration job state. + values: + - :DRAFT + - :NOT_STARTED + - :RUNNING + - :COMPLETED + - :STOPPED + - :FAILED + - !ruby/object:Api::Type::Enum + name: 'phase' + output: true + description: | + The current migration job phase. + values: + - :FULL_DUMP + - :CDC + - :PROMOTE_IN_PROGRESS + - :WAITING_FOR_SOURCE_WRITES_TO_STOP + - :PREPARING_THE_DUMP + - :READY_FOR_PROMOTE + - !ruby/object:Api::Type::NestedObject + name: 'error' + description: | + Output only. The error details in case of state FAILED. + output: true + properties: + - !ruby/object:Api::Type::Integer + name: 'code' + output: true + description: | + The status code, which should be an enum value of google.rpc.Code. + - !ruby/object:Api::Type::String + name: 'message' + output: true + description: | + Human readable message indicating details about the current status. + - !ruby/object:Api::Type::Array + name: 'details' + description: | + A list of messages that carry the error details. + item_type: Api::Type::KeyValuePairs + output: true + - !ruby/object:Api::Type::Enum + name: 'type' + description: | + The type of the migration job. + immutable: true + required: true + values: + - :ONE_TIME + - :CONTINUOUS + - !ruby/object:Api::Type::String + name: 'source' + immutable: true + required: true + description: | + The name of the source connection profile resource in the form of projects/{project}/locations/{location}/connectionProfiles/{sourceConnectionProfile}. + - !ruby/object:Api::Type::String + name: 'destination' + immutable: true + required: true + description: | + The name of the destination connection profile resource in the form of projects/{project}/locations/{location}/connectionProfiles/{destinationConnectionProfile}. + - !ruby/object:Api::Type::NestedObject + name: 'dumpFlags' + description: | + The initial dump flags. + properties: + - !ruby/object:Api::Type::Array + name: 'dumpFlags' + description: | + A list of dump flags + item_type: !ruby/object:Api::Type::NestedObject + properties: + - !ruby/object:Api::Type::String + name: 'name' + description: | + The name of the flag + - !ruby/object:Api::Type::String + name: 'value' + description: | + The vale of the flag + - !ruby/object:Api::Type::NestedObject + name: 'performanceConfig' + description: | + Data dump parallelism settings used by the migration. + properties: + - !ruby/object:Api::Type::Enum + name: 'dumpParallelLevel' + description: | + Initial dump parallelism level. + values: + - :MIN + - :OPTIMAL + - :MAX + - !ruby/object:Api::Type::String + name: 'dumpPath' + description: | + The path to the dump file in Google Cloud Storage, + in the format: (gs://[BUCKET_NAME]/[OBJECT_NAME]). + This field and the "dump_flags" field are mutually exclusive. + - !ruby/object:Api::Type::Enum + name: 'dumpType' + description: | + The type of the data dump. Supported for MySQL to CloudSQL for MySQL + migrations only. + values: + - :LOGICAL + - :PHYSICAL + - !ruby/object:Api::Type::NestedObject + name: 'staticIpConnectivity' + description: | + If set to an empty object (`{}`), the source database will allow incoming + connections from the public IP of the destination database. + You can retrieve the public IP of the Cloud SQL instance from the + Cloud SQL console or using Cloud SQL APIs. + exactly_one_of: + - reverseSshConnectivity + - vpcPeeringConnectivity + allow_empty_object: true + send_empty_value: true + properties: [] + - !ruby/object:Api::Type::NestedObject + name: 'reverseSshConnectivity' + description: | + The details of the VPC network that the source database is located in. + exactly_one_of: + - staticIpConnectivity + - vpcPeeringConnectivity + properties: + - !ruby/object:Api::Type::String + name: 'vmIp' + description: | + The IP of the virtual machine (Compute Engine) used as the bastion server + for the SSH tunnel. + - !ruby/object:Api::Type::Integer + name: 'vmPort' + description: | + The forwarding port of the virtual machine (Compute Engine) used as the + bastion server for the SSH tunnel. + - !ruby/object:Api::Type::String + name: 'vm' + description: | + The name of the virtual machine (Compute Engine) used as the bastion server + for the SSH tunnel. + - !ruby/object:Api::Type::String + name: 'vpc' + description: | + The name of the VPC to peer with the Cloud SQL private network. + - !ruby/object:Api::Type::NestedObject + name: 'vpcPeeringConnectivity' + description: | + The details of the VPC network that the source database is located in. + exactly_one_of: + - staticIpConnectivity + - reverseSshConnectivity + properties: + - !ruby/object:Api::Type::String + name: 'vpc' + description: | + The name of the VPC network to peer with the Cloud SQL private network. diff --git a/mmv1/templates/terraform/examples/database_migration_service_migration_job_mysql_to_mysql.tf.erb b/mmv1/templates/terraform/examples/database_migration_service_migration_job_mysql_to_mysql.tf.erb new file mode 100644 index 000000000000..b5e93e819231 --- /dev/null +++ b/mmv1/templates/terraform/examples/database_migration_service_migration_job_mysql_to_mysql.tf.erb @@ -0,0 +1,105 @@ +data "google_project" "project" { +} + +resource "google_sql_database_instance" "source_csql" { + name = "<%= ctx[:vars]["source_csql"] %>" + database_version = "MYSQL_5_7" + settings { + tier = "db-n1-standard-1" + deletion_protection_enabled = false + } + deletion_protection = false +} + +resource "google_sql_ssl_cert" "source_sql_client_cert" { + common_name = "<%= ctx[:vars]["source_sqldb_cert"] %>" + instance = google_sql_database_instance.source_csql.name + + depends_on = [google_sql_database_instance.source_csql] +} + +resource "google_sql_user" "source_sqldb_user" { + name = "<%= ctx[:vars]["source_sqldb_user"] %>" + instance = google_sql_database_instance.source_csql.name + password = "<%= ctx[:vars]["source_sqldb_pass"] %>" + + depends_on = [google_sql_ssl_cert.source_sql_client_cert] +} + +resource "google_database_migration_service_connection_profile" "source_cp" { + location = "us-central1" + connection_profile_id = "<%= ctx[:vars]["source_cp"] %>" + display_name = "<%= ctx[:vars]["source_cp"] %>_display" + labels = { + foo = "bar" + } + mysql { + host = google_sql_database_instance.source_csql.ip_address.0.ip_address + port = 3306 + username = google_sql_user.source_sqldb_user.name + password = google_sql_user.source_sqldb_user.password + ssl { + client_key = google_sql_ssl_cert.source_sql_client_cert.private_key + client_certificate = google_sql_ssl_cert.source_sql_client_cert.cert + ca_certificate = google_sql_ssl_cert.source_sql_client_cert.server_ca_cert + } + cloud_sql_id = "<%= ctx[:vars]["source_csql"] %>" + } + + depends_on = [google_sql_user.source_sqldb_user] +} + +resource "google_sql_database_instance" "destination_csql" { + name = "<%= ctx[:vars]["destination_csql"] %>" + database_version = "MYSQL_5_7" + settings { + tier = "db-n1-standard-1" + deletion_protection_enabled = false + } + deletion_protection = false +} + +resource "google_database_migration_service_connection_profile" "destination_cp" { + location = "us-central1" + connection_profile_id = "<%= ctx[:vars]["destination_cp"] %>" + display_name = "<%= ctx[:vars]["destination_cp"] %>_display" + labels = { + foo = "bar" + } + mysql { + cloud_sql_id = "<%= ctx[:vars]["destination_csql"] %>" + } + depends_on = [google_sql_database_instance.destination_csql] +} + +resource "google_compute_network" "default" { + name = "<%= ctx[:vars]['destination_csql'] %>" +} + +resource "google_database_migration_service_migration_job" "<%= ctx[:primary_resource_id] %>" { + location = "us-central1" + migration_job_id = "<%= ctx[:vars]["migration_id"] %>" + display_name = "<%= ctx[:vars]["migration_id"] %>_display" + labels = { + foo = "bar" + } + performance_config { + dump_parallel_level = "MAX" + } + vpc_peering_connectivity { + vpc = google_compute_network.default.id + } + dump_type = "LOGICAL" + dump_flags { + dump_flags { + name = "max-allowed-packet" + value = "1073741824" + } + } + source = google_database_migration_service_connection_profile.source_cp.name + destination = google_database_migration_service_connection_profile.destination_cp.name + type = "CONTINUOUS" +} + + + diff --git a/mmv1/templates/terraform/examples/database_migration_service_migration_job_postgres_to_alloydb.tf.erb b/mmv1/templates/terraform/examples/database_migration_service_migration_job_postgres_to_alloydb.tf.erb new file mode 100644 index 000000000000..8017a8647036 --- /dev/null +++ b/mmv1/templates/terraform/examples/database_migration_service_migration_job_postgres_to_alloydb.tf.erb @@ -0,0 +1,120 @@ +data "google_project" "project" { +} + +resource "google_sql_database_instance" "source_csql" { + name = "<%= ctx[:vars]["source_csql"] %>" + database_version = "POSTGRES_15" + settings { + tier = "db-custom-2-13312" + deletion_protection_enabled = false + } + deletion_protection = false +} + +resource "google_sql_ssl_cert" "source_sql_client_cert" { + common_name = "<%= ctx[:vars]["source_sqldb_cert"] %>" + instance = google_sql_database_instance.source_csql.name + + depends_on = [google_sql_database_instance.source_csql] +} + +resource "google_sql_user" "source_sqldb_user" { + name = "<%= ctx[:vars]["source_sqldb_user"] %>" + instance = google_sql_database_instance.source_csql.name + password = "<%= ctx[:vars]["source_sqldb_pass"] %>" + + depends_on = [google_sql_ssl_cert.source_sql_client_cert] +} + +resource "google_database_migration_service_connection_profile" "source_cp" { + location = "us-central1" + connection_profile_id = "<%= ctx[:vars]["source_cp"] %>" + display_name = "<%= ctx[:vars]["source_cp"] %>_display" + labels = { + foo = "bar" + } + postgresql { + host = google_sql_database_instance.source_csql.ip_address.0.ip_address + port = 3306 + username = google_sql_user.source_sqldb_user.name + password = google_sql_user.source_sqldb_user.password + ssl { + client_key = google_sql_ssl_cert.source_sql_client_cert.private_key + client_certificate = google_sql_ssl_cert.source_sql_client_cert.cert + ca_certificate = google_sql_ssl_cert.source_sql_client_cert.server_ca_cert + } + cloud_sql_id = "<%= ctx[:vars]["source_csql"] %>" + } + + depends_on = [google_sql_user.source_sqldb_user] +} + +resource "google_alloydb_cluster" "destination_alloydb" { + cluster_id = "<%= ctx[:vars]['destination_alloydb'] %>" + location = "us-central1" + network_config { + network = google_compute_network.default.id + } + database_version = "POSTGRES_15" + + initial_user { + user = "<%= ctx[:vars]['destination_alloydb'] %>" + password = "<%= ctx[:vars]['destination_alloydb'] %>" + } +} + +resource "google_alloydb_instance" "destination_alloydb_primary" { + cluster = google_alloydb_cluster.destination_alloydb.name + instance_id = "<%= ctx[:vars]['destination_alloydb'] %>-primary" + instance_type = "PRIMARY" + + depends_on = [google_service_networking_connection.vpc_connection] +} + +resource "google_compute_global_address" "private_ip_alloc" { + name = "<%= ctx[:vars]['destination_alloydb'] %>" + 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_compute_network" "default" { + name = "<%= ctx[:vars]['destination_alloydb'] %>" +} + +resource "google_database_migration_service_connection_profile" "destination_cp" { + location = "us-central1" + connection_profile_id = "<%= ctx[:vars]["destination_cp"] %>" + display_name = "<%= ctx[:vars]["destination_cp"] %>_display" + labels = { + foo = "bar" + } + postgresql { + alloydb_cluster_id = "<%= ctx[:vars]["destination_alloydb"] %>" + } + depends_on = [google_alloydb_cluster.destination_alloydb, google_alloydb_instance.destination_alloydb_primary] +} + +resource "google_database_migration_service_migration_job" "<%= ctx[:primary_resource_id] %>" { + location = "us-central1" + migration_job_id = "<%= ctx[:vars]["migration_id"] %>" + display_name = "<%= ctx[:vars]["migration_id"] %>_display" + labels = { + foo = "bar" + } + static_ip_connectivity { + } + source = google_database_migration_service_connection_profile.source_cp.name + destination = google_database_migration_service_connection_profile.destination_cp.name + type = "CONTINUOUS" +} + + + diff --git a/mmv1/templates/terraform/examples/database_migration_service_migration_job_postgres_to_postgres.tf.erb b/mmv1/templates/terraform/examples/database_migration_service_migration_job_postgres_to_postgres.tf.erb new file mode 100644 index 000000000000..01eff734e21d --- /dev/null +++ b/mmv1/templates/terraform/examples/database_migration_service_migration_job_postgres_to_postgres.tf.erb @@ -0,0 +1,90 @@ +data "google_project" "project" { +} + +resource "google_sql_database_instance" "source_csql" { + name = "<%= ctx[:vars]["source_csql"] %>" + database_version = "POSTGRES_15" + settings { + tier = "db-custom-2-13312" + deletion_protection_enabled = false + } + deletion_protection = false +} + +resource "google_sql_ssl_cert" "source_sql_client_cert" { + common_name = "<%= ctx[:vars]["source_sqldb_cert"] %>" + instance = google_sql_database_instance.source_csql.name + + depends_on = [google_sql_database_instance.source_csql] +} + +resource "google_sql_user" "source_sqldb_user" { + name = "<%= ctx[:vars]["source_sqldb_user"] %>" + instance = google_sql_database_instance.source_csql.name + password = "<%= ctx[:vars]["source_sqldb_pass"] %>" + + depends_on = [google_sql_ssl_cert.source_sql_client_cert] +} + +resource "google_database_migration_service_connection_profile" "source_cp" { + location = "us-central1" + connection_profile_id = "<%= ctx[:vars]["source_cp"] %>" + display_name = "<%= ctx[:vars]["source_cp"] %>_display" + labels = { + foo = "bar" + } + postgresql { + host = google_sql_database_instance.source_csql.ip_address.0.ip_address + port = 3306 + username = google_sql_user.source_sqldb_user.name + password = google_sql_user.source_sqldb_user.password + ssl { + client_key = google_sql_ssl_cert.source_sql_client_cert.private_key + client_certificate = google_sql_ssl_cert.source_sql_client_cert.cert + ca_certificate = google_sql_ssl_cert.source_sql_client_cert.server_ca_cert + } + cloud_sql_id = "<%= ctx[:vars]["source_csql"] %>" + } + + depends_on = [google_sql_user.source_sqldb_user] +} + +resource "google_sql_database_instance" "destination_csql" { + name = "<%= ctx[:vars]["destination_csql"] %>" + database_version = "POSTGRES_15" + settings { + tier = "db-custom-2-13312" + deletion_protection_enabled = false + } + deletion_protection = false +} + +resource "google_database_migration_service_connection_profile" "destination_cp" { + location = "us-central1" + connection_profile_id = "<%= ctx[:vars]["destination_cp"] %>" + display_name = "<%= ctx[:vars]["destination_cp"] %>_display" + labels = { + foo = "bar" + } + postgresql { + cloud_sql_id = "<%= ctx[:vars]["destination_csql"] %>" + } + depends_on = [google_sql_database_instance.destination_csql] +} + +resource "google_database_migration_service_migration_job" "<%= ctx[:primary_resource_id] %>" { + location = "us-central1" + migration_job_id = "<%= ctx[:vars]["migration_id"] %>" + display_name = "<%= ctx[:vars]["migration_id"] %>_display" + labels = { + foo = "bar" + } + static_ip_connectivity { + } + source = google_database_migration_service_connection_profile.source_cp.name + destination = google_database_migration_service_connection_profile.destination_cp.name + type = "CONTINUOUS" +} + + + diff --git a/mmv1/third_party/terraform/services/databasemigrationservice/resource_database_migration_service_migration_job_test.go b/mmv1/third_party/terraform/services/databasemigrationservice/resource_database_migration_service_migration_job_test.go new file mode 100644 index 000000000000..18d28ac54609 --- /dev/null +++ b/mmv1/third_party/terraform/services/databasemigrationservice/resource_database_migration_service_migration_job_test.go @@ -0,0 +1,256 @@ +package databasemigrationservice_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +func TestAccDatabaseMigrationServiceMigrationJob_update(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckDatabaseMigrationServiceMigrationJobDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDatabaseMigrationServiceMigrationJob_full(context), + }, + { + ResourceName: "google_database_migration_service_migration_job.mysqltomysql", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"labels", "location", "migration_job_id", "terraform_labels"}, + }, + { + Config: testAccDatabaseMigrationServiceMigrationJob_update(context), + }, + { + ResourceName: "google_database_migration_service_migration_job.mysqltomysql", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"labels", "location", "migration_job_id", "terraform_labels"}, + }, + }, + }) +} + +func testAccDatabaseMigrationServiceMigrationJob_full(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_project" "project" { +} + +resource "google_sql_database_instance" "source_csql" { + name = "tf-test-source-csql%{random_suffix}" + database_version = "MYSQL_5_7" + settings { + tier = "db-n1-standard-1" + deletion_protection_enabled = false + } + deletion_protection = false +} + +resource "google_sql_ssl_cert" "source_sql_client_cert" { + common_name = "cert%{random_suffix}" + instance = google_sql_database_instance.source_csql.name + + depends_on = [google_sql_database_instance.source_csql] +} + +resource "google_sql_user" "source_sqldb_user" { + name = "username%{random_suffix}" + instance = google_sql_database_instance.source_csql.name + password = "password%{random_suffix}" + + depends_on = [google_sql_ssl_cert.source_sql_client_cert] +} + +resource "google_database_migration_service_connection_profile" "source_cp" { + location = "us-central1" + connection_profile_id = "tf-test-source-cp%{random_suffix}" + display_name = "tf-test-source-cp%{random_suffix}_display" + labels = { + foo = "bar" + } + mysql { + host = google_sql_database_instance.source_csql.ip_address.0.ip_address + port = 3306 + username = google_sql_user.source_sqldb_user.name + password = google_sql_user.source_sqldb_user.password + ssl { + client_key = google_sql_ssl_cert.source_sql_client_cert.private_key + client_certificate = google_sql_ssl_cert.source_sql_client_cert.cert + ca_certificate = google_sql_ssl_cert.source_sql_client_cert.server_ca_cert + } + cloud_sql_id = "tf-test-source-csql%{random_suffix}" + } + + depends_on = [google_sql_user.source_sqldb_user] +} + +resource "google_sql_database_instance" "destination_csql" { + name = "tf-test-destination-csql%{random_suffix}" + database_version = "MYSQL_5_7" + settings { + tier = "db-n1-standard-1" + deletion_protection_enabled = false + } + deletion_protection = false +} + +resource "google_database_migration_service_connection_profile" "destination_cp" { + location = "us-central1" + connection_profile_id = "tf-test-destination-cp%{random_suffix}" + display_name = "tf-test-destination-cp%{random_suffix}_display" + labels = { + foo = "bar" + } + mysql { + cloud_sql_id = "tf-test-destination-csql%{random_suffix}" + } + depends_on = [google_sql_database_instance.destination_csql] +} + +resource "google_compute_network" "default" { + name = "tf-test-destination-csql%{random_suffix}" +} + +resource "google_database_migration_service_migration_job" "mysqltomysql" { + location = "us-central1" + migration_job_id = "tf-test-my-migrationid%{random_suffix}" + display_name = "tf-test-my-migrationid%{random_suffix}_display" + labels = { + foo = "bar" + } + performance_config { + dump_parallel_level = "MAX" + } + vpc_peering_connectivity { + vpc = google_compute_network.default.id + } + dump_type = "LOGICAL" + dump_flags { + dump_flags { + name = "max-allowed-packet" + value = "1073741824" + } + } + source = google_database_migration_service_connection_profile.source_cp.name + destination = google_database_migration_service_connection_profile.destination_cp.name + type = "CONTINUOUS" +} +`, context) +} + +func testAccDatabaseMigrationServiceMigrationJob_update(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_project" "project" { +} + +resource "google_sql_database_instance" "source_csql" { + name = "tf-test-source-csql%{random_suffix}" + database_version = "MYSQL_5_7" + settings { + tier = "db-n1-standard-1" + deletion_protection_enabled = false + } + deletion_protection = false +} + +resource "google_sql_ssl_cert" "source_sql_client_cert" { + common_name = "cert%{random_suffix}" + instance = google_sql_database_instance.source_csql.name + + depends_on = [google_sql_database_instance.source_csql] +} + +resource "google_sql_user" "source_sqldb_user" { + name = "username%{random_suffix}" + instance = google_sql_database_instance.source_csql.name + password = "password%{random_suffix}" + + depends_on = [google_sql_ssl_cert.source_sql_client_cert] +} + +resource "google_database_migration_service_connection_profile" "source_cp" { + location = "us-central1" + connection_profile_id = "tf-test-source-cp%{random_suffix}" + display_name = "tf-test-source-cp%{random_suffix}_display" + labels = { + foo = "bar" + } + mysql { + host = google_sql_database_instance.source_csql.ip_address.0.ip_address + port = 3306 + username = google_sql_user.source_sqldb_user.name + password = google_sql_user.source_sqldb_user.password + ssl { + client_key = google_sql_ssl_cert.source_sql_client_cert.private_key + client_certificate = google_sql_ssl_cert.source_sql_client_cert.cert + ca_certificate = google_sql_ssl_cert.source_sql_client_cert.server_ca_cert + } + cloud_sql_id = "tf-test-source-csql%{random_suffix}" + } + + depends_on = [google_sql_user.source_sqldb_user] +} + +resource "google_sql_database_instance" "destination_csql" { + name = "tf-test-destination-csql%{random_suffix}" + database_version = "MYSQL_5_7" + settings { + tier = "db-n1-standard-1" + deletion_protection_enabled = false + } + deletion_protection = false +} + +resource "google_database_migration_service_connection_profile" "destination_cp" { + location = "us-central1" + connection_profile_id = "tf-test-destination-cp%{random_suffix}" + display_name = "tf-test-destination-cp%{random_suffix}_display" + labels = { + foo = "bar" + } + mysql { + cloud_sql_id = "tf-test-destination-csql%{random_suffix}" + } + depends_on = [google_sql_database_instance.destination_csql] +} + +resource "google_compute_network" "default" { + name = "tf-test-destination-csql%{random_suffix}" +} + +resource "google_database_migration_service_migration_job" "mysqltomysql" { + location = "us-central1" + migration_job_id = "tf-test-my-migrationid%{random_suffix}" + display_name = "tf-test-my-migrationid%{random_suffix}_display" + labels = { + foo = "bar" + } + performance_config { + dump_parallel_level = "MIN" + } + static_ip_connectivity { + } + dump_type = "LOGICAL" + dump_flags { + dump_flags { + name = "max-allowed-packet" + value = "1231231234" + } + } + source = google_database_migration_service_connection_profile.source_cp.name + destination = google_database_migration_service_connection_profile.destination_cp.name + type = "ONE_TIME" +} +`, context) +}