Skip to content

INTMDB-710: Serverless Instance wants to do an in-place update on every run #1152

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

Merged
merged 8 commits into from
May 3, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func integrationToSchema(d *schema.ResourceData, integration *matlas.ThirdPartyI
"org_name": integration.OrgName,
"url": integrationSchema.URL,
"secret": integrationSchema.Secret,
"microsoft_teams_webhook_url": integrationSchema.MicrosoftTeamsWebhookURL,
"microsoft_teams_webhook_url": integration.MicrosoftTeamsWebhookURL,
"user_name": integrationSchema.UserName,
"password": integrationSchema.Password,
"service_discovery": integration.ServiceDiscovery,
Expand Down
8 changes: 4 additions & 4 deletions mongodbatlas/resource_mongodbatlas_serverless_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ func resourceMongoDBAtlasServerlessInstanceRead(ctx context.Context, d *schema.R
if err := d.Set("connection_strings_standard_srv", serverlessInstance.ConnectionStrings.StandardSrv); err != nil {
return diag.Errorf("error setting `connection_strings_standard_srv` for serverless instance (%s): %s", d.Id(), err)
}
if len(serverlessInstance.ConnectionStrings.PrivateEndpoint) > 0 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if was the bug as we want to populate the ConnectionStrings.PrivateEndpoint with an empty array

if err := d.Set("connection_strings_private_endpoint_srv", flattenSRVConnectionString(serverlessInstance.ConnectionStrings.PrivateEndpoint)); err != nil {
return diag.Errorf("error setting `connection_strings_private_endpoint_srv` for serverless instance (%s): %s", d.Id(), err)
}

if err := d.Set("connection_strings_private_endpoint_srv", flattenSRVConnectionString(serverlessInstance.ConnectionStrings.PrivateEndpoint)); err != nil {
return diag.Errorf("error setting `connection_strings_private_endpoint_srv` for serverless instance (%s): %s", d.Id(), err)
}

if err := d.Set("create_date", serverlessInstance.CreateDate); err != nil {
return diag.Errorf("error setting `create_date` for serverless instance (%s): %s", d.Id(), err)
}
Expand Down
17 changes: 16 additions & 1 deletion mongodbatlas/resource_mongodbatlas_serverless_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAccClusterRSServerlessInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "project_id", projectID),
resource.TestCheckResourceAttr(resourceName, "name", instanceName),
resource.TestCheckResourceAttr(resourceName, "termination_protection_enabled", "false"),
testAccCheckConnectionStringPrivateEndpointIsPresentWithNoElement(resourceName),
),
},
},
Expand Down Expand Up @@ -114,11 +115,25 @@ func testAccCheckMongoDBAtlasServerlessInstanceImportStateIDFunc(resourceName st
}

ids := decodeStateID(rs.Primary.ID)

return fmt.Sprintf("%s-%s", ids["project_id"], ids["name"]), nil
}
}

func testAccCheckConnectionStringPrivateEndpointIsPresentWithNoElement(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("not found: %s", resourceName)
}

if connectionStringPrivateEndpoint := rs.Primary.Attributes["connection_strings_private_endpoint_srv.#"]; connectionStringPrivateEndpoint == "" {
return fmt.Errorf("expected connection_strings_private_endpoint_srv to be present")
}

return nil
}
}

func testAccMongoDBAtlasServerlessInstanceConfig(projectID, name string, ignoreConnectionStrings bool) string {
lifecycle := ""

Expand Down