mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
2b4d030a69
Providers were not strict (and were not forced to be) about customizing the diff when a computed attribute needed to be updated during apply. The fix we have in place to prevent loss of information during the helper/schema apply process would add in single missing value back in. The first place this was caught was when we attempt to fix up the flatmapped attributes. The 1->0 count error is now better handled by our cty.Value normalization step, so we can remove the special apply case here altogether The next place is in normalizeNullValues, and since the intent was to re-insert missing zero-value lists and sets, adding a check for a length of 0 protects us from adding in extra elements. The new test fixture emulated common provider behavior of re-computing values without customizing the diff. Since we can work around it, and core will provider appropriate warnings, the shims should try to maintain the legacy behavior.
115 lines
2.6 KiB
Go
115 lines
2.6 KiB
Go
package test
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
)
|
|
|
|
func testResourceList() *schema.Resource {
|
|
return &schema.Resource{
|
|
Create: testResourceListCreate,
|
|
Read: testResourceListRead,
|
|
Update: testResourceListUpdate,
|
|
Delete: testResourceListDelete,
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
"list_block": {
|
|
Type: schema.TypeList,
|
|
Optional: true,
|
|
Elem: &schema.Resource{
|
|
Schema: map[string]*schema.Schema{
|
|
"string": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
},
|
|
"int": {
|
|
Type: schema.TypeInt,
|
|
Optional: true,
|
|
},
|
|
"force_new": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
ForceNew: true,
|
|
},
|
|
"sublist": {
|
|
Type: schema.TypeList,
|
|
Optional: true,
|
|
Elem: &schema.Schema{
|
|
Type: schema.TypeString,
|
|
},
|
|
},
|
|
"sublist_block": {
|
|
Type: schema.TypeList,
|
|
Optional: true,
|
|
Computed: true,
|
|
ForceNew: true,
|
|
Elem: &schema.Resource{
|
|
Schema: map[string]*schema.Schema{
|
|
"string": {
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
},
|
|
"int": {
|
|
Type: schema.TypeInt,
|
|
Required: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"dependent_list": {
|
|
Type: schema.TypeList,
|
|
Optional: true,
|
|
Elem: &schema.Resource{
|
|
Schema: map[string]*schema.Schema{
|
|
"val": {
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"computed_list": {
|
|
Type: schema.TypeList,
|
|
Computed: true,
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func testResourceListCreate(d *schema.ResourceData, meta interface{}) error {
|
|
d.SetId("testId")
|
|
return testResourceListRead(d, meta)
|
|
}
|
|
|
|
func testResourceListRead(d *schema.ResourceData, meta interface{}) error {
|
|
fixedIps := d.Get("dependent_list")
|
|
|
|
// all_fixed_ips should be set as computed with a CustomizeDiff func, but
|
|
// we're trying to emulate legacy provider behavior, and updating a
|
|
// computed field was a common case.
|
|
ips := []interface{}{}
|
|
if fixedIps != nil {
|
|
for _, v := range fixedIps.([]interface{}) {
|
|
m := v.(map[string]interface{})
|
|
ips = append(ips, m["val"])
|
|
}
|
|
}
|
|
if err := d.Set("computed_list", ips); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testResourceListUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
return testResourceListRead(d, meta)
|
|
}
|
|
|
|
func testResourceListDelete(d *schema.ResourceData, meta interface{}) error {
|
|
d.SetId("")
|
|
return nil
|
|
}
|