How to take some data which contains valid Elixir code format and execute it as Elixir code?

Do you mean you want to implement Plugin/Pipeline pattern? in which a set of Plugin/Pipeline can be arranged customly by client to produce a particular workflow? in Elixir there’s a lot of inspiration for this pattern, like Plug v1.20.2 — Documentation or internals of Overview — absinthe v1.11.0.

At it’s core, most plugin pattern in elixir usually:

  1. Define individual plugin as module
  2. arrange steps of plugin in a list
  3. Have a set of helper function for handling context of execution

Then you could execute the list of plugin by repeatedly calling apply on them.

Example of simple plugin pattern

defmodule GenerateRandomString do
  def call(execution_context, opts) do
    put_execution_context(execution_context, :random_string, some_random_string)
  end
end

defmodule CreateResourceGroup do
  def call(execution_context, opts) do
    ... do something here
  end
end

def execute_workflow(workflow) do
  context = new_execution_context()
  Enum.reduce(workflow, context, fn {module, opts}, context ->
    apply(module, :call, [context, opts])
  end)
end

workflow = [
  {GenerateRandomString, []},
  {CreateResourceGroup, [namespace: "dev"]}
]

execute_workflow(workflow)

# Unwrapped of execute_workflow, for step by step visualisation
# context = new_execution_context()
# context = GenerateRandomString.call(context, [])
# context = CreateResourceGroup.call(context, [namespace: dev])