mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-28 09:26:26 -06:00
Add InstanceKey.Value method
Have the InstanceKey implementations handle their own cty.Value conversions.
This commit is contained in:
parent
2a646aba46
commit
8421abaca0
@ -18,6 +18,10 @@ import (
|
|||||||
type InstanceKey interface {
|
type InstanceKey interface {
|
||||||
instanceKeySigil()
|
instanceKeySigil()
|
||||||
String() string
|
String() string
|
||||||
|
|
||||||
|
// Value returns the cty.Value of the appropriate type for the InstanceKey
|
||||||
|
// value.
|
||||||
|
Value() cty.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseInstanceKey returns the instance key corresponding to the given value,
|
// ParseInstanceKey returns the instance key corresponding to the given value,
|
||||||
@ -56,6 +60,10 @@ func (k IntKey) String() string {
|
|||||||
return fmt.Sprintf("[%d]", int(k))
|
return fmt.Sprintf("[%d]", int(k))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (k IntKey) Value() cty.Value {
|
||||||
|
return cty.NumberIntVal(int64(k))
|
||||||
|
}
|
||||||
|
|
||||||
// StringKey is the InstanceKey representation representing string indices, as
|
// StringKey is the InstanceKey representation representing string indices, as
|
||||||
// used when the "for_each" argument is specified with a map or object type.
|
// used when the "for_each" argument is specified with a map or object type.
|
||||||
type StringKey string
|
type StringKey string
|
||||||
@ -69,6 +77,10 @@ func (k StringKey) String() string {
|
|||||||
return fmt.Sprintf("[%q]", string(k))
|
return fmt.Sprintf("[%q]", string(k))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (k StringKey) Value() cty.Value {
|
||||||
|
return cty.StringVal(string(k))
|
||||||
|
}
|
||||||
|
|
||||||
// InstanceKeyLess returns true if the first given instance key i should sort
|
// InstanceKeyLess returns true if the first given instance key i should sort
|
||||||
// before the second key j, and false otherwise.
|
// before the second key j, and false otherwise.
|
||||||
func InstanceKeyLess(i, j InstanceKey) bool {
|
func InstanceKeyLess(i, j InstanceKey) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user