As the ecosystem around Terraform continues to grow we’re going to continue to blog about tools that we find interesting in this space. Today, we’ll talk about Bridgecrew Yor, which can be used to automatically tag infrastructure across a number of IaC platforms.
Yor supports a number of different “Built-in Taggers”. The “Git-based Tagger” is super helpful for organizations adopting GitOps:
“The git_* tags connect cloud resources to individual git commits and establish clear ownership between developers and resources which are routinely change.”
The “custom tagger”, which we’ll interact with today, allows you to build any tagging standard to meet your organizational.
The combination of the two essentially brings together a necessary GitOps paper trail plus your tagging standard to meet the general organizational needs.
Scalr has many native integrations out of the box, but we have added flexibility by providing custom hooks to integrate with any tool in the cloud ecosystem, which is exactly what we’ll do with Yor. To do this we are going to leverage a couple of Scalr features:
First, let's create some Terraform code to launch a S3 bucket. NOTE: You can use your own Terraform code, it is not required to use this sample as Yor will automatically tag any resources that it supports.
Sample Terraform code (main.tf):
Variables for the Terraform (variables.tf):
Now lets create a pre-plan.sh script that will execute in the custom hook. This downloads Yor to be used in the Scalr runtime environment.
NOTE: Make sure that pre-plan.sh is added as an executable to Git.
Now, let’s create a python script (scripts.py) that the pre-plan.sh will call. This script will pull a number of different objects like VCS information, run details, and workspace tags, which Yor will then use to tag the instance with:
Next, log into Scalr and create a workspace, in this example we’ll set a VCS provider as the source and link to the repository with the code that was just created:
Drop down custom hooks and add pre-plan.sh to the before plan hook:
Add some sample workspace tags. This can only be done in the new beta UI( add /app2 to your URL https://<account>.scalr.io/app2/) or through the Scalr Terraform provider.
Click create workspace.
If you’re using the main.tf and variables.tf from the example, it will require you to set some variables in Scalr:
Now all you have to do is execute the run:
During the run, you’ll see that it first executes the pre-plan.sh
Then the run goes through the rest of the pipeline resulting in an apply and the resources being tagged property in AWS:
In just a few simple steps we were able to automate our tagging strategy for Terraform using Scalr custom hooks and plugging Yor into the pipeline. As you can see, Yor is a very simple, yet powerful, tool to get up and running. The Scalr custom hooks open up the possibilities for many integrations and having a fully customized workflow without having to build a DIY pipeline.
Test it out for yourself in Scalr today!