Skip to content

[FEATURE] Implement Conditional Resource Evaluation #51

Closed
@jeffreyaven

Description

@jeffreyaven

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions