/
shared.go
66 lines (62 loc) · 1.85 KB
/
shared.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
66
package db
import (
"context"
"errors"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vk-cs/terraform-provider-vkcs/vkcs/internal/util"
)
func resourceDatabaseCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
if diff.Id() != "" && diff.HasChange("cloud_monitoring_enabled") {
t, exists := diff.GetOk("datastore.0.type")
if !exists {
return errors.New("datastore.0.type is not found")
}
if exists && util.IsOperationNotSupported(t.(string), Redis, MongoDB) {
return diff.ForceNew("cloud_monitoring_enabled")
}
}
return nil
}
func checkDBNetworks(
rawNetworks []interface{}, path cty.Path, diags diag.Diagnostics,
) diag.Diagnostics {
if len(rawNetworks) < 2 {
return diags
}
p := path
p = append(p,
cty.GetAttrStep{Name: "network"},
cty.IndexStep{Key: cty.NumberIntVal(1)},
)
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Multiple networks are deprecated",
Detail: "Multiple networks are deprecated and won't be supported in next major release.",
AttributePath: p,
})
hasNetWithSecGroup := -1
for i, n := range rawNetworks {
rawNetwork := n.(map[string]interface{})
if rawNetwork["security_groups"] != nil {
if hasNetWithSecGroup < 0 {
hasNetWithSecGroup = i
continue
}
p := path
p = append(p,
cty.GetAttrStep{Name: "network"},
cty.IndexStep{Key: cty.NumberIntVal(int64(hasNetWithSecGroup))},
cty.GetAttrStep{Name: "security_groups"},
)
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Argument \"security_group\" is ignored",
Detail: "Argument \"security_group\" is overwritten by the last occurrence.",
AttributePath: p,
})
}
}
return diags
}