My Shitty Code

Embracing the Messiness in Search of Epic Solutions

Home

Welcome to my encyclopedia of shitty code!

  • GCP Logging Agent: Converting Unstructured to Structured Logging

    BACKGROUND The GCP logging agent uses modified fluentd, which allows us to do either unstructured logging or structured logging. The structured logging relies on JSON payload while the unstructured logging can be any texts. The advantage of structured logging is we can leverage log features in GCP Log Viewer. UNSTRUCTURED LOGGING Installing the unstructured logging […] Read More…

  • GCP Stackdriver Agent: “write_gcm: can not take infinite value” Error

    PROBLEM When running the stackdriver-agent (v6.x), the log file contains the following errors:- SOLUTION By default, the swap metric is enabled. To verify, go to /etc/stackdriver/collectd.conf and locate the following configuration:- This error occurs because the VM instance does not have swap memory, hence this metric plugin tries to divide by 0. To verify the […] Read More…

  • Terraform: Handling Errors with try(…)

    PROBLEM Given the following output block:- Sometimes, during an apply or destroy, we may get this error:- One way to fix this is to do conditional expressions like this, but it’s not pretty:- SOLUTION Since Terraform v0.12.20, we can solve this with try and achieve the same outcome:- Read More…

  • GCP: Deleting Project with Lien… Quickly

    PROBLEM The whole idea of placing a lien on a project is to prevent accidental deletion. But, sometimes it’s a little pain in the ass to attempt a project deletion in GCP Console only to find out a lien was set, especially during the development phase. Then, we grumpily open up Cloud Shell and run […] Read More…

  • Terraform: Skipping Buggy Provider Version

    PROBLEM Given the following required_providers block… … it will allow the following Google provider version: >= 3.8, < 4.0. As of today (May 10), the latest Google provider is 3.20.0. A quick terraform init confirms that. However, sometimes, there’s a need to skip a buggy version. For example, 3.20.0 breaks google_compute_firewall. SOLUTION To achieve that, […] Read More…

  • GCP + Terraform: Running Terraform Commands with a Service Account

    PROBLEM When running these commands… … it allows terraform apply to provision the infrastructure using your credential. However, sometimes there’s a need to run Terraform using a service account. SOLUTION First, identify the service account you want to use… for example: [email protected] Then, create and download the private key for the service account. Command: Output: […] Read More…

  • GCP + Kitchen Terraform: Local Development Workflow

    INTRODUCTION Here’s a typical workflow for implementing and running Kitchen Terraform tests outside of the GCP environment, for example, from an IDE on a Mac laptop. Enable “gcloud” Access Command: The first step is to ensure we can interact with GCP using the gcloud command using our user credential. This is needed because the tests […] Read More…

  • Git: Configuring Different Git User Info Depending on Projects

    PROBLEM Given, the following global config stored under ~/.gitconfig… When committing any code, the above user info will always be used. However, there are times you want to use a different user info depending on projects (ex: work projects, GitHub projects, etc) SOLUTION This is one of many ways to solve this problem. Let’s assume […] Read More…

  • Terragrunt: “plan-all” while Passing Outputs between Modules

    PROBLEM Terragrunt has a feature that allows one module to pass outputs to another module. For example, if “project-prod” module wants to consume “subfolders” output from “folder” module, it can be done like this in “project-prod” module’s terragrunt.hcl:- The challenge is when running commands such as plan-all, it will fail with the following error:- SOLUTION […] Read More…

About Author

This author has 20+ years of experience in software engineering and cloud engineering. In an industry where knowledge becomes obsolete in the next three months, he learns anything that crosses his path with no mercy. He codes Java while drinking Espresso and writes Spock specifications while listening to Groovy beats. He masters Google Cloud Platform just like he masters the art of predicting the movement of dark clouds over his backyard, where 60% of the time, he is right every time.

This author suffers from the Dunning-Kruger effect, where he overestimates his competence and underestimates his ignorance. Technology buzzwords never scare him, for he does not know what to be afraid of in the first place. GCP, GCS, GCR, GKE, GWT, JWT… they all sound the same to him. This author is a jack of all trades but a master of none. He writes like he knows all the answers, yet he googles for better solutions from elsewhere. He fakes it until he makes it, and if he doesn’t, that’s okay because he has the attention span of a squirrel.

By now, you should know this author is full of shit, and he apologizes in advance if you are trying to solve your company’s real problems with his shitty solutions.