Selecting an AWS subnet by name in Terraform

One of my recent challenges has been to write tf code to select existing subnets and use them in new blocks of code (specifically in this case to create a Directory, Workspaces and add a few Security Group entries). Since I am relatively new to using Terraform to do this it took far longer to figure out than I would care to say and I figured it would be best to document what finally worked and had the concept click for me in my mind.

provider "aws" {
  region = "us-east-1"
}
variable "subnet_name" {
  default = "workspaces-private-us-east-1c"
}
data "aws_subnet" "selected" {
  filter {
    name = "tag:Name"
    values = ["${var.subnet_name}"]
  }
}

output "vpcid" {
  value = "${data.aws_subnet.selected.vpc_id}"
}

output "subnet_name" {
  value = "${var.subnet_name}"
}
output "subnet_id" {
  value = "${data.aws_subnet.selected.id}"
}

This will look up the named subnet “workspaces-private-us-east-1c” and obtain not only the VPC ID associated with it but the unique subnet id as well, the output should look something like the below sample provided the name you are looking up is unique

data.aws_subnet.selected: Refreshing state...

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

subnet_id = subnet-0299e079c90b20ea6
subnet_name = workspaces-private-us-east-1c
vpcid = vpc-04066bef0a56ebcc2

This is of course specific to things as of Terraform 0.12.20 and provider.aws 2.48.0 so naturally things may change over time, however this will get you close and provide you enough of a starting point to use these subnets in other things.

Youtube Essential Ripping Platform

So I have been a longtime user of youtube-dl for ages to archive some things (obscure music, recordings of tech talks) and figured it was worth taking some time to make a simple and easy to use way to achieve this that others could benefit from. More simply put I created a front-end with Python and Flask to sit on top of youtube-dl and make the process so easy non-technical people could use it. Thus YERP was born (https://gitlab.com/dword4/yerp) to fill that role. I know there are tons of other competiting ideas out there doing the exact same thing but I wanted to take a crack at it for my own home network and get it so simplified that all you had to do was run a Dockerfile and it would spring into existence without configuration.

The project is VERY green right now and things are moving around and changing alot (even in my head before code is committed to the repository) so don’t bank on things staying how they are. There are tons of little features I want to put in like folder organization, backups, flags for filetypes and the like which will take quite a while to figure out how I would like to implement them. So if you do run the program just beware and if you find something that can be done better feel free to submit a PR and I will gladly bring other code into the project since I am only one person and not exactly a professional at this to begin with.

Apple 7th Gen iPad + Smart Cover Fix

Perhaps the most frustrating part of using the Apple Smart Cover with the 7th Gen iPad is that the keyboard just randomly stops working from time to time with no real rhyme or reason as to why. After lots of searching around and not getting anywhere I finally found a solution that works like a charm

  1. Physically disconnect cover from the iPad
  2. Reconnect the cover
  3. use Cmd + Tab to switch through a few apps
  4. resume typing because Apple hasn’t fixed this in the software yet

Considering I have seen articles from like 2 years ago where this was an issue it really feels like Apple should have fixed this by now but nope, an up to date 7th generation iPad in 2020 is still having this issue. Makes me wonder what that premium price tag for most Apple goods go to if not fixing/refining the products.

Winter Improvements for Hockey-Info

Finally got around to a rather large update for this project, fixed some small bugs such as the L10 data being way wrong (was showing win-loss-ot for the entire seaseon) as well as added in missing stats for Goalies and made the display of previous game results more sensible. Also redid about 95% of the interface to use Bootstrap4 which has made the look more uniform throughout. If you are interested in seeing the code itself you can see that here, or if you just want to check out the live site which I host as well then you can head over to http://hockey-info.online.

On the Road: Chicago

Not too shabby of a view

So I find myself on the road in Chicago as of Sunday, doing a round of technical interviews in my effort to take the next step in my career progression. Not a very long stay but the view from my hotel room at night was great, really captured the feel of the city at night I think. As much as I miss being at home and sleeping in my own bed I kind of wish I could have at least one more day if only to take a trip to a few landmarks and hit up a nearby fountain pen shop.

Still Moving

Slowly but surely I am getting my stuff set back up, the computer was the first part as I am currently searching for a job and need access to my resume files and my email in a manner other than my phone or tablet. Speaking of tablets I am really enjoying my 6th generation iPad that I got recently with the LTE option on it. After some talk with a buddy of mine (mikep) and getting blink-shell on the app store I gotta say its a fantastic ssh experience on iOS. I have been using it to decent success to work on a few side projects like my youtube-dl front-end.

It is pretty wild how much stuff accumulates over the course of 5 years and nothing quite puts it in focus like moving and having to drastically downsize. My office had 3 different desks, 3 computers and 6 monitors ranging in size from 23″ to 27″. To say the heat could get excessive in there was an understatement, I ran a box fan in the hallway to help circulate the air. In the move I have downsized to just a matched pair of 24″ screens and a single desk, hopefully this more focused environment will let me be more productive when it comes to projects and work.

On the topic of work it seems like the more moving I do the more I just want to lock myself away and code, I have ideas for tweaks to existing projects like the hockey-info website and new stuff like YeRP which needs a big push to get to a point where I am ready to release it to the internet for general use. I wonder what it is about absence of coding that makes me want to do it more?

New Digs

So I am moving and took the opportunity to change my desk setup to something a lilttle more focused from my previously insane configuration. Behold an actual matched pair of 24″ screens on a mount where I will hopefully be churning out all sorts of new projects (like YeRP – Yet another Ripping Portal that uses flask and youtube-dl to present a mobile friendly interface.

Patching CentOS 7 (and overcoming problems)

So I was working on patching some of my Icinga infrastructure at work, and it seems that sometimes libyajl breaks things, as illustrated below

root@icingasatellite ~]# yum update
Loaded plugins: fastestmirror, rhnplugin
This system is receiving updates from RHN Classic or Red Hat Satellite.
Loading mirror speeds from cached hostfile

  • epel: mirror.optus.net
    Resolving Dependencies
    --> Running transaction check
    ---> Package icinga2.x86_64 0:2.10.4-1.el7.icinga will be updated
    ---> Package icinga2.x86_64 0:2.10.5-1.el7.icinga will be an update
    ---> Package icinga2-bin.x86_64 0:2.10.4-1.el7.icinga will be updated
    ---> Package icinga2-bin.x86_64 0:2.10.5-1.el7.icinga will be an update
    --> Processing Dependency: libyajl.so.2()(64bit) for package: icinga2-bin-2.10.5-1.el7.icinga.x86_64
    Traceback (most recent call last):
    File "/bin/yum", line 29, in
    yummain.user_main(sys.argv[1:], exit_code=True)
    File "/usr/share/yum-cli/yummain.py", line 375, in user_main
    errcode = main(args)
    File "/usr/share/yum-cli/yummain.py", line 239, in main
    (result, resultmsgs) = base.buildTransaction()
    File "/usr/lib/python2.7/site-packages/yum/
    init.py", line 1198, in buildTransaction
    (rescode, restring) = self.resolveDeps()
    File "/usr/lib/python2.7/site-packages/yum/depsolve.py", line 893, in resolveDeps
    CheckDeps, checkinstalls, checkremoves, missing = self._resolveRequires(errors)
    File "/usr/lib/python2.7/site-packages/yum/depsolve.py", line 1025, in _resolveRequires
    (checkdep, missing, errormsgs) = self._processReq(po, dep)
    File "/usr/lib/python2.7/site-packages/yum/depsolve.py", line 350, in _processReq
    CheckDeps, missingdep = self._requiringFromTransaction(po, requirement, errormsgs)
    File "/usr/lib/python2.7/site-packages/yum/depsolve.py", line 680, in _requiringFromTransaction
    rel=pkg.rel)
    File "/usr/lib/python2.7/site-packages/yum/
    init.py", line 5280, in update
    availpkgs = self._compare_providers(availpkgs, requiringPo)
    File "/usr/lib/python2.7/site-packages/yum/depsolve.py", line 1648, in _compare_providers
    bestnum = max(pkgresults.values())
    ValueError: max() arg is an empty sequence

