Terraform Testing Tools

terraform testing tools

What begins with “T”? I have been thinking about various ways of testing infrastructure and resources lately and have been having a difficult time parsing out the various tools that are available. This post is meant to be a reference for “finding the right tool for the right job” as part of testing various infrastructures.

Often times when you start talking about testing, you will hear about the testing pyramid, which is described along with some other interesting aspects of testing Terraform in this blog post, it covers a lot of the pitfalls and gotchas you might run into.

My aim originally was to find a good tool for unit testing Terraform and as part of that adventure have uncovered a number of other interesting projects, that while not directly applicable, could be very useful for a number of different testing scenarios. Read the above blog post for more info but suffice to say, unit testing (the bottom layer of the testing pyramid) is quite difficult to do with Infrastructure as Code and Terraform and at this point is mostly not a solved problem.

Here is the list of tools that I uncovered in my research. Please let me know if there are any missing.

Terratest

Terratest is written and maintained by the folks at Terragrunt and it provides a comprehensive testing experience for deploying Infrastructure as Code, testing that it works as expected and then tears down the IaC when it is finished. From what I can tell this is probably the most comprehensive testing tool out there, still doesn’t cover unit tests, but is a great way to ensure things are working end to end.

Kitchen-Terraform

Follows the BDD philosophy and spins up, tests and spins down various Terraform resources. Works in a similar fashion to Terratest to bring up the environment, test and then tear things down.

serverspec

This testing tool is one of the original tools I ran across when originally mulling over the idea of unit testing infrastructure back in the days when configuration management tools like Chef, Puppet and Salt ruled the earth.

inspec (aws-resources)

Very similiar to awspec, this tool provides a framework for testing various AWS resources. This one is nice because it uses inspec to build on and so it has a lot of extra capabilities.

awspec

Very similar to the other “spec” tools, awspec is built in the same style as serverspec/inspec and provides a very nice interface for testing various AWS resource types. Since it is modeled after serverspec, you will need to deal with Ruby.

Testinfra

Another Python based unit testing style framework. This tools varies from Terraform Validate in that it mainly focuses on testing the lower level server and OS, but it does have integration for testing a number of other things.

terraform-compliance

A nice tool for testing (and enforcing Terraform compliance rules).

Terraform Validate

This is a nice tool for expressing various test conditions as compliance, especially if you are already familiar with Python and its testing landscape. This tool parses configs using pyhcl and allows you to write familiar unittest style tests for Terraform configurations.

Pulumi

This one is a bit of a wild card but could prove interesting to some readers. Pulumi provides direct integration into your language of choice (Python for me) to enable you to write pulumi code using language native unit tests. Obviously Pulumi isn’t Terraform but I had to mention it here because there is a significant amount of crossover between the tools.

Read More

Automatically set Terraform environment variables

automatically load environment variables

If you have spent any time managing infrastructure you have probably run into the issue of needing to set environment variables in order to connect to various resources.

For example, the AWS Terraform provider allows you to automatically source local environment variables, which solves the issue of placing secrets in places they should be, ie. writing the keys into configurations or state. This use case is pretty straight forward, you can just set the environment variables once and everything will be able to connect.

The problem arises when environments need to be changed frequently or other configurations requiring secrets or tokens to connect to other resources need to be changed.

There are various tools available to solve the issue of managing and storing secrets for connecting to AWS including aws-vault and aws-env. The main issue is that these tools are opinionated and only work with AWS and aren’t designed to work with Terraform.

Of course this problem isn’t specific to Terraform, but the solution I have discovered using ondir is generic enough that it can be applied to Terraform as well as any other task that involves setting up environment variables or running shell commands whenever a specific directory is changed to or left.

With that said, the ondir tool in combination with Terragrunt, gives you a set of tools that vastly improves the Terraform experience. There is a lot of Terragrunt reference material already so I won’t discuss it much here. The real power of my solution comes from combining ondir with Terragrunt to enhance how you use Terraform.

Note: Before getting into more details of ondir, it is worth mentioning that there are several other similar tools, the most well known of which is called direnv. Direnv provides a few other features and a nice library for completing actions so it is definitely work checking out if you are not looking for a solution specific to Terraform/Terragrunt. Other tools in the space include autoenv, smartcd and a few others.

Direnv should technically work to solve the problem, but when managing and maintaining large infrastructures, I have found it to be more tedious and cumbersome to manage.

Ondir

