-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathmodel.go
65 lines (55 loc) · 2.19 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package searchdeployment
import (
"context"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
// TODO: update before merging to master: "go.mongodb.org/atlas-sdk/v20250219001/admin"
"github.com/mongodb/atlas-sdk-go/admin"
)
func NewSearchDeploymentReq(ctx context.Context, searchDeploymentPlan *TFSearchDeploymentRSModel) admin.ApiSearchDeploymentRequest {
var specs []TFSearchNodeSpecModel
searchDeploymentPlan.Specs.ElementsAs(ctx, &specs, true)
resultSpecs := make([]admin.ApiSearchDeploymentSpec, len(specs))
for i, spec := range specs {
resultSpecs[i] = admin.ApiSearchDeploymentSpec{
InstanceSize: spec.InstanceSize.ValueString(),
NodeCount: int(spec.NodeCount.ValueInt64()),
}
}
return admin.ApiSearchDeploymentRequest{
Specs: resultSpecs,
}
}
func NewTFSearchDeployment(ctx context.Context, clusterName string, deployResp *admin.ApiSearchDeploymentResponse, timeout *timeouts.Value, allowMultipleSpecs bool) (*TFSearchDeploymentRSModel, diag.Diagnostics) {
result := TFSearchDeploymentRSModel{
ID: types.StringPointerValue(deployResp.Id),
ClusterName: types.StringValue(clusterName),
ProjectID: types.StringPointerValue(deployResp.GroupId),
StateName: types.StringPointerValue(deployResp.StateName),
EncryptionAtRestProvider: types.StringPointerValue(deployResp.EncryptionAtRestProvider),
}
if timeout != nil {
result.Timeouts = *timeout
}
specs := deployResp.GetSpecs()
if !allowMultipleSpecs && len(specs) > 1 {
specs = specs[:1]
}
specsList, diagnostics := types.ListValueFrom(ctx, SpecObjectType, newTFSpecsModel(specs))
if diagnostics.HasError() {
return nil, diagnostics
}
result.Specs = specsList
return &result, diagnostics
}
func newTFSpecsModel(specs []admin.ApiSearchDeploymentSpec) []TFSearchNodeSpecModel {
result := make([]TFSearchNodeSpecModel, len(specs))
for i, v := range specs {
result[i] = TFSearchNodeSpecModel{
InstanceSize: types.StringValue(v.InstanceSize),
NodeCount: types.Int64Value(int64(v.NodeCount)),
}
}
return result
}