Turns out the secret is simply to install yaljl and yajal-devel and then I can patch successfully, really surprised nobody else out there has run into this yet but its the second time in a month I have had it happen when patching.

Project: hockey-info

So I don’t always have great cell phone service, sometimes its weak 4G or even not 4G at all so modern designed apps suffer when bandwidth is a trickle at best. I would be away from home trying to find out whats going on with a Caps game and the NHL app would just be painfully slow or not work at all sometimes. Eventually I decided the only reasonable thing a hockey nerd such as myself could do was write something to fill this void, ideally something simple and effective to get me the information I wanted without a lot of overhead and frilly extra stuff I didn’t really care about.

The repos are still in high flux right now as I don’t even have a readme file yet for the main one, however this page can serve to sort of explain the bits and pieces.

nhlapi – This is what started it all for me really, I wanted more information about games (for an IRC bot) and threw myself into pulling various bits of information together about the NHL API in an easy to read and access way so others didn’t have to spend the hours I did looking for how to do things.

hockey-info – A super simple website written in Python utilizing the Flask framework. The focus is to be fast, simple and mobile friendly. It directly queries the NHL API for all its information and is formatted in a way that works well on mobile

hockey-info-docker – A bare bones Dockerfile to deploy the latest release of hockey-info. The container is based on Alpine and is as trimmed down as possible, makes deployment super simple and easy for anybody to run their own instance with only a few commands (provided you already have a Docker host to run it on).

Naturally I make no warranty about this app or any of the code I have written, its purely something neat I built in my spare time and am tossing out there for others to enjoy, modify and extend to their hearts content. If you do happen to have input, ideas, or feedback hit me up on twitter or just open an issue on Gitlab if its a purely technical issue to address with the code.

Hockey Records

The NHL was kind enough to release records.nhl.com to the public to browse more interesting stats than just game-by-game data, things like players that have hit the 1000 point milestone and other more trivia-friendly factoids.  Naturally the spidey senses went to tingling as soon as I saw the news on Reddit so I ran off to start poking at it and lo-and-behold it actually hits what appears to be the same data source as nhl.com/stats/rest but with all sorts of extra endpoints to try out.  This time around I attempted to be slightly clever and looked at https://records.nhl.com/static/js/client.bundle.js to save myself the trial-and-error process I used on a lot of the Stats API.  Turns out this was actually a smart move an probably would have let me document a lot of this stuff sooner if I had thought to spend some time poking around the code of the stats website.  No matter,  what counts is that now there is a rough outline of the Records API and it has been rolled into the NHLAPI repo on Gitlab.  Just like before if you see something I missed feel free to open a PR and if I don’t happen to see it right away @ me on twitter, I try to respond fairly quickly.

Footnote: https://beautifier.io/ is fantastic, it let me unmangle the client.bundle.js file so it was readable

Close Bitnami banner
Bitnami