arabold / serverless-export-env

Serverless plugin to export environment variables into a .env file
MIT License
103 stars 34 forks source link

feat: set resource values from stack output #23

Closed andersquist closed 4 years ago

andersquist commented 4 years ago

This is a proposal for a fix for the following use case as mentioned in https://github.com/arabold/serverless-export-env/issues/21 .

Let's say we have something like this in the Resource section of a serverless.yml:

resources:
  Resources:
   SNSSomethingNotificationTopic:
      Type: AWS::SNS::Topic

  Outputs:
    SNSSomethingNotificationTopicName:
      Value: !GetAtt SNSSomethingNotificationTopic.TopicName

Then the SNSSomethingNotificationTopicName would not get resolved to the actual value but instead a JSON object containing something this after the call to collectResourceOutputs:

{ 'Fn::GetAtt': [ 'SNSSomethingNotificationTopic', 'TopicName' ] }

Which when it gets written to the .env file becomes SNS_NOTIFICATION_TOPIC_NAME: [object Object]

It would seem that the computed value is not fetched when the stack is created or updated for this kind of use case so in short my proposal is to try and get the actual stacks output values from AWS and map them to the outputs before using any other values.