Skip to content

Commit

Permalink
Add support for Database Migration Services - Connection Profile reso…
Browse files Browse the repository at this point in the history
  • Loading branch information
NickElliot authored and Madhura Phadnis committed Apr 27, 2023
1 parent 4b49015 commit f3666e0
Show file tree
Hide file tree
Showing 16 changed files with 1,043 additions and 0 deletions.
577 changes: 577 additions & 0 deletions mmv1/products/databasemigrationservice/connectionprofile.yaml

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions mmv1/products/databasemigrationservice/product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2022 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::Product
name: DatabaseMigrationService
display_name: DatabaseMigrationService
versions:
- !ruby/object:Api::Product::Version
name: ga
base_url: https://datamigration.googleapis.com/v1/
scopes:
- https://www.googleapis.com/auth/cloud-platform
apis_required:
- !ruby/object:Api::Product::ApiReference
name: Database Migration API
url: https://console.cloud.google.com/apis/library/datamigration.googleapis.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("alloydb.0.settings.0.initial_user.0.password")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("cloudsql.0.settings.0.root_password")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("mysql.0.password")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("mysql.0.ssl.0.ca_certificate")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("mysql.0.ssl.0.client_certificate")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("mysql.0.ssl.0.client_key")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("postgresql.0.password")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("postgresql.0.ssl.0.ca_certificate")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("postgresql.0.ssl.0.client_certificate")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%# The license inside this block applies to this file.
# Copyright 2023 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("postgresql.0.ssl.0.client_key")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
data "google_project" "project" {
}

resource "google_compute_network" "default" {
name = "tf-test-alloydb-cp%{random_suffix}"
}

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

depends_on = [google_compute_network.default]
}

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]

depends_on = [google_compute_global_address.private_ip_alloc]
}


resource "google_database_migration_service_connection_profile" "<%= ctx[:primary_resource_id] %>" {
location = "us-central1"
connection_profile_id = "<%= ctx[:vars]["profile"] %>"
display_name = "<%= ctx[:vars]["profile"] %>_display"
labels = {
foo = "bar"
}
alloydb {
cluster_id = "dbmsalloycluster%{random_suffix}"
settings {
initial_user {
user = "alloyuser%{random_suffix}"
password = "alloypass%{random_suffix}"
}
vpc_network = "projects/${data.google_project.project.number}/global/networks/${google_compute_network.default.name}"
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]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
data "google_project" "project" {
}

resource "google_sql_database_instance" "cloudsqldb" {
name = "<%= ctx[:vars]["sqldb"] %>"
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 = "<%= ctx[:vars]["sqldb_cert"] %>"
instance = google_sql_database_instance.cloudsqldb.name

depends_on = [google_sql_database_instance.cloudsqldb]
}

resource "google_sql_user" "sqldb_user" {
name = "<%= ctx[:vars]["sqldb_user"] %>"
instance = google_sql_database_instance.cloudsqldb.name
password = "<%= ctx[:vars]["sqldb_pass"] %>"

depends_on = [google_sql_ssl_cert.sql_client_cert]
}



resource "google_database_migration_service_connection_profile" "<%= ctx[:primary_resource_id] %>" {
location = "us-central1"
connection_profile_id = "<%= ctx[:vars]["from_profile"] %>"
display_name = "<%= ctx[:vars]["from_profile"] %>_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 = "<%= ctx[:vars]["sqldb"] %>"
}

depends_on = [google_sql_user.sqldb_user]
}


resource "google_database_migration_service_connection_profile" "<%= ctx[:primary_resource_id] %>_destination" {
location = "us-central1"
connection_profile_id = "<%= ctx[:vars]["to_profile"] %>"
display_name = "<%= ctx[:vars]["to_profile"] %>_displayname"
labels = {
foo = "bar"
}
cloudsql {
settings {
database_version = "MYSQL_5_7"
user_labels = {
cloudfoo = "cloudbar"
}
tier = "db-n1-standard-1"
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/<%= ctx[:vars]["from_profile"] %>"
root_password = "testpasscloudsql"
}


}
depends_on = [google_database_migration_service_connection_profile.<%= ctx[:primary_resource_id] %>]
}
Loading

0 comments on commit f3666e0

Please sign in to comment.