Skip to content

TODO is a simple web application with API Swagger documentation, which can be managed via TODO Terraform provider

License

Notifications You must be signed in to change notification settings

jakuboskera/todo

Repository files navigation

☑ TODO

jakuboskera jakuboskera jakuboskera jakuboskera

TODO is a simple web application which displays tasks that "should be done". These tasks can be created/updated/deleted only via API /api/v1 using proper API Key. This API is documented with Swagger documentation. Purpose of this application is mainly to leverage it as a basic application which can be then mananaged with IaC/GitOps approach.

Last release is always automatically deployed as live demo in Fly.io 🚀:

https://todo.jakuboskera.dev

TODO's tasks in live demo are managed via TODO Terraform provider and Terraform manifests are stored in repository jakuboskera/infra/todo.

As you can see, tasks which are defined in this Terraform manifest are same as tasks in live demo.

See Manage TODO application via Terraform provider.

📖 TOC

🏁 Get started

  1. Clone this repo

    git clone [email protected]:jakuboskera/todo.git
  2. Navigate to a folder todo

    cd todo
  3. Issue make command to see available targets, which you can use

    make

🎉 Run in docker using docker-compose

⚠️ Prerequisites

  • docker
  • docker-compose

🚀 Install

make run

Application is by default accessible on http://localhost:5000.

The application needs environment variable API_KEY with some secret. This secret is then used for securing API endpoints for adding, updating or deleting tasks. By default the secret is 12345678 (configured in .env file). So requests for interacting with these endpoints need to have HTTP header X-API-KEY with value which is equal to the environment variable API_KEY, otherwise the HTTP error code 401 is returned to the client.

🧹 Cleanup

make clean

😎 Manage TODO application via Terraform provider

There was created a TODO Terraform provider for this application, which can be used for managing a TODO instance. So you can create/update/delete a TODO tasks using Terraform manifests.

  1. Run TODO application localy using docker-compose

  2. Go to http://localhost:5000 and check that there are no tasks created

  3. Create this terraform manifest to create two tasks

    # main.tf
    
    terraform {
      required_providers {
        todo = {
          source  = "jakuboskera/todo"
          version = "0.2.0"
        }
      }
    }
    
    provider "todo" {
      url     = "http://localhost:5000"
      api_key = "12345678"
    }
    
    resource "todo_task" "coding" {
      text = "Create the best application ever"
    }
    
    resource "todo_task" "girlfriend" {
      text    = "Find a kind and pretty girlfriend"
      is_done = true
    }
  4. Initialize this Terraform project

    terraform init
  5. Create tasks in TODO application

    terraform apply -auto-approve
  6. Go to http://localhost:5000 and check if these tasks were created:

    1. Create the best application ever
    2. Find a kind and pretty girlfriend
  7. Now you can change a text of this task, modify status, add another tasks, etc.

  8. After that you can delete tasks by

    terraform destroy -auto-approve

Develop

This will run application localy using SQLite as database.

export FLASK_APP=$PWD/main.py
export FLASK_DEBUG=True
export API_KEY=12345678 # used in X-API-KEY header when creating/updating/deleting tasks in API
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
flask db upgrade
flask run

If you will do a changes to DB schema don't forget to run

flask db migrate