mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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
|
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
|
// Get a diff from the newest state
|
||||||
diff, err := r.Provider.Diff(newState, r.Config)
|
diff, err := r.Provider.Diff(newState, r.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -375,11 +375,31 @@ func TestTerraformPlan_providerInit(t *testing.T) {
|
|||||||
if !p.ConfigureCalled {
|
if !p.ConfigureCalled {
|
||||||
t.Fatal("configure should be called")
|
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)
|
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 {
|
func testConfig(t *testing.T, name string) *config.Config {
|
||||||
c, err := config.Load(filepath.Join(fixtureDir, name, "main.tf"))
|
c, err := config.Load(filepath.Join(fixtureDir, name, "main.tf"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -484,6 +504,10 @@ func testProviderFunc(n string, rs []string) ResourceProviderFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refreshFn := func(s *ResourceState) (*ResourceState, error) {
|
refreshFn := func(s *ResourceState) (*ResourceState, error) {
|
||||||
|
if _, ok := s.Attributes["nil"]; ok {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user