Move cirrus definitions to YAML files #93
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Inputs to the task-batch-compute, task, and workflow submodules are now configured via YAML definitions stored in individual directories and files rather than long lists of HCL objects. This prevents redundant cirrus configuration across deployment environments while still allowing for environment-specific values to be set via template variables in task definitions.
A new cirrus submodule,
typed-definitions
, was created to facilitate this change by addressing Terraform's difficulty with implicit typecasting of complex objects derived from YAML definitions. This module is used behind the scenes and should not be called by the user.Related issue(s)
Proposed Changes
cirrus
module (and all upstream modules) no longer take lists oftask
,task-batch-compute
, andworkflow
config objects. Instead, it accepts the following:task_batch_compute_definitions_dir
- filepath to the directory containing subdirectories withtask-batch-compute
YAML definitions. Filepath is relative to the Terraform deployment's root directory.task_definitions_dir
- filepath to the directory containing subdirectories withtask
YAML definitions. Filepath is relative to the Terraform deployment's root directory.task_definitions_variables
- map of maps to strings. Used for templatingtask
YAML definitions with any environment-specific values, such as data buckets. The outer map keys should be task names, the inner map keys a name that represents the placeholder's purpose (e.g.,{ copy-assets = { image_tag = "v3.0" }}
). See example below for more.workflow_definitions_dir
- filepath to the directory containing subdirectories withworkflow
YAML definitions. Filepath is relative to the Terraform deployment's root directory.cirrus
module will glob each of the specified directories above for anydefinition.yaml
files that are one level deep, e.g.<definitions dir>/<namespaced dir>/definition.yaml
. Each set of globbed YAML files are decoded into a list of their HCL equivalent objects.task
YAML definitions are templated prior to HCL conversion using thetask_definitions_variables
contents.task-batch-compute
andworkflow
YAML definitions are not templated; contents are the same across all environments (though workflow state machine JSONs are different by necessity - this is handled by thecirrus
module).cirrus
's submodule executions. Thus, thetyped-definitions
submodule was added undercirrus
to explicitly convert these tuples to their expected type (along with some additional input validation). The resulting list of objects are passed to thetask
,task-batch-compute
, andworkflow
submodules. The user does not need to use this submodule directly; thecirrus
module will use it automatically.task
,task-batch-compute
, andworkflow
resources are created just as before.Converting to YAML
cirrus_inputs.task_batch_compute
list, perform the following steps:cirrus/task-batch-compute
. The directory name should match that object'sname
attribute.definition.yaml
under this new subdirectory. Convert the contents of that single HCL element into its YAML equivalent.README.md
with any information about thistask-batch-compute
item that you deem useful (purpose, etc.).Updated layout:
Example source HCL:
Example converted YAML:
cirrus_inputs.tasks
list, perform the following steps:cirrus/tasks
. The directory name should match that object'sname
attribute.definition.yaml
under this new subdirectory. Convert the contents of that single HCL element into its YAML equivalent. If there are any values that might be specific to a given deployment environment, such as a source data bucket, you should template those now:${my-first-task.image_tag}
cirrus_inputs.task_definitions_variables
HCL variable, add an entry with a value specific to your target environment, e.g.:{ my_first_task = { image_tag = "dev", ...} ...}
. This value will be templated into your task definition at runtime prior to HCL conversion.${CIRRUS_DATA_BUCKET}
in your task YAML definition without having to add an entry for it tocirrus_inputs.task_definitions_variables
.README.md
with any information about thistask
item that you deem useful (purpose, source code repo link, etc.).Updated layout:
Example source HCL for a
dev
environment:Example converted YAML that would be used across all environments:
Example
cirrus_inputs.task_definitions_variables
for thedev
environment:cirrus_inputs.workflows
list, perform the following steps:cirrus/workflows
. The directory name should match that object'sname
attribute.definition.yaml
under this new subdirectory. Convert the contents of that single HCL element into its YAML equivalent.template_variables
is no longer used. You'll update the the state machine JSON accordingly in the next step.template_filepath
is now namedstate_machine_filepath
.state-machine.json
under this new subdirectory and fill it with the contents of your state machine JSON. Make sure yourdefinition.yaml
'sstate_machine_filepath
points to this file (path is relative to the root of the repo). If you haven't already replaced your usage oftemplate_variables
, do so now:${arbitrary_variable_name}
with the explicit lookup value, e.g.${<your task name>.<task type>.<task attribute>}
, such as${my-first-task.lambda.function_arn}
. See here for the valid values.template_variables
config from yourdefinition.yaml
if you haven't already.README.md
with any information about thisworkflow
item that you deem useful (purpose, task flow, arch diagram, etc.).Updated layout:
Example source HCL:
Example converted YAML:
Testing
This change was validated by the following observations:
task-batch-compute
,task
, andworkflow
resources should be the same as they were before (though the state machine contents may change slightly based on the whims of Terraform's JSON diffing).Checklist