aws / ec2-image-builder-roadmap

Public Roadmap for EC2 Image Builder.
Other
34 stars 7 forks source link

[Image Builder] [AWSTOE]: Add conditional operators for recipes #95

Open tiilikainen opened 6 months ago

tiilikainen commented 6 months ago

Community Note

Tell us about your request I would like conditional operators to be added to recipes (similar, perhaps, to how if statements work in the new Image Workflow resource).

Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard? I am trying to reduce the amount of ExecuteBash module calls being used in our AWSTOE documents. Currently, any time there is any sort of conditional logic required in our component, we have to resort to implementing that block of code as pure Bash instead of AWSTOE module calls.

Unless this feature is implemented, we are largely blocked from reimplementing our components in AWSTOE, and we are unable to modularize our code (e.g. extract and reuse common functionality).

Unfortunately, the new Image Workflow functionality is not usable for this use case because it will only execute an entire recipe as written (i.e. you cannot inject conditional logic into the middle of recipe execution).

Are you currently working around this issue? Right now, every single one of our component documents contains only one step. The rest of the logic is expressed in an external Bash script.

Below is an example of a complete component that we are currently using.

name: LinuxServices
description: Install linux services
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: ExecuteServicesScript
        action: ExecuteBash
        inputs:
         commands:
          - |
            . ./set-environment-variables.sh
            sudo -E bash setup-services.sh

Our first component downloads our bash scripts, and the subsequent components just execute them in sequence.

Additional context We build over 60 different images, and our pre-Image Builder code base consists of these Bash scripts that are being called by the newer components. We would eventually like to do away with these Bash scripts without increasing the amount of time it takes to maintain the actual code.