From the Github page, Ondir is a small program to automate tasks specific to certain directories, so isn’t designed specifically to set environment variables but makes a perfect fit doing so.

Install ondir

# OSX
brew install ondir
# Ubuntu
apt install ondir

Configure ondir

After installing, add the following lines to your ~/.zshrc (or these lines if you are using bash) and restart your shell.

val_ondir() {
  eval "`ondir \"$OLDPWD\" \"$PWD\"`"
}
chpwd_functions=( eval_ondir $chpwd_functions )

Ondir leverages an ~/.ondirrc file to configure the tool. This file basically consists of enter and leave directives for performing actions when specific directories are entered and left. To make this tool useful with Terragrunt, I have setup a simple example below for exporting a database password given a path that gets switched into (if the path ends in stage/database), which is defined in the ~/.ondirrc file. One very nice feature of ondir is that it allows regular expressions to be used to define the enter/leave directives, which makes allows for complex paths to be defined.

enter .+(stage\/database)
    echo "Setting database password"
    export TF_VAR_db_password=mypassword
leave .+(stage\/database)
    unset TF_VAR_db_password

With this logic, the shell should automatically export a database password for Terraform to use whenever you switch to the directory ending in stage/database.

cd ~/project/path/to/stage/database
# Check your environment for the variable
env | grep TF_VAR
TF_VAR_db_password=mypassword

cd ~
# When you leave the directory it should get unset
env | grep TF_VAR

In a slightly more complicated example, you may have a databases.sh script containing more logic for setting up or exporting variables or otherwise setting up environments.

#!/usr/bin/env bash

db_env=$(pwd | awk -F '/' '{print $(NF-1)"/"$NF}')

if [[ "$db_env" == "stage/database" ]]; then
    # do stuff
    export TF_VAR_db_password="mypassword"

else [[ "$db_env" == "prod/database" ]]; then
    # do other stuff
    export TF_VAR_db_password="myotherpassword"
fi

Conclusion

That’s pretty much. Now you can automatically set environment variables for Terraform to use, based on the directory we are currently and no longer need to worry about setting and unsetting environment variables manually.

I HIGHLY recommend checking out direnv as well. It offers slightly different functionality, and some neat features which in some cases may actually be better for specific tasks than ondir. For example, the direnv stdlib has some great helpers to help configure environments cleanly.

For me, using ondir for managing my Terragrunt configs and direnv for managing other projects makes the most sense.

Read More

Explorando el Mundo de Casino Betfair y las Ventajas del Betfair App

En el mundo de las apuestas en línea, Betfair se destaca como uno de los líderes indiscutibles. Con una amplia gama de servicios que incluyen Betfair casino online y Betfair slots, esta plataforma ofrece una experiencia enriquecedora para todos los jugadores. Hoy exploraremos cómo puedes sacar el máximo provecho de la app de Betfair y disfrutar de todo lo que Casino Betfair tiene para ofrecer.

Apuestas y Casino en la Palma de tu Mano

La Betfair app permite a los usuarios acceder fácilmente a todas las funciones de Betfair desde cualquier lugar. Ya sea que te interese jugar en el Betfair casino o explorar las Slot Betfair, la aplicación te asegura un acceso rápido y seguro.

Betfair casino

¿Cómo Iniciar con el Betfair Login?

El proceso de Betfair login es sencillo. Debes ingresar tu usuario y contraseña desde la página principal o la app. Una vez dentro, el mundo del Casino Betfair está a tus pies.

Una Mirada a las Slots de Betfair

Una de las mayores atracciones del casino en línea son las slots. Las Betfair slots ofrecen variedad y emoción, con múltiples temas y opciones de apuesta. Tanto jugadores novatos como experimentados encontrarán algo a su gusto.

Promociones y Bonos

Betfair regularmente ofrece promociones para nuevos clientes y bonificaciones a los jugadores habituales. Estas ofertas pueden ser en forma de giros gratis o créditos adicionales para las apuestas.

La Seguridad en Betfair

La seguridad es una prioridad en Betfair. La plataforma asegura que las transacciones y datos personales estén protegidos mediante encriptación de alta seguridad. Además, las normas de juego responsable son parte central de la política de Betfair.

Conclusión

El Betfair apuestas y su casino en línea ofrecen una experiencia de entretenimiento completa. Desde un conveniente acceso móvil a través de la app hasta una variedad de juegos de casino, Betfair garantiza diversión y seguridad en un solo lugar.

Read More

Fedezze Fel a TippmixPRO Online Élményét – Tippmixpro app és Bónusz Lehet?ségek

A sportfogadás világában, különösen Magyarországon, a TippmixPRO egy kiemelked? lehet?ség, amely az online fogadók számára kínál egyedi esélyeket és exkluzív bónuszokat. Az alábbi cikkben bemutatjuk, hogy mit kínál a Tippmixpro app és miként lehet a Tippmixpro bónuszok által profitálni.

Tippmixpro app: A Jöv? Sportfogadása

Az okostelefonok korában a fogadás rajongói számára elengedhetetlen egy jól m?köd?, felhasználóbarát alkalmazás. A Tippmixpro app pontosan ezt biztosítja. Felhasználói egyszer?en és gyorsan elérhetik a legfrissebb mérk?zéseket, statisztikákat és odds-okat. Az app intuitív felülete lehet?vé teszi a sima navigációt a különböz? fogadási piacok között.

Bónuszok és Különleges Ajánlatok

Amikor regisztrál a https://tippmixpro-hu.eu.com/ weboldalon, az új játékosok vonzó bónuszokkal találkozhatnak. Ezek a bónuszok ösztönzik a játékosokat arra, hogy gyakrabban és nagyobb tétekkel fogadjanak, ami növeli a nyerési esélyeiket. Az online fogadási platform különféle promóciókkal és kampányokkal tartja fenn a játékosok érdekl?dését.

Online Fogadás Kényelme

A TippmixPRO online platform lehet?vé teszi a játékosok számára, hogy otthonuk kényelméb?l élvezhessék a fogadást. Nincs szükség a fizikális lottózók látogatására, minden egyszer?en elérhet? az interneten keresztül. Az online térben a transzparencia és a gyorsaság ugyanolyan fontosak, mint a megbízhatóság, amit a TippmixPRO garantál.

TippmixPRO Kép

Összegzés

A TippmixPRO online fogadási lehet?ségei számos új és tapasztalt sportfogadó számára nyújtanak izgalmas élményeket. A Tippmixpro app segít maximalizálni a hatékonyságot, míg a Tippmixpro bónuszok lehet?séget adnak arra, hogy még jobban kiélvezhesse a sportfogadások izgalmait. Kezdje meg fogadási kalandját még ma!

Read More

Révélations sur Cresus Casino : Découvrez les bonus et offres incroyables du Cresus Online Casino

Bienvenue dans le monde passionnant du Cresus Casino! Dans cet article, nous allons explorer comment profiter au maximum de Cresus Casino Bonus et découvrir les offres exclusives proposées par ce célèbre site de jeux en ligne.

Pourquoi choisir Cresus Online Casino ?

Cresus Online Casino est réputé pour sa vaste gamme de jeux captivants et ses promotions généreuses. Les joueurs peuvent y trouver aussi bien des machines à sous dernier cri que des tables de jeux classiques comme le blackjack et la roulette. Le site veille à offrir une expérience utilisateur agréable grâce à une interface intuitive et des transactions sécurisées.

Profitez des bonus exclusifs sur Cresus Casino

Le Cresus Casino Bonus est l’une des principales raisons qui attirent tant de joueurs. En tant que nouveau venu, vous pouvez bénéficier d’un bonus de bienvenue alléchant qui boostera vos chances de gagner dès votre arrivée. De plus, Cresus Casino propose régulièrement des promotions pour récompenser la fidélité de ses utilisateurs. Imaginez pouvoir doubler votre mise grâce à un bonus sans dépôt!

Une expérience immersive avec Cresus Casino Online

Cresus Casino Logo

En plus des offres attractives, Cresus Casino Online offre une expérience de jeu immersive avec des graphismes de haute qualité et des effets sonores réalistes. Vous pouvez également profiter de parties en direct avec de vrais croupiers, vous donnant l’impression d’être dans un casino réel sans quitter le confort de chez vous.

En savoir plus en vidéo

Pour ceux qui souhaitent en savoir plus sur les fonctionnalités et les nouveautés du Cresus Online Casino, n’hésitez pas à consulter notre vidéo explicative ci-dessus. Vous y trouverez des astuces et des conseils pour maximiser vos gains.

En conclusion, le Cresus Casino Online est une destination incontournable pour tout amateur de jeux d’argent. Que vous soyez à la recherche de divertissement ou de profits, ce casino en ligne saura répondre à toutes vos attentes!

Read More