I’m in a ComponentResource constructor (so no awai...
# typescript
d
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
there’s
aws.ebs.getSnapshotOutput
if you don’t want to use that, do it inside an
apply
d
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
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
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
yeah outside the component is the way to do it, just have the snapshot id as an argument input