예제 #1
0
func resource_aws_db_instance_destroy(
	s *terraform.ResourceState,
	meta interface{}) error {
	p := meta.(*ResourceProvider)
	conn := p.rdsconn

	log.Printf("[DEBUG] DB Instance destroy: %v", s.ID)

	opts := rds.DeleteDBInstance{DBInstanceIdentifier: s.ID}

	if s.Attributes["skip_final_snapshot"] == "true" {
		opts.SkipFinalSnapshot = true
	}

	log.Printf("[DEBUG] DB Instance destroy configuration: %v", opts)
	_, err := conn.DeleteDBInstance(&opts)

	if err != nil {
		newerr, ok := err.(*rds.Error)
		if ok && newerr.Code == "InvalidDBInstance.NotFound" {
			return nil
		}
		return err
	}

	return nil
}
func resourceAwsDbInstanceDelete(d *schema.ResourceData, meta interface{}) error {
	conn := meta.(*AWSClient).rdsconn

	log.Printf("[DEBUG] DB Instance destroy: %v", d.Id())

	opts := rds.DeleteDBInstance{DBInstanceIdentifier: d.Id()}

	if d.Get("skip_final_snapshot").(bool) {
		opts.SkipFinalSnapshot = true
	} else {
		opts.FinalDBSnapshotIdentifier = d.Get("final_snapshot_identifier").(string)
	}

	log.Printf("[DEBUG] DB Instance destroy configuration: %v", opts)
	if _, err := conn.DeleteDBInstance(&opts); err != nil {
		return err
	}

	log.Println(
		"[INFO] Waiting for DB Instance to be destroyed")
	stateConf := &resource.StateChangeConf{
		Pending: []string{"creating", "backing-up",
			"modifying", "deleting", "available"},
		Target:     "",
		Refresh:    resourceAwsDbInstanceStateRefreshFunc(d, meta),
		Timeout:    20 * time.Minute,
		MinTimeout: 10 * time.Second,
		Delay:      30 * time.Second, // Wait 30 secs before starting
	}
	if _, err := stateConf.WaitForState(); err != nil {
		return err
	}

	return nil
}
func resource_aws_db_instance_destroy(
	s *terraform.ResourceState,
	meta interface{}) error {
	p := meta.(*ResourceProvider)
	conn := p.rdsconn

	log.Printf("[DEBUG] DB Instance destroy: %v", s.ID)

	opts := rds.DeleteDBInstance{DBInstanceIdentifier: s.ID}

	if s.Attributes["skip_final_snapshot"] == "true" {
		opts.SkipFinalSnapshot = true
	} else {
		opts.FinalDBSnapshotIdentifier = s.Attributes["final_snapshot_identifier"]
	}

	log.Printf("[DEBUG] DB Instance destroy configuration: %v", opts)
	_, err := conn.DeleteDBInstance(&opts)

	log.Println(
		"[INFO] Waiting for DB Instance to be destroyed")

	stateConf := &resource.StateChangeConf{
		Pending: []string{"creating", "backing-up",
			"modifying", "deleting", "available"},
		Target:     "",
		Refresh:    DBInstanceStateRefreshFunc(s.ID, conn),
		Timeout:    10 * time.Minute,
		MinTimeout: 10 * time.Second,
		Delay:      30 * time.Second, // Wait 30 secs before starting
	}

	// Wait, catching any errors
	_, err = stateConf.WaitForState()
	if err != nil {
		return err
	}

	return nil
}