GithubHelp home page GithubHelp logo

hasura / terrazura Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adron/terrazura

1.0 1.0 0.0 23.5 MB

Hasura + Azure + Terraform repo for code stream session on December 30th @ 10am.

License: Apache License 2.0

HCL 13.43% Shell 15.38% PLpgSQL 50.85% JavaScript 20.34%

terrazura's Introduction

terrazura

I created this repo during a live stream on my Twitch Thrashing Code Channel ๐Ÿค˜ at 10am on the 30th of December, 2020. The VOD is now available on my YouTube Thrashing Code Channel (click here for the direct link to video). A rough as hell year, but wanted to wrap it up with some solid content. In this stream I tackled a ton of specifics, in detail about getting Hasura deployed in Azure, Postgres backed, a database schema designed and created, using database schema migrations, and all sorts of tips n' tricks along the way. 3 hours of solid how to get shit done material!

Deployment (i.e. Prerequisites)

You'll need several CLI tools to use this repository for your own.

  1. Terraform - instructions & notes
  2. Azure CLI - instructions & notes
  3. Hasura CLI - instructions & notes

One those tools are available a few things need to be done with the aforementeiond tools.

The Azure CLI needs to be authenticated against Azure using the az login command. I wrote a post about setting up Terraform and the Azure CLI "Development Workspace with Terraform on Azure: Part 1 โ€“ Install and Setup Terraform and Azure CLI", check it out for specific details on setting up these two tools. This deployment can be used just by setting up and using this option to authenticate and Terraform will use this authenticated CLI moving forward, however I'd highly suggest using a Service Principal. For more details about setting up a Service Principal I've got some details about authenticatig to Azure in "Development Workspace with Azure: Building a Packer Image", in which the Packer image details aren't pertinent to this but in section 5 of that post I cover in detail the intricacies of setting up an Azure Service Princpal and the environment variables that you'll need.

The Hasura CLI needs to just be available and the scripts will utilize it apporpriately from within the folder structure of the project.

One these tools are made available and setup with the appropriate security and configuration, several environment variables need to be set so the launch scripts can pull the needed variable values to pass to Terraform for execution. The following are the environment variables needed:

  • PUSERNAME - The Postgres Username for the Postgres Server. Generally the default that Postgres usually uses in examples and such is simply postgres but you can enter whatever you'd like for the username here. This however may cause you to need to configure that user and the group the user is in within the database for the permissions against the tables you want. The TLDR is, for default setup it's a good idea to just roll with the default postgres user here.
  • PPASSWORD - This is your super secret password that the Postgres server will be setup with, as the password for the user setup as PUSERNAME. As stated above, that's probably postgres, so this would be the password for the postgres user in that case.

Other variables are also set and passed in via the bash scripts included in the repo, check out the terraformapply.sh or terraformdestroy.sh files to see where you can change those to your liking.

One all of these tools are installed, configured appropriately, and the environment variables set you're all good to go to launch per the following scripts. To terraform apply and deploy this Hasura API and Postgres Database, run:

./terraformapply.sh

Then when you're done using the environment run the script to destroy it:

./terraformdestroy.sh

How To, Video, and Blog Details About This Project

Picture at Time in Point of the Video

Some of the things covered:

  • Setup of infrastructure as code using Terraform.
  • Setup of GraphQL API Hasura Server.
  • Setup of Dev AND Live Prod Deployment using Docker & Terraform.
  • Build out of our initial Database Schema.
  • Deployment of the database schema to Hasura using Hasura CLI Migrations.
  • Coverage of basic GraphQL and looking into queries and mutations.

Time Points:

  • 02:49โ€‹ - Shout out to the stream sponsor, Azure, and links to some collateral material.
  • 14:50โ€‹ - In this first segment, I start but run into some troubleshooting needs around the provider versions for Terraform in regards to Azure. You can skip this part unless you want to see what issue I ran into.
  • 18:24โ€‹ - Since I ran into issues with the current version of Terraform I had installed, at this time I show a quick upgrade to the latest version.
  • 27:22โ€‹ - After upgrading and fighting through trial and error execution of Terraform until I finally get the right combination of provider and Terraform versions.
  • 27:53โ€‹ - Adding the first Terraform resource, the Azure resource group.
  • 29:47โ€‹ - Azure Portal oddness, just to take note off if/when you're working through this. Workaround later in the stream.
  • 32:00โ€‹ - Adding the Postgres server resource.
  • 44:43โ€‹ - In this segment I switched over to Jetbrain's Intellij to do the rest of the work. I also tweak the IDE to re-add the plugin for the material design themes and icons. If you use this IDE, it's very much IMHO worth getting this to switch between themes.
  • 59:32โ€‹ - After getting leveled-up with the IDE, I wrap up the Postgres server resource and terraform apply it the overall set of resources. At this point I also move forward with the infrastructure as code, with emphasis on additive changes to the immutable infrastructure by emphasizing use of terraform apply and minimizing any terraform destroy use.
  • 1:02:07โ€‹ - At this time, I try figuring out the portal issue by az logout and logging back in az login to Azure Still no resources shown but...
  • 1:08:47โ€‹ - eventually I realize I have to use the hack solution of pasting the subscription ID into the @Azure portal to get resources for the particular subscription account which seems highly counter intuitive since its the ONLY account. ๐Ÿง
  • 1:22:54โ€‹ - The next thing I setup, now that I have variables that need passed in on every terraform execution, I add a script to do this for me.
  • 1:29:35โ€‹ - Next up is adding the database to the database server and firewall rule. Also we get to see Jetbrains IntelliJ HCL plugin introspection at work adding required properties to the firewall resource! A really useful feature.
  • 1:38:24โ€‹ - Next up, creating the Azure container to deploy our Hasura GraphQL API for Postgres to!
  • 1:51:42โ€‹ - BAM! API Server is done and launched! I've got a live GraphQL API up and running in Azure and we're ready to start building a data model!
  • 1:56:22โ€‹ - In this segment I show how to turn off the public facing console and shift one's development workflow to the local Hasura console working against - local OR your live dev environment.
  • 1:58:29โ€‹ - Next segment I get into schema migrations, initializing a directory structure for Hasura CLI use, and metadata, migrations, and related data. Including an update to the latest CLI so you can see how to do that, after a run into a slight glitch. ๐Ÿ˜ฌ
  • 2:23:02โ€‹ - I also shift over to dbdiagram to graphically build out some of the schema via their markdown, then use the SQL export option for postgres combined with Hasura's option to execute plain ole SQL via migrations...
  • 2:31:48โ€‹ - Getting a bit more in depth in this segment, I delve through - via the Hasura console - to build out relationships between the tables and data so the graphql queries can introspect accordingly.
  • 2:40:30โ€‹ - Next segment, graphql time! I show some of the options of what is available immediately for queries and mutations via the console.
  • 2:50:36โ€‹ - Then some more details about metadata. I'm going to do a stream with further details, since I was a little fuzzy on some of those details myself, in the very very near future. However a good introduction to what the metadata does for the graphql API.
  • 2:59:07โ€‹ - Then as a wrap up to all of this... I nuke EVERYTHING and deploy it all out to Azure again inclusive of schema migrations, metadata, etc. ๐Ÿค˜๐Ÿป
  • 3:16:30โ€‹ - Final segment, I add some data to the database and get into a few basic queries and mutations in graphql via the graphiql console interface in Hasura.

terrazura's People

Contributors

adron avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.