11package mongodb
22
33import (
4+ "bytes"
45 "context"
56 "errors"
67 "fmt"
8+ "io"
79 "strings"
810 "time"
911
@@ -12,9 +14,11 @@ import (
1214 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1315 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1416 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
17+
1518 ipamAPI "github.com/scaleway/scaleway-sdk-go/api/ipam/v1"
1619 mongodb "github.com/scaleway/scaleway-sdk-go/api/mongodb/v1"
1720 "github.com/scaleway/scaleway-sdk-go/scw"
21+
1822 "github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
1923 "github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
2024 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
@@ -233,6 +237,11 @@ func ResourceInstance() *schema.Resource {
233237 // Common
234238 "region" : regional .Schema (),
235239 "project_id" : account .ProjectIDSchema (),
240+ "tls_certificate" : {
241+ Type : schema .TypeString ,
242+ Computed : true ,
243+ Description : "PEM-encoded TLS certificate for MongoDB" ,
244+ },
236245 },
237246 CustomizeDiff : customdiff .All (
238247 func (ctx context.Context , d * schema.ResourceDiff , meta any ) error {
@@ -460,6 +469,18 @@ func ResourceInstanceRead(ctx context.Context, d *schema.ResourceData, m any) di
460469
461470 _ = d .Set ("settings" , map [string ]string {})
462471
472+ cert , err := mongodbAPI .GetInstanceCertificate (& mongodb.GetInstanceCertificateRequest {
473+ Region : region ,
474+ InstanceID : ID ,
475+ }, scw .WithContext (ctx ))
476+ if err == nil && cert != nil {
477+ var buf bytes.Buffer
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
0 commit comments