This repo contains terraform files to deploy django app using github actions.
.
├── .github
│ └── workflows
│ ├── build-v1.yml
│ ├── build.yml
├── .terraform.lock.hcl
├── README.md
├── main.tf
└── src
└── app
├── .dockerignore
├── .env
├── .env.example
├── .pytest_cache
├── Dockerfile
├── Pipfile
├── Pipfile.lock
├── README.md
├── devops_example_25981
├── docker-compose.override.yml
├── docker-compose.yml
├── heroku.yml
├── home
├── manage.py
├── modules
├── postgres-data
├── static
├── staticfiles
└── users
Following are instructions on setting up your environment.
- Generate Heroku Authorization and Terraform backend store
heroku authorizations:create --description terraform-my-app
APP_NAME=<Define app name>
heroku addons:create heroku-postgresql:hobby-dev --app $APP_NAME
-
Setup Github Secrets for Heroku:
DATABASE_URL
- This is needed to store terraform remote file state.HEROKU_API_KEY
- Store the authorziation token generatedHEROKU_EMAIL
- Email id for heroku account
-
Setup Github Secrets for App:
SECRET_KEY
-
Github Actions CI/CD setup is now ready and can be triggered with push to master branch or manually from actions tab.
There are 2 Actions defined in this repo
heroku_build.example: Still creating... [4m10s elapsed]
heroku_build.example: Still creating... [4m20s elapsed]
heroku_build.example: Still creating... [4m30s elapsed]
heroku_build.example: Creation complete after 4m34s [id=74b5d9f5-943e-4040-a96f-84dfe964d983]
Apply complete! Resources: 1 added, 0 changed, 1 destroyed.
Outputs:
app_id = "9b4a5cd9-4ee4-42d3-8476-20f7a9fc3bee"
app_name = "shashank123456789"
app_url = "https://shashank123456789.herokuapp.com"
- export
HEROKU_API_KEY
=<TOKEN>
- export
HEROKU_EMAIL
- export
DATABASE_URL
=$(heroku config:get DATABASE_URL --app $APP_NAME)
- terraform init -backend-config="conn_str=$DATABASE_URL"
- terraform plan -out plan
- terraform apply plan