remote: Expose delete state

This commit is contained in:
Armon Dadgar 2014-12-04 18:07:05 -08:00 committed by Mitchell Hashimoto
parent 6a182c2684
commit de8ff3b981
2 changed files with 36 additions and 0 deletions

View File

@ -350,6 +350,27 @@ func PushState(conf *terraform.RemoteState, force bool) (StateChangeResult, erro
}
}
// DeleteState is used to delete the remote state given
// the configuration for the remote endpoint.
func DeleteState(conf *terraform.RemoteState) error {
if conf == nil {
return fmt.Errorf("Missing remote server configuration")
}
// Setup the client
client, err := NewClientByState(conf)
if err != nil {
return fmt.Errorf("Failed to create remote client: %v", err)
}
// Destroy the state
err = client.DeleteState()
if err != nil {
return fmt.Errorf("Failed to delete remote state: %v", err)
}
return nil
}
// blankState is used to return a serialized form of a blank state
// with only the remote info.
func blankState(conf *terraform.RemoteState) ([]byte, error) {

View File

@ -287,6 +287,21 @@ func TestPushState_Error(t *testing.T) {
}
}
func TestDeleteState(t *testing.T) {
defer testFixCwd(testDir(t))
remote, srv := testRemotePush(t, 200)
defer srv.Close()
local := terraform.NewState()
testWriteLocal(t, local)
err := DeleteState(remote)
if err != nil {
t.Fatalf("err: %v", err)
}
}
func TestBlankState(t *testing.T) {
remote := &terraform.RemoteState{
Type: "http",