@@ -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