forked from opentofu/opentofu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.go
136 lines (109 loc) · 3.26 KB
/
check.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package addrs
import "fmt"
// Check is the address of a check block within a module.
//
// For now, checks do not support meta arguments such as "count" or "for_each"
// so this address uniquely describes a single check within a module.
type Check struct {
referenceable
Name string
}
func (c Check) String() string {
return fmt.Sprintf("check.%s", c.Name)
}
// InModule returns a ConfigCheck from the receiver and the given module
// address.
func (c Check) InModule(modAddr Module) ConfigCheck {
return ConfigCheck{
Module: modAddr,
Check: c,
}
}
// Absolute returns an AbsCheck from the receiver and the given module instance
// address.
func (c Check) Absolute(modAddr ModuleInstance) AbsCheck {
return AbsCheck{
Module: modAddr,
Check: c,
}
}
func (c Check) Equal(o Check) bool {
return c.Name == o.Name
}
func (c Check) UniqueKey() UniqueKey {
return c // A Check is its own UniqueKey
}
func (c Check) uniqueKeySigil() {}
// ConfigCheck is an address for a check block within a configuration.
//
// This contains a Check address and a Module address, meaning this describes
// a check block within the entire configuration.
type ConfigCheck struct {
Module Module
Check Check
}
var _ ConfigCheckable = ConfigCheck{}
func (c ConfigCheck) UniqueKey() UniqueKey {
return configCheckUniqueKey(c.String())
}
func (c ConfigCheck) configCheckableSigil() {}
func (c ConfigCheck) CheckableKind() CheckableKind {
return CheckableCheck
}
func (c ConfigCheck) String() string {
if len(c.Module) == 0 {
return c.Check.String()
}
return fmt.Sprintf("%s.%s", c.Module, c.Check)
}
// AbsCheck is an absolute address for a check block under a given module path.
//
// This contains an actual ModuleInstance address (compared to the Module within
// a ConfigCheck), meaning this uniquely describes a check block within the
// entire configuration after any "count" or "foreach" meta arguments have been
// evaluated on the containing module.
type AbsCheck struct {
Module ModuleInstance
Check Check
}
var _ Checkable = AbsCheck{}
func (c AbsCheck) UniqueKey() UniqueKey {
return absCheckUniqueKey(c.String())
}
func (c AbsCheck) checkableSigil() {}
// CheckRule returns an address for a given rule type within the check block.
//
// There will be at most one CheckDataResource rule within a check block (with
// an index of 0). There will be at least one, but potentially many,
// CheckAssertion rules within a check block.
func (c AbsCheck) CheckRule(typ CheckRuleType, i int) CheckRule {
return CheckRule{
Container: c,
Type: typ,
Index: i,
}
}
// ConfigCheckable returns the ConfigCheck address for this absolute reference.
func (c AbsCheck) ConfigCheckable() ConfigCheckable {
return ConfigCheck{
Module: c.Module.Module(),
Check: c.Check,
}
}
func (c AbsCheck) CheckableKind() CheckableKind {
return CheckableCheck
}
func (c AbsCheck) String() string {
if len(c.Module) == 0 {
return c.Check.String()
}
return fmt.Sprintf("%s.%s", c.Module, c.Check)
}
type configCheckUniqueKey string
func (k configCheckUniqueKey) uniqueKeySigil() {}
type absCheckUniqueKey string
func (k absCheckUniqueKey) uniqueKeySigil() {}