Skip to content

Commit c7d11a8

Browse files
authored
Support creating Database Migration Service connection profiles connected to existing Cloud SQL and AlloyDB instances (#11484)
1 parent 5354c6c commit c7d11a8

4 files changed

+160
-16
lines changed

mmv1/products/databasemigrationservice/ConnectionProfile.yaml

+55-16
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ examples:
9696
global_address_name: 'private-ip-alloc'
9797
network_name: 'vpc-network'
9898
skip_test: true
99+
- !ruby/object:Provider::Terraform::Examples
100+
name: 'database_migration_service_connection_profile_existing_mysql'
101+
primary_resource_id: 'existing-mysql'
102+
vars:
103+
destination_csql: 'destination-csql'
104+
destination_cp: 'destination-cp'
105+
- !ruby/object:Provider::Terraform::Examples
106+
name: 'database_migration_service_connection_profile_existing_postgres'
107+
primary_resource_id: 'existing-psql'
108+
vars:
109+
destination_csql: 'destination-csql'
110+
destination_cp: 'destination-cp'
111+
- !ruby/object:Provider::Terraform::Examples
112+
name: 'database_migration_service_connection_profile_existing_alloydb'
113+
primary_resource_id: 'existing-alloydb'
114+
vars:
115+
destination_alloydb: 'destination-alloydb'
116+
destination_cp: 'destination-cp'
99117
parameters:
100118
- !ruby/object:Api::Type::String
101119
name: 'connectionProfileId'
@@ -184,25 +202,30 @@ properties:
184202
properties:
185203
- !ruby/object:Api::Type::String
186204
name: 'host'
187-
required: true
205+
required_with:
206+
- 'mysql.0.port'
207+
- 'mysql.0.username'
188208
description: |
189-
Required. The IP or hostname of the source MySQL database.
209+
The IP or hostname of the source MySQL database.
190210
- !ruby/object:Api::Type::Integer
191211
name: 'port'
192-
required: true
212+
required_with:
213+
- 'mysql.0.host'
214+
- 'mysql.0.username'
193215
description: |
194-
Required. The network port of the source MySQL database.
216+
The network port of the source MySQL database.
195217
- !ruby/object:Api::Type::String
196218
name: 'username'
197-
required: true
219+
required_with:
220+
- 'mysql.0.host'
221+
- 'mysql.0.port'
198222
description: |
199-
Required. The username that Database Migration Service will use to connect to the database. The value is encrypted when stored in Database Migration Service.
223+
The username that Database Migration Service will use to connect to the database. The value is encrypted when stored in Database Migration Service.
200224
- !ruby/object:Api::Type::String
201225
name: 'password'
202-
required: true
203226
immutable: true
204227
description: |
205-
Required. Input only. The password for the user that Database Migration Service will be using to connect to the database.
228+
Input only. The password for the user that Database Migration Service will be using to connect to the database.
206229
This field is not returned on request, and the value is encrypted when stored in Database Migration Service.
207230
sensitive: true
208231
custom_flatten: templates/terraform/custom_flatten/database_migration_service_connection_profile_mysql_password.go.erb
@@ -266,25 +289,37 @@ properties:
266289
properties:
267290
- !ruby/object:Api::Type::String
268291
name: 'host'
269-
required: true
292+
required_with:
293+
- 'postgresql.0.port'
294+
- 'postgresql.0.username'
295+
- 'postgresql.0.password'
270296
description: |
271-
Required. The IP or hostname of the source MySQL database.
297+
The IP or hostname of the source MySQL database.
272298
- !ruby/object:Api::Type::Integer
273299
name: 'port'
274-
required: true
300+
required_with:
301+
- 'postgresql.0.host'
302+
- 'postgresql.0.username'
303+
- 'postgresql.0.password'
275304
description: |
276-
Required. The network port of the source MySQL database.
305+
The network port of the source MySQL database.
277306
- !ruby/object:Api::Type::String
278307
name: 'username'
279-
required: true
308+
required_with:
309+
- 'postgresql.0.host'
310+
- 'postgresql.0.port'
311+
- 'postgresql.0.password'
280312
description: |
281-
Required. The username that Database Migration Service will use to connect to the database. The value is encrypted when stored in Database Migration Service.
313+
The username that Database Migration Service will use to connect to the database. The value is encrypted when stored in Database Migration Service.
282314
- !ruby/object:Api::Type::String
283315
name: 'password'
284-
required: true
316+
required_with:
317+
- 'postgresql.0.host'
318+
- 'postgresql.0.port'
319+
- 'postgresql.0.username'
285320
immutable: true
286321
description: |
287-
Required. Input only. The password for the user that Database Migration Service will be using to connect to the database.
322+
Input only. The password for the user that Database Migration Service will be using to connect to the database.
288323
This field is not returned on request, and the value is encrypted when stored in Database Migration Service.
289324
sensitive: true
290325
custom_flatten: templates/terraform/custom_flatten/database_migration_service_connection_profile_postgresql_password.go.erb
@@ -339,6 +374,10 @@ properties:
339374
name: 'cloudSqlId'
340375
description: |
341376
If the source is a Cloud SQL database, use this field to provide the Cloud SQL instance ID of the source.
377+
- !ruby/object:Api::Type::String
378+
name: 'alloydbClusterId'
379+
description: |
380+
If the connected database is an AlloyDB instance, use this field to provide the AlloyDB cluster ID.
342381
- !ruby/object:Api::Type::Enum
343382
name: 'networkArchitecture'
344383
output: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
data "google_project" "project" {
2+
}
3+
4+
resource "google_alloydb_cluster" "destination_alloydb" {
5+
cluster_id = "<%= ctx[:vars]['destination_alloydb'] %>"
6+
location = "us-central1"
7+
network_config {
8+
network = google_compute_network.default.id
9+
}
10+
database_version = "POSTGRES_15"
11+
12+
initial_user {
13+
user = "<%= ctx[:vars]['destination_alloydb'] %>"
14+
password = "<%= ctx[:vars]['destination_alloydb'] %>"
15+
}
16+
}
17+
18+
resource "google_alloydb_instance" "destination_alloydb_primary" {
19+
cluster = google_alloydb_cluster.destination_alloydb.name
20+
instance_id = "<%= ctx[:vars]['destination_alloydb'] %>-primary"
21+
instance_type = "PRIMARY"
22+
23+
depends_on = [google_service_networking_connection.vpc_connection]
24+
}
25+
26+
resource "google_compute_global_address" "private_ip_alloc" {
27+
name = "<%= ctx[:vars]['destination_alloydb'] %>"
28+
address_type = "INTERNAL"
29+
purpose = "VPC_PEERING"
30+
prefix_length = 16
31+
network = google_compute_network.default.id
32+
}
33+
34+
resource "google_service_networking_connection" "vpc_connection" {
35+
network = google_compute_network.default.id
36+
service = "servicenetworking.googleapis.com"
37+
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
38+
}
39+
40+
resource "google_compute_network" "default" {
41+
name = "<%= ctx[:vars]['destination_alloydb'] %>"
42+
}
43+
44+
resource "google_database_migration_service_connection_profile" "<%= ctx[:primary_resource_id] %>" {
45+
location = "us-central1"
46+
connection_profile_id = "<%= ctx[:vars]["destination_cp"] %>"
47+
display_name = "<%= ctx[:vars]["destination_cp"] %>_display"
48+
labels = {
49+
foo = "bar"
50+
}
51+
postgresql {
52+
alloydb_cluster_id = "<%= ctx[:vars]["destination_alloydb"] %>"
53+
}
54+
depends_on = [google_alloydb_cluster.destination_alloydb, google_alloydb_instance.destination_alloydb_primary]
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
data "google_project" "project" {
2+
}
3+
4+
resource "google_sql_database_instance" "destination_csql" {
5+
name = "<%= ctx[:vars]["destination_csql"] %>"
6+
database_version = "MYSQL_5_7"
7+
settings {
8+
tier = "db-n1-standard-1"
9+
deletion_protection_enabled = false
10+
}
11+
deletion_protection = false
12+
}
13+
14+
resource "google_database_migration_service_connection_profile" "<%= ctx[:primary_resource_id] %>" {
15+
location = "us-central1"
16+
connection_profile_id = "<%= ctx[:vars]["destination_cp"] %>"
17+
display_name = "<%= ctx[:vars]["destination_cp"] %>_display"
18+
labels = {
19+
foo = "bar"
20+
}
21+
mysql {
22+
cloud_sql_id = "<%= ctx[:vars]["destination_csql"] %>"
23+
}
24+
depends_on = [google_sql_database_instance.destination_csql]
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
data "google_project" "project" {
2+
}
3+
4+
resource "google_sql_database_instance" "destination_csql" {
5+
name = "<%= ctx[:vars]["destination_csql"] %>"
6+
database_version = "POSTGRES_15"
7+
settings {
8+
tier = "db-custom-2-13312"
9+
deletion_protection_enabled = false
10+
}
11+
deletion_protection = false
12+
}
13+
14+
resource "google_database_migration_service_connection_profile" "<%= ctx[:primary_resource_id] %>" {
15+
location = "us-central1"
16+
connection_profile_id = "<%= ctx[:vars]["destination_cp"] %>"
17+
display_name = "<%= ctx[:vars]["destination_cp"] %>_display"
18+
labels = {
19+
foo = "bar"
20+
}
21+
postgresql {
22+
cloud_sql_id = "<%= ctx[:vars]["destination_csql"] %>"
23+
}
24+
depends_on = [google_sql_database_instance.destination_csql]
25+
}

0 commit comments

Comments
 (0)