helper/schema: can set conninfo
This commit is contained in:
parent
2fd2470c92
commit
3d3789920d
|
@ -91,6 +91,19 @@ func (d *ResourceData) Id() string {
|
|||
return result
|
||||
}
|
||||
|
||||
// ConnInfo returns the connection info for this resource.
|
||||
func (d *ResourceData) ConnInfo() map[string]string {
|
||||
if d.newState != nil {
|
||||
return d.newState.ConnInfo
|
||||
}
|
||||
|
||||
if d.state != nil {
|
||||
return d.state.ConnInfo
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dependencies returns the dependencies in this state.
|
||||
func (d *ResourceData) Dependencies() []terraform.ResourceDependency {
|
||||
if d.newState != nil {
|
||||
|
@ -111,6 +124,12 @@ func (d *ResourceData) SetId(v string) {
|
|||
d.newState.ID = v
|
||||
}
|
||||
|
||||
// SetConnInfo sets the connection info for a resource.
|
||||
func (d *ResourceData) SetConnInfo(v map[string]string) {
|
||||
d.once.Do(d.init)
|
||||
d.newState.ConnInfo = v
|
||||
}
|
||||
|
||||
// SetDependencies sets the dependencies of a resource.
|
||||
func (d *ResourceData) SetDependencies(ds []terraform.ResourceDependency) {
|
||||
d.once.Do(d.init)
|
||||
|
@ -123,6 +142,7 @@ func (d *ResourceData) State() *terraform.ResourceState {
|
|||
var result terraform.ResourceState
|
||||
result.ID = d.Id()
|
||||
result.Attributes = d.stateObject("", d.schema)
|
||||
result.ConnInfo = d.ConnInfo()
|
||||
result.Dependencies = d.Dependencies()
|
||||
|
||||
if v := d.Id(); v != "" {
|
||||
|
|
|
@ -1531,6 +1531,22 @@ func TestResourceDataState(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestResourceDataSetConnInfo(t *testing.T) {
|
||||
d := &ResourceData{}
|
||||
d.SetConnInfo(map[string]string{
|
||||
"foo": "bar",
|
||||
})
|
||||
|
||||
expected := map[string]string{
|
||||
"foo": "bar",
|
||||
}
|
||||
|
||||
actual := d.State()
|
||||
if !reflect.DeepEqual(actual.ConnInfo, expected) {
|
||||
t.Fatalf("bad: %#v", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceDataSetDependencies(t *testing.T) {
|
||||
d := &ResourceData{}
|
||||
d.SetDependencies([]terraform.ResourceDependency{
|
||||
|
|
Loading…
Reference in New Issue