func testAccCheckBoshStemcellDestroy(resource string, stemcellName string, stemcellVersion string) resource.TestCheckFunc {

	return func(s *terraform.State) error {

		_, ok := s.RootModule().Resources[resource]
		if ok {
			return fmt.Errorf("stemcell resource '%s' still exists in the terraform state", resource)
		}

		var (
			err error

			director *bosh_client.Director
			stemcell *bosh_client.Stemcell
		)

		director, err = GetDirector()
		if err != nil {
			return err
		}

		stemcell, err = director.GetStemcell(stemcellName, stemcellVersion)
		if err != nil {
			return err
		}
		if stemcell != nil {
			return fmt.Errorf("stemcell '%s' version '%s' was not deleted as expected", stemcellName, stemcellVersion)
		}

		return nil
	}
}
func testAccCheckBoshReleaseDestroy(resource string, releaseName string, releaseVersion string) resource.TestCheckFunc {

	return func(s *terraform.State) error {

		_, ok := s.RootModule().Resources[resource]
		if ok {
			return fmt.Errorf("release resource '%s' still exists in the terraform state", resource)
		}

		var (
			err error

			director *bosh_client.Director
			release  *bosh_client.Release
		)

		director, err = GetDirector()
		if err != nil {
			return err
		}

		release, err = director.GetRelease(releaseName, releaseVersion)
		if err != nil {
			return err
		}
		if release != nil {
			return fmt.Errorf("release '%s' version '%s' was not deleted as expected", releaseName, releaseVersion)
		}

		return nil
	}
}
func testAccCheckBoshStemcellExists(resource string) resource.TestCheckFunc {

	return func(s *terraform.State) error {

		var (
			err error

			director *bosh_client.Director
			stemcell *bosh_client.Stemcell
		)

		director, err = GetDirector()
		if err != nil {
			return err
		}

		rs, ok := s.RootModule().Resources[resource]
		if !ok {
			return fmt.Errorf("stemcell resource '%s' not found in terraform state", resource)
		}

		log.Printf("[DEBUG] Resource state: %# v", pretty.Formatter(rs))

		attributes := rs.Primary.Attributes
		stemcell, err = director.GetStemcell(attributes["name"], attributes["version"])
		if err != nil {
			return err
		}
		if stemcell.CID != attributes["cid"] {
			return fmt.Errorf("retrieved stemcell CID '%s' does not match '%s' which is "+
				"the CID of resource state '%s'", stemcell.CID, attributes["cid"], resource)
		}

		return nil
	}
}
func testAccCheckBoshReleaseExists(resource string) resource.TestCheckFunc {

	return func(s *terraform.State) error {

		var (
			err error

			director *bosh_client.Director
			release  *bosh_client.Release
		)

		director, err = GetDirector()
		if err != nil {
			return err
		}

		rs, ok := s.RootModule().Resources[resource]
		if !ok {
			return fmt.Errorf("release resource '%s' not found in terraform state", resource)
		}

		log.Printf("[DEBUG] Resource state: %# v", pretty.Formatter(rs))

		attributes := rs.Primary.Attributes
		release, err = director.GetRelease(attributes["name"], attributes["version"])
		if err != nil {
			return err
		}
		if release.CommitHash != attributes["commit_hash"] {
			return fmt.Errorf("retrieved release commite hash '%s' does not match '%s' which is "+
				"the commit hash of resource state '%s'", release.CommitHash, attributes["commit_hash"], resource)
		}

		return nil
	}
}