Skip to content

Commit 778d970

Browse files
committed
feat(mongodb): add tsl certificate
1 parent 9662e6a commit 778d970

File tree

4 files changed

+2267
-284
lines changed

4 files changed

+2267
-284
lines changed

docs/resources/mongodb_instance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ In addition to all arguments above, the following attributes are exported:
126126
- `id` - The ID of the endpoint.
127127
- `port` - TCP port of the endpoint.
128128
- `dns_records` - List of DNS records for your endpoint.
129+
- `tls_certificate` - The PEM-encoded TLS certificate for the MongoDB® instance, if available.
129130

130131
## Import
131132

internal/services/mongodb/instance.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package mongodb
22

33
import (
4+
"bytes"
45
"context"
56
"errors"
67
"fmt"
8+
"io"
79
"strings"
810
"time"
911

@@ -233,6 +235,11 @@ func ResourceInstance() *schema.Resource {
233235
// Common
234236
"region": regional.Schema(),
235237
"project_id": account.ProjectIDSchema(),
238+
"tls_certificate": {
239+
Type: schema.TypeString,
240+
Computed: true,
241+
Description: "PEM-encoded TLS certificate for MongoDB",
242+
},
236243
},
237244
CustomizeDiff: customdiff.All(
238245
func(ctx context.Context, d *schema.ResourceDiff, meta any) error {
@@ -460,6 +467,20 @@ func ResourceInstanceRead(ctx context.Context, d *schema.ResourceData, m any) di
460467

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

470+
cert, err := mongodbAPI.GetInstanceCertificate(&mongodb.GetInstanceCertificateRequest{
471+
Region: region,
472+
InstanceID: ID,
473+
}, scw.WithContext(ctx))
474+
475+
var buf bytes.Buffer
476+
477+
if err == nil && cert != nil {
478+
_, copyErr := io.Copy(&buf, cert.Content)
479+
if copyErr == nil {
480+
_ = d.Set("tls_certificate", buf.String())
481+
}
482+
}
483+
463484
return diags
464485
}
465486

internal/services/mongodb/instance_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestAccMongoDBInstance_Basic(t *testing.T) {
4141
resource.TestCheckResourceAttr("scaleway_mongodb_instance.main", "node_number", "1"),
4242
resource.TestCheckResourceAttr("scaleway_mongodb_instance.main", "user_name", "my_initial_user"),
4343
resource.TestCheckResourceAttr("scaleway_mongodb_instance.main", "password", "thiZ_is_v&ry_s3cret"),
44+
resource.TestCheckResourceAttrSet("scaleway_mongodb_instance.main", "tls_certificate"),
4445
),
4546
},
4647
},

0 commit comments

Comments
 (0)