Updates In The Python Telegram Heroku Template

Published on Aug. 21, 2022 | Tags: terraform heroku infrastructure

Yesterday, I decided to start learning terraform and I started with some of my bots to see the gist of it. And can be very complex, these bots are simple enough in both code and required infrastructure that it was easy enough for me to try and play around a bit. Then, this morning, I decided to update the telegram heroku bot template repo to add these features. In the readme I wrote up all the necessary steps to create the repo and have it be managed by terraform.


This is the relevant part of the README:


By using Terraform


First and foremost, we need to install and configure the terraform cli tool.
Download and install terraform: https://www.terraform.io/downloads
Configure terraform with heroku by first creating a new authorization key:


heroku authorizations:create --description <helpful description for later>

With this key, let's export the following environment variables:


export HEROKU_API_KEY=<auth-token> HEROKU_EMAIL=$(heroku whoami)

Now that terraform is configured with the heroku provider, we can continue by customising our heroku app.
A main.tf terraform file is already prepared to do everything that needs to be done in heroku to get it up and running.
Before running any terraform commands, a bit of setup is needed. (From here on out it is assumed terraform is
installed and configured).



  1. The bot must be created in telegram beforehand anyway as you will need the telegram api token.

  2. Copy the file terraform.tfvars.example into terraform.tfvars.

  3. Fill in the heroku-app-name and the telegram-api-token values with the appropriate values.

  4. Now, we can initialise our terraform app by terraform init.

  5. You can now run terraform plan to see all the steps terraform will take.

  6. When you are happy with the changes, you can run terraform apply and terraform will create the heroku stack for you.


Once it is run and successful, we have our heroku app created! And we can move on onto deploying our application.


If you want to make any modifications in the future about the heroku application, you can run plan again to make sure all the changes are OK, then run apply again to apply them.


For more information about this, check out the official heroku tutorial and the heroku terraform official documentation.


NOTE: Make sure not to commit any of the files in .terraform, terraform.tfvars or any other file other than your .tf file as they will contain sensitive data.


Edit: This is a continuation of the previous post: https://www.jovell.dev/blog/2022/2/telegram-bots-from-idea-to-production/.


Ferran Jovell