Looped Network

Mastodon

No Starch Press seems to so consistently produce terrific books. I buy from them pretty regularly, and they always seem to offer up sales on pre-orders. Just today I got an email about getting 30% off The Book of Kubernetes, and it sounds like a great read. Here’s to hoping I can knock a few things off my to-read docket before it releases.

This post easily falls into the “so ridiculous that it shouldn’t be a post” category. However, considering how long I ended up stuck on it earlier today, I figure it’s worth making if it stands a chance of helping even one other person avoid the same fate as me. 😅

I’ve started doing a little bit of work with the Terraform Cloud API. Specifically, I was looking at being able to update a workspace variable through code. In this case, I was trying to change a variable I called replica_count which, if the name wasn’t enough of a giveaway, I was using to track how many replicas should be used in a Kubernetes container spec.

I found that I was able to easily get back all of my workspace variables via a GET to:

https://app.terraform.io/api/v2/workspaces/{workspace_id}/vars/

However, trying to make a PATCH to...

https://app.terraform.io/api/v2/workspaces/{workspace_id}/vars/{variable_id}

... with a body in JSON to specify the change resulted in a 500 internal server error response.

The JSON in the body wasn’t very complex. I only needed to modify the value. As the documentation specifies, and the type must be set to “vars” and the id must be set to the ID of the variable to change. This is a bit odd to me since I also have to give the ID in the URL, but it’s not a big deal. The attributes property then can optionally contain whatever property or properties need to be updated. In my case, the JSON just looked like:

{
    “data”: {
        “id”: var_id,
        “type”: “vars”,
        “attributes”: {
            “value”: 2
        }
    }
}

There isn’t a lot to go wrong here... but I managed to do it! I finally figured out what was wrong when I changed my PATCH to a GET just to validate that my JSON had to be the culprit. The GET responds with JSON which is very similar to what I needed to send, and that’s what tipped me off to the fact that the value of the variable is always a string, even if I’m thinking of it as a number in my head. So my value line needed to be:

“value”: “2”

After seeing that in the response to my GET, I updated my JSON, re-PATCHed, and saw that everything was successful.

After some debate and testing this morning, I think I’ve decided that I’ll most likely use Python for my proposed Write Freely CLI/TUI client. I created a repo for it, though I don’t have anything committed yet. I was initially debating between Python—a language with which I’m moderately familiar and trying to work with as much as I can since most of the things I do for work leverage it—and Go—a language which interests me but which I don’t know very well at all.

I have to admit that I was initially leaning toward Go for a few reason. First is that, in a perfect world, I eventually work on this project for a long time and it becomes something that other people may want to use. In that case, packaging things up for other people to use outside of something like a Docker container is a bit of a pain with Python. You can’t really expect most people to leverage a Python virtual environment to run your code. I also don’t particularly like making virtual environments all the time since my VPS doesn’t exactly have a ton of storage space. I figured Go would solve both of these problems since I wouldn’t need a virtual environment, and I could easily bundle my finished code up as a single executable, one which I could cross-compile for every platform if I so desired.

In practice, however, the space efficiency wasn’t great. Part of the problem is that I wanted to use the vim-go plugin, which requires a fairly hefty download of extras, accomplished via running :GoInstallBinaries from within Vim; if you don’t do this, you’ll see errors whenever you open or attempt to save a new .go file.

My bigger issue, though, is that it was pretty confusing to me off the bat just how to organize a Go application. I’ve written several very small Go applications before, and all of them were contained to a single file. Doing this is a nightmare as far as keeping things organized goes, and it very quickly becomes difficult to remember what is where as I scroll endlessly back and forth in a single file. I did some research on how projects should be organized, but despite having a page documenting exactly that, I honestly found the documentation very difficult. It doesn’t give concrete examples showing the file structure and seems to make a lot of assumptions about what people already know. It’s entirely possible there’s other documentation I should be reading prior to reading the link I just shared, but if that’s the case then I wish it was linked to from within that page.

Ultimately, I decided that trying to figure out things like this with Go seemed like a bit too much of a hurdle on top of also just learning how to do pretty much everything I need with the language. I do have some Udemy courses on Go that cover more in-depth topics than the books I’ve previously read (e.g. creating a full stack web application), so I may try to watch some of those in order to figure out if they help me any from an organization standpoint. I would like to take the opportunity to learn Go, but the documentation I’ve seen thus far doesn’t make me feel good about it.

I’ve been attempting to work through having fewer distractions in my life, especially throughout the day and especially stemming from my phone. I spend more time looking at my phone than I really like, despite the fact that my first inclination is to reach for it at literally any moment of downtime. No one else has joined the call yet for a work meeting? Better doomscroll for a bit. I need to upload a freshly built Docker image to the development lab via VPN, and it’s going to take about 2 minutes? That’s 2 minutes I can spend looking at nonsense on the Internet.

Ideally I could just avoid having my phone in the room with me while I’m working, but the reality of the situation is that I typically need to have it on hand. I get calls related to work on it, and I use it for MFA across a wide swath of services. Instead, I tried to make myself feel less inclined to constantly reach for it with less things that I want to check all the time. One of my first attempts at minimizing how much my phone distracts me was to get off Mastodon. Mastodon, much like how I used Twitter before it, almost immediately became the thing that I would always feel the need to look at, as if missing a single post was going to somehow make a big difference. I should have realized how far down the Mastodon rabbit hole I had gone when one of the main things I noticed about any Mastodon iOS app I tried was how it handled refreshing my timeline.

Moving away from Mastodon wasn’t too bad, but I still like the idea of having somewhere that I could post random nonsense, quick quips, etc. I wanted somewhere for content that wasn’t really “blog post” worthy but felt like fun to put online somewhere. I initially started with Tumblr. This actually worked pretty well, as Tumblr functinos decently well for both long form content and shorter content, especially when I wanted to post links, images, or even quotes. I actually even started working on a CLI Tumblr client that I could use from a VPS I was SSH’d into. I haven’t made it very far other than an extremely early build that allows for a few different post types, but I found their API pleasant to work with, especially via their SDK. The problem, however, is that Tumblr didn’t really solve the problem. I still ended up following a handful of other blogs, and before long I was still finding myself absentmindedly reaching for my phone so that I could spend a few minutes scrolling through memes and anime GIFs. Like many other social media platforms which aren’t Mastodon, Tumblr also has a vested interest in keeping my eyes glued to their platform as much as possible. As a result, a specially curated timeline of content their algorithms thought I would like was always waiting for me if nothing had recently been posted from the accounts I followed.

I went back to the drawing board and eventually realized that Write.as could work even better for this. Naturally, it has support for both long form posts like this one as well as shorter content that doesn’t even require a title. So that’s what I’ll be giving it a shot with, especially while I still have more than 6 months of time left on my Pro subscription. What’s also cool is that it has an API, so I may shift my focus into working on a CLI client for it rather than continuing with the Tumblr one that I (hopefully) won’t be leveraging much going forward. This would allow me to easily write content from any web browser, from my iOS devices via the Write Freely app, and from an SSH session if I have my (eventual) app installed.