mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-20 11:48:24 -06:00
Due to the lossiness of our legacy models for diff and state, shimming a diff and then creating a state from it produces a different result than shimming a state directly. That means that ImportStateVerify no longer works as expected if there are any Computed attributes in the schema where d.Set isn't called during Read. Fixing that for every case would require some risky changes to the shim behavior, so we're instead going to ask provider developers to address it by adding `d.Set` calls where needed, since that is the contract for "Computed" anyway -- a default value should be produced during Create, and thus by extension during Import. However, since a common situation where this occurs is attributes marked as "Removed", since all of the code that deals with them has generally been deleted, we'll avoid problems in that case here by treating Removed attributes as ignored for the purposes of ImportStateVerify. This required exporting some functionality that was formerly unexported in helper/schema, but it's a relatively harmless schema introspection function so shouldn't be a big deal to export it.
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package test
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
)
|
|
|
|
func testResourceImportRemoved() *schema.Resource {
|
|
return &schema.Resource{
|
|
Create: testResourceImportRemovedCreate,
|
|
Read: testResourceImportRemovedRead,
|
|
Delete: testResourceImportRemovedDelete,
|
|
Update: testResourceImportRemovedUpdate,
|
|
|
|
Importer: &schema.ResourceImporter{
|
|
State: testResourceImportRemovedImportState,
|
|
},
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
"removed": {
|
|
Type: schema.TypeInt,
|
|
Optional: true,
|
|
Computed: true,
|
|
Removed: "do not use",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func testResourceImportRemovedImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
|
var results []*schema.ResourceData
|
|
|
|
results = append(results, d)
|
|
|
|
{
|
|
other := testResourceDefaults()
|
|
od := other.Data(nil)
|
|
od.SetType("test_resource_import_removed")
|
|
od.SetId("foo")
|
|
results = append(results, od)
|
|
}
|
|
|
|
return results, nil
|
|
}
|
|
|
|
func testResourceImportRemovedCreate(d *schema.ResourceData, meta interface{}) error {
|
|
d.SetId("foo")
|
|
return testResourceImportRemovedRead(d, meta)
|
|
}
|
|
|
|
func testResourceImportRemovedUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
return testResourceImportRemovedRead(d, meta)
|
|
}
|
|
|
|
func testResourceImportRemovedRead(d *schema.ResourceData, meta interface{}) error {
|
|
return nil
|
|
}
|
|
|
|
func testResourceImportRemovedDelete(d *schema.ResourceData, meta interface{}) error {
|
|
return nil
|
|
}
|