Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Implement Conditional Resource Evaluation #51

Open
jeffreyaven opened this issue Dec 21, 2024 · 0 comments
Open

[FEATURE] Implement Conditional Resource Evaluation #51

jeffreyaven opened this issue Dec 21, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@jeffreyaven
Copy link
Member

Feature Description

Introduce an if condition within the resources section of the stackql_manifest.yml file to enable conditional evaluation of resources during deployment. This feature allows users to specify Python expressions that determine whether a resource should be tested, provisioned, or deprovisioned. The expressions can utilize literals (string, boolean, int, etc.) or reference runtime-templated values from other program variables.

Example(s)

Currently, all resources listed in the stackql_manifest.yml are processed unconditionally. This enhancement allows for conditional processing based on specified criteria. For instance:

resources:
  - name: get_transfer_kms_key_id
    if: "environment == 'production'"
    ...

In this example, the get_transfer_kms_key_id resource will only be processed if the environment variable equals 'production'. Similarly:

resources:
  - name: get_transfer_kms_key_id
    if: "some_var == '{{ some_other_var_value }}'"
    ...

Here, the condition compares some_var to the value of some_other_var_value, allowing for dynamic decision-making during deployment.

Possible Approaches or Libraries to Consider

  • Expression Evaluation: Utilize Python's eval() function to evaluate the conditional expressions. Ensure that the evaluation context includes necessary variables and is secured against potential code injection vulnerabilities.

  • Template Rendering: Implement a templating mechanism (e.g., using Jinja2) to resolve variables within expressions before evaluation. This allows for dynamic substitution of values and enhances flexibility.

Additional Context

  • Documentation: Create an if.mdx file in the website/docs/manifest_fields/resources directory, detailing the usage, syntax, and examples of the if condition in resource definitions.

  • Security Considerations: Carefully handle the evaluation of expressions to prevent security risks associated with arbitrary code execution. Implement validation and sanitization of inputs where necessary.

  • Testing: Develop unit and integration tests to verify the correct functionality of the conditional evaluation feature under various scenarios and edge cases.

This enhancement will provide users with greater control and flexibility in managing resource deployments, enabling more dynamic and context-sensitive operations within stackql-deploy.

@jeffreyaven jeffreyaven added the enhancement New feature or request label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants