galaxybrainco / cloudtower

Highly opinionated cloud management.
Apache License 2.0
0 stars 0 forks source link

Convert a docker-compose.yml file to terraform #1

Open phildini opened 1 year ago

phildini commented 1 year ago

This ticket is designed to be a long-form research ticket, with me working in public as I work out the first version of python script to convert a specific docker-compose file (ideally, the one from https://github.com/bookwyrm-social/bookwyrm) into a set of terraform files that I actually believe will do the thing.

Here's the steps as I see them:

phildini commented 1 year ago

Ok, this did not take long, but I'm already vaguely annoyed at bookwyrm's docker-compose.yml, specifically because of:

  db:
    build: postgres-docker
    env_file: .env
    entrypoint: /bookwyrm-entrypoint.sh
    command: cron postgres
    volumes:
      - pgdata:/var/lib/postgresql/data
      - backups:/backups
    networks:
      - main

(https://github.com/bookwyrm-social/bookwyrm/blob/1ff7d836ae595a8e22db8a2e9d4895e19d8dbb1c/docker-compose.yml#L28-L37)

Because they're defining their own postgres container, we don't get to take easy advantage of "knowing" this should actually be an RDS.

Although! Detecting that there's a volume called pgdata might be enough?

phildini commented 1 year ago

Ok, so using https://sourceforge.net/projects/ruamel-yaml/ (Sourceforge! What a rush!) I was able to parse the takahe docker-compose.yml.

It is annoying to me that this library strictly deals in orderedDicts, so my common repl tools are useless, but on the bright side ruamel/PyYaml auto-includes anchors.

So now I have rough parsing of the docker-compose, and I need to figure out what to do with it.

My first thought was cookiecutter, but I think that might be too heavy-weight? I think what I'm going to do instead is use jinja-fied versions of a standard terraform, and see how far I can get with that.

TODO added: look into how much flexibility there is in terraform resource naming