Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions docs/resources/mongodb_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ In addition to all arguments above, the following attributes are exported:
- `id` - The ID of the endpoint.
- `port` - TCP port of the endpoint.
- `dns_records` - List of DNS records for your endpoint.
- `tls_certificate` - The PEM-encoded TLS certificate for the MongoDB® instance, if available.

## Import

Expand Down
24 changes: 24 additions & 0 deletions internal/services/mongodb/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"io"
"strings"
"time"

Expand Down Expand Up @@ -233,6 +234,11 @@ func ResourceInstance() *schema.Resource {
// Common
"region": regional.Schema(),
"project_id": account.ProjectIDSchema(),
"tls_certificate": {
Type: schema.TypeString,
Computed: true,
Description: "PEM-encoded TLS certificate for MongoDB",
},
},
CustomizeDiff: customdiff.All(
func(ctx context.Context, d *schema.ResourceDiff, meta any) error {
Expand Down Expand Up @@ -460,6 +466,24 @@ func ResourceInstanceRead(ctx context.Context, d *schema.ResourceData, m any) di

_ = d.Set("settings", map[string]string{})

cert, err := mongodbAPI.GetInstanceCertificate(&mongodb.GetInstanceCertificateRequest{
Region: region,
InstanceID: ID,
}, scw.WithContext(ctx))

if err == nil && cert != nil {
certBytes, readErr := io.ReadAll(cert.Content)
if readErr == nil {
_ = d.Set("tls_certificate", string(certBytes))
} else {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Failed to read MongoDB TLS certificate content",
Detail: readErr.Error(),
})
}
}

return diags
}

Expand Down
1 change: 1 addition & 0 deletions internal/services/mongodb/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestAccMongoDBInstance_Basic(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_mongodb_instance.main", "node_number", "1"),
resource.TestCheckResourceAttr("scaleway_mongodb_instance.main", "user_name", "my_initial_user"),
resource.TestCheckResourceAttr("scaleway_mongodb_instance.main", "password", "thiZ_is_v&ry_s3cret"),
resource.TestCheckResourceAttrSet("scaleway_mongodb_instance.main", "tls_certificate"),
),
},
},
Expand Down
Loading
Loading