Skip to content

Commit b6371ba

Browse files
Datastream mongodb source (#15211) (#10888)
[upstream:542b160e0987721443637cb43096a4cad0f5cb18] Signed-off-by: Modular Magician <[email protected]>
1 parent eb47695 commit b6371ba

13 files changed

+2556
-92
lines changed

.changelog/15211.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
datastream: added `mongodb_profile` field to `google_datastream_connection_profile`
3+
```
4+
5+
```release-note:enhancement
6+
datastream: added `backfill_all.mongodb_excluded_objects` and `source_config.mongodb_source_config` fields to `google_datastream_stream`
7+
```

google-beta/services/datastream/resource_datastream_connection_profile.go

Lines changed: 624 additions & 7 deletions
Large diffs are not rendered by default.

google-beta/services/datastream/resource_datastream_connection_profile_generated_meta.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ fields:
2323
- api_field: 'labels'
2424
- field: 'location'
2525
provider_only: true
26+
- api_field: 'mongodbProfile.hostAddresses.hostname'
27+
- api_field: 'mongodbProfile.hostAddresses.port'
28+
- api_field: 'mongodbProfile.password'
29+
- api_field: 'mongodbProfile.replicaSet'
30+
- api_field: 'mongodbProfile.secretManagerStoredPassword'
31+
- api_field: 'mongodbProfile.srvConnectionFormat'
32+
- api_field: 'mongodbProfile.sslConfig.caCertificate'
33+
- api_field: 'mongodbProfile.sslConfig.caCertificateSet'
34+
- api_field: 'mongodbProfile.sslConfig.clientCertificate'
35+
- api_field: 'mongodbProfile.sslConfig.clientCertificateSet'
36+
- api_field: 'mongodbProfile.sslConfig.clientKey'
37+
- api_field: 'mongodbProfile.sslConfig.clientKeySet'
38+
- api_field: 'mongodbProfile.sslConfig.secretManagerStoredClientKey'
39+
- api_field: 'mongodbProfile.standardConnectionFormat.directConnection'
40+
- api_field: 'mongodbProfile.username'
2641
- api_field: 'mysqlProfile.hostname'
2742
- api_field: 'mysqlProfile.password'
2843
- api_field: 'mysqlProfile.port'

google-beta/services/datastream/resource_datastream_connection_profile_generated_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBasicExample(
4949
ResourceName: "google_datastream_connection_profile.default",
5050
ImportState: true,
5151
ImportStateVerify: true,
52-
ImportStateVerifyIgnore: []string{"connection_profile_id", "create_without_validation", "labels", "location", "terraform_labels"},
52+
ImportStateVerifyIgnore: []string{"connection_profile_id", "create_without_validation", "labels", "location", "mongodb_profile.0.ssl_config.0.ca_certificate", "mongodb_profile.0.ssl_config.0.client_certificate", "mongodb_profile.0.ssl_config.0.client_key", "mongodb_profile.0.ssl_config.0.secret_manager_stored_client_key", "terraform_labels"},
5353
},
5454
},
5555
})
@@ -95,7 +95,7 @@ func TestAccDatastreamConnectionProfile_datastreamConnectionProfilePostgresqlPri
9595
ResourceName: "google_datastream_connection_profile.default",
9696
ImportState: true,
9797
ImportStateVerify: true,
98-
ImportStateVerifyIgnore: []string{"connection_profile_id", "create_without_validation", "labels", "location", "postgresql_profile.0.password", "terraform_labels"},
98+
ImportStateVerifyIgnore: []string{"connection_profile_id", "create_without_validation", "labels", "location", "mongodb_profile.0.ssl_config.0.ca_certificate", "mongodb_profile.0.ssl_config.0.client_certificate", "mongodb_profile.0.ssl_config.0.client_key", "mongodb_profile.0.ssl_config.0.secret_manager_stored_client_key", "postgresql_profile.0.password", "terraform_labels"},
9999
},
100100
},
101101
})
@@ -256,7 +256,7 @@ func TestAccDatastreamConnectionProfile_datastreamConnectionProfileFullExample(t
256256
ResourceName: "google_datastream_connection_profile.default",
257257
ImportState: true,
258258
ImportStateVerify: true,
259-
ImportStateVerifyIgnore: []string{"connection_profile_id", "create_without_validation", "forward_ssh_connectivity.0.password", "labels", "location", "terraform_labels"},
259+
ImportStateVerifyIgnore: []string{"connection_profile_id", "create_without_validation", "forward_ssh_connectivity.0.password", "labels", "location", "mongodb_profile.0.ssl_config.0.ca_certificate", "mongodb_profile.0.ssl_config.0.client_certificate", "mongodb_profile.0.ssl_config.0.client_key", "mongodb_profile.0.ssl_config.0.secret_manager_stored_client_key", "terraform_labels"},
260260
},
261261
},
262262
})
@@ -306,7 +306,7 @@ func TestAccDatastreamConnectionProfile_datastreamConnectionProfilePostgresSecre
306306
ResourceName: "google_datastream_connection_profile.default",
307307
ImportState: true,
308308
ImportStateVerify: true,
309-
ImportStateVerifyIgnore: []string{"connection_profile_id", "create_without_validation", "labels", "location", "terraform_labels"},
309+
ImportStateVerifyIgnore: []string{"connection_profile_id", "create_without_validation", "labels", "location", "mongodb_profile.0.ssl_config.0.ca_certificate", "mongodb_profile.0.ssl_config.0.client_certificate", "mongodb_profile.0.ssl_config.0.client_key", "mongodb_profile.0.ssl_config.0.secret_manager_stored_client_key", "terraform_labels"},
310310
},
311311
},
312312
})

google-beta/services/datastream/resource_datastream_connection_profile_test.go

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
25+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
2526
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
2627
)
2728

@@ -527,3 +528,224 @@ EOT
527528
}
528529
`, context)
529530
}
531+
532+
func TestAccDatastreamConnectionProfile_mongoDb(t *testing.T) {
533+
t.Parallel()
534+
535+
// Context to provide a unique suffix for resource names, preventing collisions.
536+
context := map[string]interface{}{
537+
"random_suffix": acctest.RandString(t, 10),
538+
}
539+
540+
acctest.VcrTest(t, resource.TestCase{
541+
PreCheck: func() { acctest.AccTestPreCheck(t) },
542+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
543+
CheckDestroy: testAccCheckDatastreamConnectionProfileDestroyProducer(t),
544+
Steps: []resource.TestStep{
545+
{
546+
Config: testAccDatastreamConnectionProfile_mongoDbBasicExample(context),
547+
},
548+
{
549+
ResourceName: "google_datastream_connection_profile.default",
550+
ImportState: true,
551+
ImportStateVerify: true,
552+
ImportStateVerifyIgnore: []string{
553+
"create_without_validation",
554+
"mongodb_profile.0.ssl_config.0.ca_certificate",
555+
"mongodb_profile.0.ssl_config.0.client_certificate",
556+
"mongodb_profile.0.ssl_config.0.secret_manager_stored_client_key",
557+
},
558+
},
559+
{
560+
Config: testAccDatastreamConnectionProfile_mongoDbUpdateExample(context),
561+
ConfigPlanChecks: resource.ConfigPlanChecks{
562+
PreApply: []plancheck.PlanCheck{
563+
plancheck.ExpectResourceAction("google_datastream_connection_profile.default", plancheck.ResourceActionUpdate),
564+
},
565+
},
566+
},
567+
{
568+
ResourceName: "google_datastream_connection_profile.default",
569+
ImportState: true,
570+
ImportStateVerify: true,
571+
ImportStateVerifyIgnore: []string{
572+
"create_without_validation",
573+
"mongodb_profile.0.ssl_config.0.ca_certificate",
574+
"mongodb_profile.0.ssl_config.0.client_certificate",
575+
"mongodb_profile.0.ssl_config.0.secret_manager_stored_client_key",
576+
},
577+
},
578+
{
579+
Config: testAccDatastreamConnectionProfile_mongoDbBasic2Example(context),
580+
},
581+
{
582+
ResourceName: "google_datastream_connection_profile.default2",
583+
ImportState: true,
584+
ImportStateVerify: true,
585+
ImportStateVerifyIgnore: []string{
586+
"create_without_validation",
587+
"mongodb_profile.0.ssl_config.0.client_key",
588+
"mongodb_profile.0.ssl_config.0.ca_certificate",
589+
"mongodb_profile.0.ssl_config.0.client_certificate",
590+
},
591+
},
592+
},
593+
})
594+
}
595+
596+
// Terraform configuration for the initial creation of the MongoDB connection profile.
597+
func testAccDatastreamConnectionProfile_mongoDbBasicExample(context map[string]interface{}) string {
598+
return acctest.Nprintf(`
599+
data "google_project" "project" {}
600+
601+
resource "google_secret_manager_secret" "password_secret" {
602+
project = data.google_project.project.project_id
603+
secret_id = "tf-mongo-pw-secret-%{random_suffix}"
604+
replication {
605+
auto {}
606+
}
607+
}
608+
609+
resource "google_secret_manager_secret_version" "password_secret_version" {
610+
secret = google_secret_manager_secret.password_secret.id
611+
secret_data = "my-secret-password"
612+
}
613+
614+
resource "google_secret_manager_secret" "client_key_secret" {
615+
project = data.google_project.project.project_id
616+
secret_id = "tf-mongo-key-secret-%{random_suffix}"
617+
replication {
618+
auto {}
619+
}
620+
}
621+
622+
resource "google_secret_manager_secret_version" "client_key_secret_version" {
623+
secret = google_secret_manager_secret.client_key_secret.id
624+
secret_data = file("text-fixtures/private-key.pem")
625+
}
626+
627+
628+
resource "google_datastream_connection_profile" "default" {
629+
project = data.google_project.project.project_id
630+
display_name = "tf-mongodb-profile"
631+
location = "us-central1"
632+
connection_profile_id = "tf-mongo-cp-%{random_suffix}"
633+
create_without_validation = true // Set to true for tests to bypass actual connectivity checks.
634+
635+
mongodb_profile {
636+
host_addresses {
637+
hostname = "1.1.1.1"
638+
port = 27017
639+
}
640+
replica_set = "rs0"
641+
username = "user"
642+
secret_manager_stored_password = google_secret_manager_secret_version.password_secret_version.id
643+
ssl_config {
644+
ca_certificate = file("text-fixtures/ca-cert.pem")
645+
client_certificate = file("text-fixtures/cert.pem")
646+
secret_manager_stored_client_key = google_secret_manager_secret_version.client_key_secret_version.id
647+
}
648+
standard_connection_format {
649+
direct_connection = true
650+
}
651+
}
652+
653+
depends_on = [
654+
google_secret_manager_secret_version.password_secret_version,
655+
google_secret_manager_secret_version.client_key_secret_version,
656+
]
657+
}
658+
`, context)
659+
}
660+
661+
func testAccDatastreamConnectionProfile_mongoDbBasic2Example(context map[string]interface{}) string {
662+
return acctest.Nprintf(`
663+
data "google_project" "project" {}
664+
665+
resource "google_datastream_connection_profile" "default2" {
666+
project = data.google_project.project.project_id
667+
display_name = "tf-mongodb-profile"
668+
location = "us-central1"
669+
connection_profile_id = "tf-mongo-cp-%{random_suffix}-2"
670+
create_without_validation = true // Set to true for tests to bypass actual connectivity checks.
671+
672+
mongodb_profile {
673+
host_addresses {
674+
hostname = "1.1.1.1"
675+
}
676+
username = "user"
677+
password = "password"
678+
ssl_config {
679+
client_key = file("text-fixtures/private-key.pem")
680+
ca_certificate = file("text-fixtures/ca-cert.pem")
681+
client_certificate = file("text-fixtures/cert.pem")
682+
}
683+
srv_connection_format {}
684+
}
685+
}
686+
`, context)
687+
}
688+
689+
func testAccDatastreamConnectionProfile_mongoDbUpdateExample(context map[string]interface{}) string {
690+
return acctest.Nprintf(`
691+
data "google_project" "project" {}
692+
693+
resource "google_secret_manager_secret" "password_secret" {
694+
project = data.google_project.project.project_id
695+
secret_id = "tf-mongo-pw-secret-%{random_suffix}"
696+
replication {
697+
auto {}
698+
}
699+
}
700+
701+
resource "google_secret_manager_secret_version" "password_secret_version" {
702+
secret = google_secret_manager_secret.password_secret.id
703+
secret_data = "my-secret-password"
704+
}
705+
706+
resource "google_secret_manager_secret" "client_key_secret" {
707+
project = data.google_project.project.project_id
708+
secret_id = "tf-mongo-key-secret-%{random_suffix}"
709+
replication {
710+
auto {}
711+
}
712+
}
713+
714+
resource "google_secret_manager_secret_version" "client_key_secret_version" {
715+
secret = google_secret_manager_secret.client_key_secret.id
716+
secret_data = file("text-fixtures/private-key.pem")
717+
}
718+
719+
720+
resource "google_datastream_connection_profile" "default" {
721+
project = data.google_project.project.project_id
722+
display_name = "tf-mongodb-profile-updated" // <-- Changed
723+
location = "us-central1"
724+
connection_profile_id = "tf-mongo-cp-%{random_suffix}"
725+
create_without_validation = true // Set to true for tests to bypass actual connectivity checks.
726+
727+
mongodb_profile {
728+
host_addresses {
729+
hostname = "1.1.1.1"
730+
port = 27017
731+
}
732+
replica_set = "rs0"
733+
username = "newuser" // <-- Changed
734+
secret_manager_stored_password = google_secret_manager_secret_version.password_secret_version.id
735+
ssl_config {
736+
ca_certificate = file("text-fixtures/ca-cert.pem")
737+
client_certificate = file("text-fixtures/cert.pem")
738+
secret_manager_stored_client_key = google_secret_manager_secret_version.client_key_secret_version.id
739+
}
740+
standard_connection_format {
741+
direct_connection = true
742+
}
743+
}
744+
745+
depends_on = [
746+
google_secret_manager_secret_version.password_secret_version,
747+
google_secret_manager_secret_version.client_key_secret_version,
748+
]
749+
}
750+
`, context)
751+
}

0 commit comments

Comments
 (0)