terraform: don't refresh resources that aren't created
This commit is contained in:
parent
5b95271819
commit
38b3734d12
|
@ -573,6 +573,10 @@ func (c *Context) refreshWalkFn(result *State) depgraph.WalkFunc {
|
|||
var l sync.Mutex
|
||||
|
||||
cb := func(r *Resource) error {
|
||||
if r.State.ID == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, h := range c.hooks {
|
||||
handleHook(h.PreRefresh(r.Id, r.State))
|
||||
}
|
||||
|
|
|
@ -979,6 +979,14 @@ func TestContextRefresh(t *testing.T) {
|
|||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
State: &State{
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
ID: "foo",
|
||||
Type: "aws_instance",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
p.RefreshFn = nil
|
||||
|
@ -993,7 +1001,7 @@ func TestContextRefresh(t *testing.T) {
|
|||
if !p.RefreshCalled {
|
||||
t.Fatal("refresh should be called")
|
||||
}
|
||||
if p.RefreshState.ID != "" {
|
||||
if p.RefreshState.ID != "foo" {
|
||||
t.Fatalf("bad: %#v", p.RefreshState)
|
||||
}
|
||||
if !reflect.DeepEqual(s.Resources["aws_instance.web"], p.RefreshReturn) {
|
||||
|
@ -1007,6 +1015,31 @@ func TestContextRefresh(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContextRefresh_ignoreUncreated(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
c := testConfig(t, "refresh-basic")
|
||||
ctx := testContext(t, &ContextOpts{
|
||||
Config: c,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
State: nil,
|
||||
})
|
||||
|
||||
p.RefreshFn = nil
|
||||
p.RefreshReturn = &ResourceState{
|
||||
ID: "foo",
|
||||
}
|
||||
|
||||
_, err := ctx.Refresh()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if p.RefreshCalled {
|
||||
t.Fatal("refresh should not be called")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextRefresh_hook(t *testing.T) {
|
||||
h := new(MockHook)
|
||||
p := testProvider("aws")
|
||||
|
@ -1017,6 +1050,14 @@ func TestContextRefresh_hook(t *testing.T) {
|
|||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
State: &State{
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
ID: "foo",
|
||||
Type: "aws_instance",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if _, err := ctx.Refresh(); err != nil {
|
||||
|
|
Loading…
Reference in New Issue