Skip to content

Commit

Permalink
r/virtual_machine: Update clone import test to properly reflect state
Browse files Browse the repository at this point in the history
ImportStateVerify does not fully simulate an import from scratch. This
means that we can't properly test if imported is being properly checked,
reverted, and passing the clone sub-resource through unless we hack the
state ourselves, which we do by adding another test step.
  • Loading branch information
vancluever committed Apr 9, 2018
1 parent e857920 commit 597d11f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions vsphere/resource_vsphere_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,39 @@ func TestAccResourceVSphereVirtualMachine_importClone(t *testing.T) {
testAccResourceVSphereVirtualMachineCheckExists(true),
),
},
{
Config: testAccResourceVSphereVirtualMachineConfigClone(),
Check: resource.ComposeTestCheckFunc(
testAccResourceVSphereVirtualMachineCheckExists(true),
func(s *terraform.State) error {
// This simulates an import scenario, as ImportStateVerify does not
// actually do a full TF run after import, and hence the above import
// check does not actually test to see Terraform will be able to
// plan. Hence we actually remove the clone configuration from the
// state and ensure that imported is flagged. This allows the next
// step to properly simulate the post-imported state.
rs, ok := s.RootModule().Resources["vsphere_virtual_machine.vm"]
if !ok {
return errors.New("vsphere_virtual_machine.vm not found in state")
}
for k := range rs.Primary.Attributes {
if strings.HasPrefix(k, "clone") {
delete(rs.Primary.Attributes, k)
}
}
rs.Primary.Attributes["imported"] = "true"

return nil
},
),
ExpectNonEmptyPlan: true,
},
{
Config: testAccResourceVSphereVirtualMachineConfigClone(),
Check: resource.ComposeTestCheckFunc(
testAccResourceVSphereVirtualMachineCheckExists(true),
),
},
},
})
}
Expand Down

0 comments on commit 597d11f

Please sign in to comment.