1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package rds
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/aws-sdk-go-v2/service/rds/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// The DeleteDBInstance action deletes a previously provisioned DB instance. When
15// you delete a DB instance, all automated backups for that instance are deleted
16// and can't be recovered. Manual DB snapshots of the DB instance to be deleted by
17// DeleteDBInstance are not deleted. If you request a final DB snapshot the status
18// of the Amazon RDS DB instance is deleting until the DB snapshot is created. The
19// API action DescribeDBInstance is used to monitor the status of this operation.
20// The action can't be canceled or reverted once submitted. When a DB instance is
21// in a failure state and has a status of failed, incompatible-restore, or
22// incompatible-network, you can only delete it when you skip creation of the final
23// snapshot with the SkipFinalSnapshot parameter. If the specified DB instance is
24// part of an Amazon Aurora DB cluster, you can't delete the DB instance if both of
25// the following conditions are true:
26//
27// * The DB cluster is a read replica of
28// another Amazon Aurora DB cluster.
29//
30// * The DB instance is the only instance in the
31// DB cluster.
32//
33// To delete a DB instance in this case, first call the
34// PromoteReadReplicaDBCluster API action to promote the DB cluster so it's no
35// longer a read replica. After the promotion completes, then call the
36// DeleteDBInstance API action to delete the final instance in the DB cluster.
37func (c *Client) DeleteDBInstance(ctx context.Context, params *DeleteDBInstanceInput, optFns ...func(*Options)) (*DeleteDBInstanceOutput, error) {
38	if params == nil {
39		params = &DeleteDBInstanceInput{}
40	}
41
42	result, metadata, err := c.invokeOperation(ctx, "DeleteDBInstance", params, optFns, addOperationDeleteDBInstanceMiddlewares)
43	if err != nil {
44		return nil, err
45	}
46
47	out := result.(*DeleteDBInstanceOutput)
48	out.ResultMetadata = metadata
49	return out, nil
50}
51
52//
53type DeleteDBInstanceInput struct {
54
55	// The DB instance identifier for the DB instance to be deleted. This parameter
56	// isn't case-sensitive. Constraints:
57	//
58	// * Must match the name of an existing DB
59	// instance.
60	//
61	// This member is required.
62	DBInstanceIdentifier *string
63
64	// A value that indicates whether to remove automated backups immediately after the
65	// DB instance is deleted. This parameter isn't case-sensitive. The default is to
66	// remove automated backups immediately after the DB instance is deleted.
67	DeleteAutomatedBackups *bool
68
69	// The DBSnapshotIdentifier of the new DBSnapshot created when the
70	// SkipFinalSnapshot parameter is disabled. Specifying this parameter and also
71	// specifying to skip final DB snapshot creation in SkipFinalShapshot results in an
72	// error. Constraints:
73	//
74	// * Must be 1 to 255 letters or numbers.
75	//
76	// * First character
77	// must be a letter.
78	//
79	// * Can't end with a hyphen or contain two consecutive
80	// hyphens.
81	//
82	// * Can't be specified when deleting a read replica.
83	FinalDBSnapshotIdentifier *string
84
85	// A value that indicates whether to skip the creation of a final DB snapshot
86	// before the DB instance is deleted. If skip is specified, no DB snapshot is
87	// created. If skip isn't specified, a DB snapshot is created before the DB
88	// instance is deleted. By default, skip isn't specified, and the DB snapshot is
89	// created. When a DB instance is in a failure state and has a status of 'failed',
90	// 'incompatible-restore', or 'incompatible-network', it can only be deleted when
91	// skip is specified. Specify skip when deleting a read replica. The
92	// FinalDBSnapshotIdentifier parameter must be specified if skip isn't specified.
93	SkipFinalSnapshot bool
94}
95
96type DeleteDBInstanceOutput struct {
97
98	// Contains the details of an Amazon RDS DB instance. This data type is used as a
99	// response element in the DescribeDBInstances action.
100	DBInstance *types.DBInstance
101
102	// Metadata pertaining to the operation's result.
103	ResultMetadata middleware.Metadata
104}
105
106func addOperationDeleteDBInstanceMiddlewares(stack *middleware.Stack, options Options) (err error) {
107	err = stack.Serialize.Add(&awsAwsquery_serializeOpDeleteDBInstance{}, middleware.After)
108	if err != nil {
109		return err
110	}
111	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpDeleteDBInstance{}, middleware.After)
112	if err != nil {
113		return err
114	}
115	if err = addSetLoggerMiddleware(stack, options); err != nil {
116		return err
117	}
118	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
119		return err
120	}
121	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
122		return err
123	}
124	if err = addResolveEndpointMiddleware(stack, options); err != nil {
125		return err
126	}
127	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
128		return err
129	}
130	if err = addRetryMiddlewares(stack, options); err != nil {
131		return err
132	}
133	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
134		return err
135	}
136	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
137		return err
138	}
139	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
140		return err
141	}
142	if err = addClientUserAgent(stack); err != nil {
143		return err
144	}
145	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
146		return err
147	}
148	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
149		return err
150	}
151	if err = addOpDeleteDBInstanceValidationMiddleware(stack); err != nil {
152		return err
153	}
154	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDeleteDBInstance(options.Region), middleware.Before); err != nil {
155		return err
156	}
157	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
158		return err
159	}
160	if err = addResponseErrorMiddleware(stack); err != nil {
161		return err
162	}
163	if err = addRequestResponseLogging(stack, options); err != nil {
164		return err
165	}
166	return nil
167}
168
169func newServiceMetadataMiddleware_opDeleteDBInstance(region string) *awsmiddleware.RegisterServiceMetadata {
170	return &awsmiddleware.RegisterServiceMetadata{
171		Region:        region,
172		ServiceID:     ServiceID,
173		SigningName:   "rds",
174		OperationName: "DeleteDBInstance",
175	}
176}
177