https://pulumi.com logo
#typescript
Title
# typescript
d

damp-painting-47843

11/16/2022, 10:25 PM
I’m in a ComponentResource constructor (so no await/async). I’m creating a volume but I conditionally I want to provide an initial snapshot IF the snapshot exists. I’m using aws.ebs.getSnapshot. But that returns a promise. How would I supply a snapshotId to aws.ebs.Volume?
b

billowy-army-68599

11/16/2022, 10:26 PM
there’s
aws.ebs.getSnapshotOutput
if you don’t want to use that, do it inside an
apply
d

damp-painting-47843

11/16/2022, 10:27 PM
But if there’s no output will the volume understand?
Copy code
const volumeName = `${args.instanceData.name}-volume`
  
>>    const foundSnapshot = aws.ebs.getSnapshotOutput({
        filters: [
          {
            name: "tag:Name",
            values: [volumeName],
          },    
        ],      
        mostRecent: true,
        owners: ["self"],
      }));  
    
      const volume = new aws.ebs.Volume(volumeName,  {
        size: args.instanceData.volumeSize,
        availabilityZone: args.instanceData.availabilityZone,
        tags: {
          Name: `${args.instanceData.name}-volume`,
          ProjectIdentifier: "Platform",                                                                                                                                   
          Environment: args.stack
        },
        snapshotId: foundSnapshot    
      },{                                                                                                          
        parent: this                                                                                                                                                       
      });
I.e., will the above work if there’s no snapshot?
b

billowy-army-68599

11/16/2022, 10:31 PM
if the snapshot doesn’t exist in the cloud provider then it’ll fail, if you don’t know if it exists you should create it using a resource
d

damp-painting-47843

11/16/2022, 10:31 PM
In the beginning there may be no snapshot. The snapshot is a final snapshot from a previous destroy.
Basically, I’m trying to say, if it’s never been destroyed before create a new volume, if not create a volume from this snapshot.
Perhaps the solution is to do this outside of the component.
Get the snapshot outside of the component where you can use try / catch and await. And then supply it to the component.
But it would be nice to have it all encapsulated.
b

billowy-army-68599

11/16/2022, 10:34 PM
yeah outside the component is the way to do it, just have the snapshot id as an argument input