Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Database Migration Services - Connection Profile resource #7447

Merged
merged 22 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
50c03a7
Implemented DBMS resource
NickElliot Feb 1, 2023
4ce4656
Updates
NickElliot Feb 1, 2023
2ad090d
Updates
NickElliot Feb 1, 2023
9f81375
Added custom flattens for sensitive fields
NickElliot Feb 2, 2023
77e8bc8
missing api tag
NickElliot Feb 3, 2023
de64b2e
updated required tags for field
NickElliot Feb 13, 2023
33461f4
re formatted into splitting api.yaml, added example tests
NickElliot Mar 13, 2023
efd9032
removing api.yaml
NickElliot Mar 13, 2023
055f66f
making suggested updates and corrections from reviewer -- adding outp…
NickElliot Mar 15, 2023
aef2f2a
Merged terraform.yaml to resource yaml, added examples
NickElliot Mar 17, 2023
47d3c4c
updated tests for errors
NickElliot Apr 5, 2023
2d9d109
Updates made to examples, in progress (failing) handwritten update test
NickElliot Apr 10, 2023
a41da10
added handwritten test missing from previous commit
NickElliot Apr 10, 2023
8459f96
rebasing and updating testAccPreCheck to AccTestPreCheck
NickElliot Apr 11, 2023
10308de
resolved update test issue, added import format
NickElliot Apr 12, 2023
54084bb
go fmt
NickElliot Apr 12, 2023
e47cf51
copyright notice, adding ignore_read_extra per fix for nested sensiti…
NickElliot Apr 13, 2023
5fd01af
changing hard coded cluster name to variable
NickElliot Apr 13, 2023
09ee05f
suggested formatting fixes/minor update test functionality update
NickElliot Apr 20, 2023
483f283
test indentation
NickElliot Apr 20, 2023
05baa6b
removing trailing white space
NickElliot Apr 20, 2023
5665a8a
renamed file
NickElliot Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
576 changes: 576 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
NickElliot marked this conversation as resolved.
Show resolved Hide resolved
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,58 @@
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 = {
testanno = "testanno"
}
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 = {
testalloylabela = "testalloylabelb"
}
primary_instance_settings {
id = "priminstid"
machine_config {
cpu_count = 2
}
database_flags = {
}
labels = {
testalloyinstlabela = "testalloyinstlabelb"
}
}
}
}
NickElliot marked this conversation as resolved.
Show resolved Hide resolved

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 = {
testanno = "testanno"
}
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 = {
testlabela = "testlabelb"
}
cloudsql {
settings {
database_version = "MYSQL_5_7"
user_labels = {
testuserlabela = "testuserlabelb"
}
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] %>]
NickElliot marked this conversation as resolved.
Show resolved Hide resolved
}
Loading