-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathmodel_search_deployment.go
60 lines (49 loc) · 1.85 KB
/
model_search_deployment.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
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"
"go.mongodb.org/atlas-sdk/v20231115001/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) (*TFSearchDeploymentRSModel, diag.Diagnostics) {
result := TFSearchDeploymentRSModel{
ID: types.StringPointerValue(deployResp.Id),
ClusterName: types.StringValue(clusterName),
ProjectID: types.StringPointerValue(deployResp.GroupId),
StateName: types.StringPointerValue(deployResp.StateName),
}
if timeout != nil {
result.Timeouts = *timeout
}
specsList, diagnostics := types.ListValueFrom(ctx, SpecObjectType, newTFSpecsModel(deployResp.Specs))
if diagnostics.HasError() {
return nil, diagnostics
}
result.Specs = specsList
return &result, nil
}
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
}