helper/schema: cleaner way to store Ephemeral
This commit is contained in:
parent
45c3fd58d8
commit
1685054a9a
|
@ -213,3 +213,7 @@ func (p *Provider) Resources() []terraform.ResourceType {
|
|||
|
||||
return result
|
||||
}
|
||||
|
||||
func (p *Provider) ImportState(info *terraform.InstanceInfo) ([]*terraform.InstanceState, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -221,6 +221,13 @@ func (d *ResourceData) SetConnInfo(v map[string]string) {
|
|||
d.newState.Ephemeral.ConnInfo = v
|
||||
}
|
||||
|
||||
// SetType sets the ephemeral type for the data. This is only required
|
||||
// for importing.
|
||||
func (d *ResourceData) SetType(t string) {
|
||||
d.once.Do(d.init)
|
||||
d.newState.Ephemeral.Type = t
|
||||
}
|
||||
|
||||
// State returns the new InstanceState after the diff and any Set
|
||||
// calls.
|
||||
func (d *ResourceData) State() *terraform.InstanceState {
|
||||
|
@ -260,7 +267,9 @@ func (d *ResourceData) State() *terraform.InstanceState {
|
|||
}
|
||||
|
||||
result.Attributes = mapW.Map()
|
||||
result.Ephemeral.ConnInfo = d.ConnInfo()
|
||||
if d.newState != nil {
|
||||
result.Ephemeral = d.newState.Ephemeral
|
||||
}
|
||||
|
||||
// TODO: This is hacky and we can remove this when we have a proper
|
||||
// state writer. We should instead have a proper StateFieldWriter
|
||||
|
@ -286,7 +295,7 @@ func (d *ResourceData) init() {
|
|||
// Initialize the field that will store our new state
|
||||
var copyState terraform.InstanceState
|
||||
if d.state != nil {
|
||||
copyState = *d.state
|
||||
copyState = *d.state.DeepCopy()
|
||||
}
|
||||
d.newState = ©State
|
||||
|
||||
|
|
|
@ -2930,6 +2930,17 @@ func TestResourceDataSetId_override(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestResourceDataSetType(t *testing.T) {
|
||||
d := &ResourceData{}
|
||||
d.SetId("foo")
|
||||
d.SetType("bar")
|
||||
|
||||
actual := d.State()
|
||||
if v := actual.Ephemeral.Type; v != "bar" {
|
||||
t.Fatalf("bad: %#v", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func testPtrTo(raw interface{}) interface{} {
|
||||
return &raw
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue