QQ, is there any reason I should not set variables...
# general
m
QQ, is there any reason I should not set variables in an apply block that were defined outside of the apply block?
Copy code
let foundVPC = false;

  let vpcId = getVpcsOutput({ filters }).apply((list: GetVpcsResult) => {
    if (list.ids.length > 0) {
      foundJumpVPC = true;
      return vpc;
    } else {
      <http://log.info|log.info>("No VPC found. Skipping...");
      return undefined;
    }
  });

  if(!foundJumpVPC) {
    <http://log.info|log.info>("No VPC found. Skipping...");
    return;
  }
The reason I need to do this is because I can't do something like:
if(!vpcId)
because
vpcId
is of type
Output<string | undefined>
and this condition
if(!vpcId)
will always evaluate to true.
d
The
apply
won't run until after the whole file has run. There should be a
getVpcs
that can be used for this though, provided
filters
doesn't need to be an Output
m
The
apply
won't run until after the whole file has run.
Ah so not a good idea.
The only issue is, I find that the async code doesn't play well in TS constructors.
d
Could Promise.resolve work here?
m
is that blocking?
Oh no, I don't think that works 😞 I don't resolve the promise, something internally will resolve it when
getVpcs
completes.