Skip to content

Commit

Permalink
Add DMS MigrationJob resource (#11604)
Browse files Browse the repository at this point in the history
  • Loading branch information
owaismawasy authored Sep 16, 2024
1 parent 776e5fc commit c37f6c9
Show file tree
Hide file tree
Showing 5 changed files with 856 additions and 0 deletions.
285 changes: 285 additions & 0 deletions mmv1/products/databasemigrationservice/MigrationJob.yaml
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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"
}



Loading

0 comments on commit c37f6c9

Please sign in to comment.