Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kestra-io/kestra-flows-template
https://github.com/kestra-io/kestra-flows-template
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kestra-io/kestra-flows-template
- Owner: kestra-io
- Created: 2024-05-27T12:50:06.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-07-10T13:02:28.000Z (4 months ago)
- Last Synced: 2024-07-11T09:46:15.570Z (4 months ago)
- Language: HCL
- Size: 26.4 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kestra Flow Factory with Terraform
To develop and deploy Kestra [flows](https://kestra.io/docs/workflow-components/flow), Kestra developers can use [Terraform](https://kestra.io/docs/terraform/guides/configurations).
Doing so comes with great advantages:
- Scale the codebase by using the [DRY best practices](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)
- Manage multiple environments thanks to Terraform
- Make reproducibility at the core of your Kestra developmentFile structure follows :
```YAML
.
└── environment/
├── development
├── production/ # Contains subfolders defining Kestra flows resources
│ ├── automation/
│ ├── cicd/
│ ├── dbt/
│ ├── main.tf # Instanciate each folder (automation, dbt ...)
│ └── ...
├── modules/ # Terraform modules to be used across environments
│ ├── dbt_run/
│ ├── postgres_query/
│ └── ...
└── subflows/ # Kestra subflows
├── main.tf
├── sub_query_my_postgres_database.yml
└── ...
```## Flow defintion
- Each environment (i.e. development folder) is linked to a Kestra [namespace](https://kestra.io/docs/workflow-components/namespace)
- we wrap flow definition in folders to separate use cases
- each TF module created in an `environmnent` sub-folder is called in `main.tf` to be instanciated
- `triggers` are meant to be reusable to DRY our code. They should not be declared for a specific flow (except for [flow trigger](https://kestra.io/docs/workflow-components/triggers/flow-trigger))## Environments
`development` & `production` are deployed on same Kestra instance.
`development` allows you to test your flow before going in production. Make sure you are not working at the same time on it.
`production` requires you to create a PR to validate your changes before being able to apply.
> Note: Using namespaces to seperate environment within the same Kestra instance is not recommanded for production. You can read more about best practices for Kestra environment and deployment management [here](https://kestra.io/docs/best-practices/from-dev-to-prod)
>TODO: improve developer experience if concurrent access. Not needed now. Secure `terraform apply` in production using CI/CD.## FLow deployment
1. Before creating your PR
To ensure your changes are correct and check how it impacts current state, run in `environment` :
- `terraform init`
- `terraform plan`2. Create your PR : fill the pull_request template
3. **When PR has been reviewed and accepted**
- Merge your PR
- Go on `main` branch
- Run `terraform apply` with the `terraform_apply` Kestra flow to apply your changes## Module & subflows
In order to provide modular dev experience, we leverage Terraform [modules](https://developer.hashicorp.com/terraform/language/modules/develop) and [subflow](https://kestra.io/docs/workflow-components/subflows) pattern.
- `modules` are used as an abstraction layer for a whole use case (i.e. triggering an Airbyte sync and runnong dbt) without having to worry about Kestra syntax, authentication or connection details. It allows you to use all native Terraform features regarding input validation and passing from other ressources (i.e. DBT cloud job config Terraform resource outputs or Airbyte ones) outputs to seamlessly create dependencies between components etc.
- `subflows` with terraform are best suited for generic and standalone tasks.
- It contains direct YAML and are declared within [subflows/main.tf](subflows/main.tf) and define Inputs and Outputs clearly.
- Subflows can depend on each other, this dependency should be materialized by `depends_on` field in [subflows/main.tf](subflows/main.tf).
- Can be used by `modules` to hide some non-necessary complexity and to dry redundant tasks (GCP secret retrieval for example)# Useful links
- [Fundamentals](https://kestra.io/docs/tutorial/fundamentals)
- [Leverage Terraform for flow modularity](https://kestra.io/docs/how-to-guides/terraform-templating)