Skip to content

Data Source: awsDbSnapshot

Use this data source to get information about a DB Snapshot for use when provisioning DB instances

\~> NOTE: This data source does not apply to snapshots created on Aurora DB clusters. See the awsDbClusterSnapshot data source for DB Cluster snapshots.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsDbInstanceProd = new aws.dbInstance.DbInstance(this, "prod", {
  allocatedStorage: 10,
  dbSubnetGroupName: "my_database_subnet_group",
  engine: "mysql",
  engineVersion: "5.6.17",
  instanceClass: "db.t2.micro",
  name: "mydb",
  parameterGroupName: "default.mysql5.6",
  password: "bar",
  username: "foo",
});
const dataAwsDbSnapshotLatestProdSnapshot =
  new aws.dataAwsDbSnapshot.DataAwsDbSnapshot(this, "latest_prod_snapshot", {
    dbInstanceIdentifier: awsDbInstanceProd.id,
    mostRecent: true,
  });
const awsDbInstanceDev = new aws.dbInstance.DbInstance(this, "dev", {
  instanceClass: "db.t2.micro",
  name: "mydbdev",
  snapshotIdentifier: dataAwsDbSnapshotLatestProdSnapshot.id,
});
awsDbInstanceDev.addOverride("lifecycle", [
  {
    ignore_changes: ["${snapshot_identifier}"],
  },
]);

Argument Reference

\~> NOTE: One of either dbInstanceIdentifier or dbSnapshotIdentifier is required.

The following arguments are supported:

  • mostRecent - (Optional) If more than one result is returned, use the most recent Snapshot.

  • dbInstanceIdentifier - (Optional) Returns the list of snapshots created by the specific db_instance

  • dbSnapshotIdentifier - (Optional) Returns information on a specific snapshot_id.

  • snapshotType - (Optional) Type of snapshots to be returned. If you don't specify a SnapshotType value, then both automated and manual snapshots are returned. Shared and public DB snapshots are not included in the returned results by default. Possible values are, automated, manual, shared, public and awsbackup.

  • includeShared - (Optional) Set this value to true to include shared manual DB snapshots from other AWS accounts that this AWS account has been given permission to copy or restore, otherwise set this value to false. The default is false.

  • includePublic - (Optional) Set this value to true to include manual DB snapshots that are public and can be copied or restored by any AWS account, otherwise set this value to false. The default is false.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - Snapshot ID.
  • allocatedStorage - Allocated storage size in gigabytes (GB).
  • availabilityZone - Name of the Availability Zone the DB instance was located in at the time of the DB snapshot.
  • dbSnapshotArn - ARN for the DB snapshot.
  • encrypted - Whether the DB snapshot is encrypted.
  • engine - Name of the database engine.
  • engineVersion - Version of the database engine.
  • iops - Provisioned IOPS (I/O operations per second) value of the DB instance at the time of the snapshot.
  • kmsKeyId - ARN for the KMS encryption key.
  • licenseModel - License model information for the restored DB instance.
  • optionGroupName - Provides the option group name for the DB snapshot.
  • sourceDbSnapshotIdentifier - DB snapshot ARN that the DB snapshot was copied from. It only has value in case of cross customer or cross region copy.
  • sourceRegion - Region that the DB snapshot was created in or copied from.
  • status - Status of this DB snapshot.
  • storageType - Storage type associated with DB snapshot.
  • vpcId - ID of the VPC associated with the DB snapshot.
  • snapshotCreateTime - Provides the time when the snapshot was taken, in Universal Coordinated Time (UTC).