func testAccCheckRoute53RecordExists(n string) resource.TestCheckFunc {
	return func(s *terraform.State) error {
		conn := testAccProvider.route53
		rs, ok := s.Resources[n]
		if !ok {
			return fmt.Errorf("Not found: %s", n)
		}

		if rs.ID == "" {
			return fmt.Errorf("No hosted zone ID is set")
		}

		parts := strings.Split(rs.ID, "_")
		zone := parts[0]
		name := parts[1]
		rType := parts[2]

		lopts := &route53.ListOpts{Name: name, Type: rType}
		resp, err := conn.ListResourceRecordSets(zone, lopts)
		if err != nil {
			return err
		}
		if len(resp.Records) == 0 {
			return fmt.Errorf("Record does not exist")
		}
		rec := resp.Records[0]
		if route53.FQDN(rec.Name) == route53.FQDN(name) && rec.Type == rType {
			return nil
		}
		return fmt.Errorf("Record does not exist: %#v", rec)
	}
}
func resource_aws_r53_record_refresh(
	s *terraform.ResourceState,
	meta interface{}) (*terraform.ResourceState, error) {
	p := meta.(*ResourceProvider)
	conn := p.route53

	zone := s.Attributes["zone_id"]
	lopts := &route53.ListOpts{
		Name: s.Attributes["name"],
		Type: s.Attributes["type"],
	}
	resp, err := conn.ListResourceRecordSets(zone, lopts)
	if err != nil {
		return s, err
	}

	// Scan for a matching record
	found := false
	for _, record := range resp.Records {
		if route53.FQDN(record.Name) != route53.FQDN(lopts.Name) {
			continue
		}
		if strings.ToUpper(record.Type) != strings.ToUpper(lopts.Type) {
			continue
		}

		found = true
		resource_aws_r53_record_update_state(s, &record)
		break
	}
	if !found {
		s.ID = ""
	}
	return s, nil
}
func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
	conn := testAccProvider.route53
	for _, rs := range s.Resources {
		if rs.Type != "aws_route53_record" {
			continue
		}

		parts := strings.Split(rs.ID, "_")
		zone := parts[0]
		name := parts[1]
		rType := parts[2]

		lopts := &route53.ListOpts{Name: name, Type: rType}
		resp, err := conn.ListResourceRecordSets(zone, lopts)
		if err != nil {
			return err
		}
		if len(resp.Records) == 0 {
			return nil
		}
		rec := resp.Records[0]
		if route53.FQDN(rec.Name) == route53.FQDN(name) && rec.Type == rType {
			return fmt.Errorf("Record still exists: %#v", rec)
		}
	}
	return nil
}
func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) error {
	conn := meta.(*AWSClient).route53

	zone := d.Get("zone_id").(string)
	lopts := &route53.ListOpts{
		Name: d.Get("name").(string),
		Type: d.Get("type").(string),
	}
	resp, err := conn.ListResourceRecordSets(zone, lopts)
	if err != nil {
		return err
	}

	// Scan for a matching record
	found := false
	for _, record := range resp.Records {
		if route53.FQDN(record.Name) != route53.FQDN(lopts.Name) {
			continue
		}
		if strings.ToUpper(record.Type) != strings.ToUpper(lopts.Type) {
			continue
		}

		found = true

		d.Set("records", record.Records)
		d.Set("ttl", record.TTL)

		break
	}

	if !found {
		d.SetId("")
	}

	return nil
}