getClusterSnapshot function
Future<GetClusterSnapshotResult>
getClusterSnapshot(
- GetClusterSnapshotArgs args, {
- InvokeOptions? options,
Use this data source to get information about a DB Cluster Snapshot for use when provisioning DB clusters.
> NOTE: This data source does not apply to snapshots created on DB Instances.
See the aws.rds.Snapshot data source for DB Instance snapshots.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const developmentFinalSnapshot = aws.rds.getClusterSnapshot({
dbClusterIdentifier: "development_cluster",
mostRecent: true,
});
// Use the last snapshot of the dev database before it was destroyed to create
// a new dev database.
const aurora = new aws.rds.Cluster("aurora", {
clusterIdentifier: "development_cluster",
snapshotIdentifier: developmentFinalSnapshot.then(developmentFinalSnapshot => developmentFinalSnapshot.id),
dbSubnetGroupName: "my_db_subnet_group",
}, {
ignoreChanges: ["snapshotIdentifier"],
});
const auroraClusterInstance = new aws.rds.ClusterInstance("aurora", {
clusterIdentifier: aurora.id,
instanceClass: aws.rds.InstanceType.T2_Small,
dbSubnetGroupName: "my_db_subnet_group",
});
import pulumi
import pulumi_aws as aws
development_final_snapshot = aws.rds.get_cluster_snapshot(db_cluster_identifier="development_cluster",
most_recent=True)
# Use the last snapshot of the dev database before it was destroyed to create
# a new dev database.
aurora = aws.rds.Cluster("aurora",
cluster_identifier="development_cluster",
snapshot_identifier=development_final_snapshot.id,
db_subnet_group_name="my_db_subnet_group",
opts = pulumi.ResourceOptions(ignore_changes=["snapshotIdentifier"]))
aurora_cluster_instance = aws.rds.ClusterInstance("aurora",
cluster_identifier=aurora.id,
instance_class=aws.rds.InstanceType.T2_SMALL,
db_subnet_group_name="my_db_subnet_group")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var developmentFinalSnapshot = Aws.Rds.GetClusterSnapshot.Invoke(new()
{
DbClusterIdentifier = "development_cluster",
MostRecent = true,
});
// Use the last snapshot of the dev database before it was destroyed to create
// a new dev database.
var aurora = new Aws.Rds.Cluster("aurora", new()
{
ClusterIdentifier = "development_cluster",
SnapshotIdentifier = developmentFinalSnapshot.Apply(getClusterSnapshotResult => getClusterSnapshotResult.Id),
DbSubnetGroupName = "my_db_subnet_group",
}, new CustomResourceOptions
{
IgnoreChanges =
{
"snapshotIdentifier",
},
});
var auroraClusterInstance = new Aws.Rds.ClusterInstance("aurora", new()
{
ClusterIdentifier = aurora.Id,
InstanceClass = Aws.Rds.InstanceType.T2_Small,
DbSubnetGroupName = "my_db_subnet_group",
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/rds"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
developmentFinalSnapshot, err := rds.LookupClusterSnapshot(ctx, &rds.LookupClusterSnapshotArgs{
DbClusterIdentifier: pulumi.StringRef("development_cluster"),
MostRecent: pulumi.BoolRef(true),
}, nil)
if err != nil {
return err
}
// Use the last snapshot of the dev database before it was destroyed to create
// a new dev database.
aurora, err := rds.NewCluster(ctx, "aurora", &rds.ClusterArgs{
ClusterIdentifier: pulumi.String("development_cluster"),
SnapshotIdentifier: pulumi.String(developmentFinalSnapshot.Id),
DbSubnetGroupName: pulumi.String("my_db_subnet_group"),
}, pulumi.IgnoreChanges([]string{
"snapshotIdentifier",
}))
if err != nil {
return err
}
_, err = rds.NewClusterInstance(ctx, "aurora", &rds.ClusterInstanceArgs{
ClusterIdentifier: aurora.ID().ToIDOutput().ToStringOutput(),
InstanceClass: pulumi.String(rds.InstanceType_T2_Small),
DbSubnetGroupName: pulumi.String("my_db_subnet_group"),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
data "aws_rds_getclustersnapshot" "developmentFinalSnapshot" {
db_cluster_identifier = "development_cluster"
most_recent = true
}
# Use the last snapshot of the dev database before it was destroyed to create
# a new dev database.
resource "aws_rds_cluster" "aurora" {
lifecycle {
ignore_changes = [snapshotIdentifier]
}
cluster_identifier = "development_cluster"
snapshot_identifier = data.aws_rds_getclustersnapshot.developmentFinalSnapshot.id
db_subnet_group_name = "my_db_subnet_group"
}
resource "aws_rds_clusterinstance" "aurora" {
cluster_identifier = aws_rds_cluster.aurora.id
instance_class = "db.t2.small"
db_subnet_group_name = "my_db_subnet_group"
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.rds.RdsFunctions;
import com.pulumi.aws.rds.inputs.GetClusterSnapshotArgs;
import com.pulumi.aws.rds.Cluster;
import com.pulumi.aws.rds.ClusterArgs;
import com.pulumi.aws.rds.ClusterInstance;
import com.pulumi.aws.rds.ClusterInstanceArgs;
import com.pulumi.resources.CustomResourceOptions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var developmentFinalSnapshot = RdsFunctions.getClusterSnapshot(GetClusterSnapshotArgs.builder()
.dbClusterIdentifier("development_cluster")
.mostRecent(true)
.build());
// Use the last snapshot of the dev database before it was destroyed to create
// a new dev database.
var aurora = new Cluster("aurora", ClusterArgs.builder()
.clusterIdentifier("development_cluster")
.snapshotIdentifier(developmentFinalSnapshot.id())
.dbSubnetGroupName("my_db_subnet_group")
.build(), CustomResourceOptions.builder()
.ignoreChanges("snapshotIdentifier")
.build());
var auroraClusterInstance = new ClusterInstance("auroraClusterInstance", ClusterInstanceArgs.builder()
.clusterIdentifier(aurora.id())
.instanceClass("db.t2.small")
.dbSubnetGroupName("my_db_subnet_group")
.build());
}
}
resources:
# Use the last snapshot of the dev database before it was destroyed to create
# a new dev database.
aurora:
type: aws:rds:Cluster
properties:
clusterIdentifier: development_cluster
snapshotIdentifier: ${developmentFinalSnapshot.id}
dbSubnetGroupName: my_db_subnet_group
options:
ignoreChanges:
- snapshotIdentifier
auroraClusterInstance:
type: aws:rds:ClusterInstance
name: aurora
properties:
clusterIdentifier: ${aurora.id}
instanceClass: db.t2.small
dbSubnetGroupName: my_db_subnet_group
variables:
developmentFinalSnapshot:
fn::invoke:
function: aws:rds:getClusterSnapshot
arguments:
dbClusterIdentifier: development_cluster
mostRecent: true
args Arguments passed to this invoke. Arguments for getClusterSnapshot.
options Invoke options controlling this call.
Implementation
Future<GetClusterSnapshotResult> getClusterSnapshot(
GetClusterSnapshotArgs args, {
pulumi.InvokeOptions? options,
}) async {
final deployment = pulumi.Deployment.instance;
final result = await deployment.invoke<Map<String, dynamic>>(
'aws:rds/getClusterSnapshot:getClusterSnapshot',
args.toMap(),
options: pulumi.toDeploymentInvokeOptions(options),
);
return GetClusterSnapshotResult.fromMap(result);
}