Fixed a type and reordered the case statements
Making in more inline with the existing code…
This commit is contained in:
parent
6a663796d5
commit
40fa6c3aaa
|
@ -113,7 +113,7 @@ func (d *ResourceData) HasChange(key string) bool {
|
|||
return !reflect.DeepEqual(o, n)
|
||||
}
|
||||
|
||||
// hasComputedSubKeys walks true a schema and returns whether or not the
|
||||
// hasComputedSubKeys walks through a schema and returns whether or not the
|
||||
// given key contains any subkeys that are computed.
|
||||
func (d *ResourceData) hasComputedSubKeys(key string, schema *Schema) bool {
|
||||
prefix := key + "."
|
||||
|
@ -430,10 +430,6 @@ func (d *ResourceData) getSet(
|
|||
s.m = make(map[int]interface{})
|
||||
for idx, code := range codes {
|
||||
switch t := schema.Elem.(type) {
|
||||
case *Schema:
|
||||
// Get a single value
|
||||
s.m[code] = d.get(prefix+idx, nil, t, source).Value
|
||||
result.Exists = true
|
||||
case *Resource:
|
||||
// Get the entire object
|
||||
m := make(map[string]interface{})
|
||||
|
@ -442,6 +438,10 @@ func (d *ResourceData) getSet(
|
|||
}
|
||||
s.m[code] = m
|
||||
result.Exists = true
|
||||
case *Schema:
|
||||
// Get a single value
|
||||
s.m[code] = d.get(prefix+idx, nil, t, source).Value
|
||||
result.Exists = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -469,10 +469,10 @@ func (d *ResourceData) getSet(
|
|||
}
|
||||
|
||||
switch t := schema.Elem.(type) {
|
||||
case *Schema:
|
||||
return d.get(prefix+idx, parts, t, source)
|
||||
case *Resource:
|
||||
return d.getObject(prefix+idx, parts, t.Schema, source)
|
||||
case *Schema:
|
||||
return d.get(prefix+idx, parts, t, source)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1043,14 +1043,6 @@ func (d *ResourceData) setSet(
|
|||
}
|
||||
|
||||
switch t := schema.Elem.(type) {
|
||||
case *Schema:
|
||||
for code, elem := range value.(*Set).m {
|
||||
subK := fmt.Sprintf("%s.%d", k, code)
|
||||
err := d.set(subK, nil, t, elem)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case *Resource:
|
||||
for code, elem := range value.(*Set).m {
|
||||
for field, _ := range t.Schema {
|
||||
|
@ -1062,6 +1054,14 @@ func (d *ResourceData) setSet(
|
|||
}
|
||||
}
|
||||
}
|
||||
case *Schema:
|
||||
for code, elem := range value.(*Set).m {
|
||||
subK := fmt.Sprintf("%s.%d", k, code)
|
||||
err := d.set(subK, nil, t, elem)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("%s: unknown element type (internal)", k)
|
||||
}
|
||||
|
@ -1201,10 +1201,10 @@ func (d *ResourceData) stateSet(
|
|||
|
||||
var m map[string]string
|
||||
switch t := schema.Elem.(type) {
|
||||
case *Schema:
|
||||
m = d.stateSingle(key, t)
|
||||
case *Resource:
|
||||
m = d.stateObject(key, t.Schema)
|
||||
case *Schema:
|
||||
m = d.stateSingle(key, t)
|
||||
}
|
||||
|
||||
for k, v := range m {
|
||||
|
|
|
@ -532,6 +532,17 @@ func (m schemaMap) diffList(
|
|||
}
|
||||
|
||||
switch t := schema.Elem.(type) {
|
||||
case *Resource:
|
||||
// This is a complex resource
|
||||
for i := 0; i < maxLen; i++ {
|
||||
for k2, schema := range t.Schema {
|
||||
subK := fmt.Sprintf("%s.%d.%s", k, i, k2)
|
||||
err := m.diff(subK, schema, diff, d, all)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
case *Schema:
|
||||
// Copy the schema so that we can set Computed/ForceNew from
|
||||
// the parent schema (the TypeList).
|
||||
|
@ -547,17 +558,6 @@ func (m schemaMap) diffList(
|
|||
return err
|
||||
}
|
||||
}
|
||||
case *Resource:
|
||||
// This is a complex resource
|
||||
for i := 0; i < maxLen; i++ {
|
||||
for k2, schema := range t.Schema {
|
||||
subK := fmt.Sprintf("%s.%d.%s", k, i, k2)
|
||||
err := m.diff(subK, schema, diff, d, all)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("%s: unknown element type (internal)", k)
|
||||
}
|
||||
|
@ -691,6 +691,16 @@ func (m schemaMap) diffSet(
|
|||
|
||||
for _, code := range ns.listCode() {
|
||||
switch t := schema.Elem.(type) {
|
||||
case *Resource:
|
||||
// This is a complex resource
|
||||
for k2, schema := range t.Schema {
|
||||
subK := fmt.Sprintf("%s.%d.%s", k, code, k2)
|
||||
subK = strings.Replace(subK, "-", "~", -1)
|
||||
err := m.diff(subK, schema, diff, d, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case *Schema:
|
||||
// Copy the schema so that we can set Computed/ForceNew from
|
||||
// the parent schema (the TypeSet).
|
||||
|
@ -705,16 +715,6 @@ func (m schemaMap) diffSet(
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case *Resource:
|
||||
// This is a complex resource
|
||||
for k2, schema := range t.Schema {
|
||||
subK := fmt.Sprintf("%s.%d.%s", k, code, k2)
|
||||
subK = strings.Replace(subK, "-", "~", -1)
|
||||
err := m.diff(subK, schema, diff, d, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("%s: unknown element type (internal)", k)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue