-
Notifications
You must be signed in to change notification settings - Fork 3
/
local.go
64 lines (53 loc) · 1.44 KB
/
local.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
package modconfig
import (
"fmt"
"github.com/hashicorp/hcl/v2"
"github.com/turbot/pipe-fittings/schema"
"github.com/turbot/pipe-fittings/utils"
"github.com/zclconf/go-cty/cty"
)
// Local is a struct representing a Local resource
type Local struct {
ModTreeItemImpl
// required to allow partial decoding
Remain hcl.Body `hcl:",remain" json:"-"`
Value cty.Value
metadata *ResourceMetadata //nolint:unused // TODO check this unused variable
}
func NewLocal(name string, val cty.Value, declRange hcl.Range, mod *Mod) *Local {
fullName := fmt.Sprintf("%s.local.%s", mod.ShortName, name)
l := &Local{
Value: val,
ModTreeItemImpl: ModTreeItemImpl{
HclResourceImpl: HclResourceImpl{
ShortName: name,
UnqualifiedName: fmt.Sprintf("local.%s", name),
FullName: fullName,
DeclRange: declRange,
blockType: schema.BlockTypeLocals,
// disable cty serialisation of base properties
disableCtySerialise: true,
},
Mod: mod,
},
}
return l
}
// CtyValue implements CtyValueProvider
func (l *Local) CtyValue() (cty.Value, error) {
return l.Value, nil
}
func (l *Local) Diff(other *Local) *DashboardTreeItemDiffs {
res := &DashboardTreeItemDiffs{
Item: l,
Name: l.Name(),
}
if !utils.SafeStringsEqual(l.FullName, other.FullName) {
res.AddPropertyDiff("Name")
}
if !utils.SafeStringsEqual(l.Value, other.Value) {
res.AddPropertyDiff("Value")
}
res.populateChildDiffs(l, other)
return res
}