terraform: make sure state is set to something on refresh
This commit is contained in:
parent
391e9fd250
commit
24c9b7c987
|
@ -209,6 +209,11 @@ func (t *Terraform) planWalkFn(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Make sure the state is set to at the very least the empty state
|
||||
if newState == nil {
|
||||
newState = new(ResourceState)
|
||||
}
|
||||
|
||||
// Get a diff from the newest state
|
||||
diff, err := r.Provider.Diff(newState, r.Config)
|
||||
if err != nil {
|
||||
|
|
|
@ -375,11 +375,31 @@ func TestTerraformPlan_providerInit(t *testing.T) {
|
|||
if !p.ConfigureCalled {
|
||||
t.Fatal("configure should be called")
|
||||
}
|
||||
if p.ConfigureConfig.Raw["foo"].(string) != "2" {
|
||||
if p.ConfigureConfig.Config["foo"].(string) != "2" {
|
||||
t.Fatalf("bad: %#v", p.ConfigureConfig)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTerraformPlan_refreshNil(t *testing.T) {
|
||||
tf := testTerraform(t, "plan-nil")
|
||||
|
||||
s := new(State)
|
||||
s.init()
|
||||
s.Resources["aws_instance.foo"] = &ResourceState{
|
||||
Attributes: map[string]string{
|
||||
"nil": "1",
|
||||
},
|
||||
}
|
||||
|
||||
plan, err := tf.Plan(s)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if len(plan.Diff.Resources) != 0 {
|
||||
t.Fatalf("bad: %#v", plan.Diff.Resources)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfig(t *testing.T, name string) *config.Config {
|
||||
c, err := config.Load(filepath.Join(fixtureDir, name, "main.tf"))
|
||||
if err != nil {
|
||||
|
@ -484,6 +504,10 @@ func testProviderFunc(n string, rs []string) ResourceProviderFactory {
|
|||
}
|
||||
|
||||
refreshFn := func(s *ResourceState) (*ResourceState, error) {
|
||||
if _, ok := s.Attributes["nil"]; ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue