mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
helper/schema: make the get API cleaner
This commit is contained in:
parent
3c1b55a75f
commit
d89446391a
@ -102,8 +102,7 @@ func (d *ResourceData) getRaw(key string, level getSource) getResult {
|
|||||||
parts = strings.Split(key, ".")
|
parts = strings.Split(key, ".")
|
||||||
}
|
}
|
||||||
|
|
||||||
schema := &Schema{Type: typeObject, Elem: d.schema}
|
return d.get(parts, level)
|
||||||
return d.get("", parts, schema, level)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasChange returns whether or not the given key has been changed.
|
// HasChange returns whether or not the given key has been changed.
|
||||||
@ -215,7 +214,7 @@ func (d *ResourceData) State() *terraform.InstanceState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raw := d.get(k, nil, nil, source)
|
raw := d.get([]string{k}, source)
|
||||||
rawMap[k] = raw.Value
|
rawMap[k] = raw.Value
|
||||||
if raw.ValueProcessed != nil {
|
if raw.ValueProcessed != nil {
|
||||||
rawMap[k] = raw.ValueProcessed
|
rawMap[k] = raw.ValueProcessed
|
||||||
@ -328,17 +327,12 @@ func (d *ResourceData) getChange(
|
|||||||
parts2 = strings.Split(key, ".")
|
parts2 = strings.Split(key, ".")
|
||||||
}
|
}
|
||||||
|
|
||||||
schema := &Schema{Type: typeObject, Elem: d.schema}
|
o := d.get(parts, oldLevel)
|
||||||
o := d.get("", parts, schema, oldLevel)
|
n := d.get(parts2, newLevel)
|
||||||
n := d.get("", parts2, schema, newLevel)
|
|
||||||
return o, n
|
return o, n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ResourceData) get(
|
func (d *ResourceData) get(addr []string, source getSource) getResult {
|
||||||
k string,
|
|
||||||
parts []string,
|
|
||||||
schema *Schema,
|
|
||||||
source getSource) getResult {
|
|
||||||
d.once.Do(d.init)
|
d.once.Do(d.init)
|
||||||
|
|
||||||
level := "set"
|
level := "set"
|
||||||
@ -357,11 +351,6 @@ func (d *ResourceData) get(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build the address of the key we're looking for and ask the FieldReader
|
// Build the address of the key we're looking for and ask the FieldReader
|
||||||
var addr []string
|
|
||||||
if k != "" {
|
|
||||||
addr = strings.Split(k, ".")
|
|
||||||
}
|
|
||||||
addr = append(addr, parts...)
|
|
||||||
for i, v := range addr {
|
for i, v := range addr {
|
||||||
if v[0] == '~' {
|
if v[0] == '~' {
|
||||||
addr[i] = v[1:]
|
addr[i] = v[1:]
|
||||||
@ -394,6 +383,5 @@ func (d *ResourceData) get(
|
|||||||
ValueProcessed: result.ValueProcessed,
|
ValueProcessed: result.ValueProcessed,
|
||||||
Computed: result.Computed,
|
Computed: result.Computed,
|
||||||
Exists: result.Exists,
|
Exists: result.Exists,
|
||||||
Schema: schema,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user