Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions internal/services/mongodb/instance.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package mongodb

import (
"bytes"
"context"
"errors"
"fmt"
"io"
"strings"
"time"

Expand Down Expand Up @@ -233,6 +235,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 +467,20 @@ 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))

var buf bytes.Buffer

if err == nil && cert != nil {
_, copyErr := io.Copy(&buf, cert.Content)
if copyErr == nil {
_ = d.Set("tls_certificate", buf.String())
}
}

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