TerraDagger 🗡️
An easy to understand GO library for building portables CI/CD pipelines (as code) using Dagger for your infrastructure-as-code ☁️.
TerraDagger is a GO library that provides a set of functions and patterns for building portable CI/CD pipelines (as code) for your infrastructure-as-code. It's based on the wonderful Dagger pipeline-as-code project, and heavily inspired by Terratest. The problem that TerraDagger tries to solve is to provide a simple way to run your Terraform code in a portable way, and also to provide a way to run your pipelines in a containerized way, so you can run your pipelines in any environment, and also in any CI/CD platform.
Install it using Go get:
go get github.com/Excoriate/go-terradagger
NOTE: For the tools used in this project, please check the Makefile, and the Taskfile files. You'll also need pre-commit installed.
Configure the terradagger client, which under the hood, will configure the Dagger client:
td := terradagger.New(ctx, &terradagger.Options{
Workspace: viper.GetString("workspace"),
})
Now, it's time to start the engine (Dagger). It's important to start the engine before running any command, so ensure that your Docker daemon or any compatible OCI runtime is running.
if err := td.StartEngine(); err != nil {
return err // Handle the error properly in your code.
}
defer td.Engine.GetEngine().Close()
Terradagger has global options, and also specific terraform and terragrunt options. you can set the global options like this:
tfOptions :=
terraformcore.WithOptions(td, &terraformcore.TfOptions{
ModulePath: viper.GetString("module"),
EnableSSHPrivateGit: true,
TerraformVersion: viper.GetString("terraform-version"),
EnvVarsToInjectByKeyFromHost: []string{"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"},
})
There are many options supported, options that are meant to facilitate the use of containerized pipelines based on common use-cases, such as:
And then, you're good to go and run your desired Terraform commands, and chain them as you wish:
_, tfInitErr := terraform.InitE(td, tfOptions, terraform.InitOptions{})
if tfInitErr != nil {
return tfInitErr
}
NOTE: The
Esuffix in the function name means that the specific terraform command will return thestdoutand an error object. The variant without theEsuffix will return the actual Dagger Container object, and an error object.
To see a full working example, please check the terradagger-cli that's built in this repository
Note: This is still work in progress, however, I'll be happy to receive any feedback or contribution. Ensure you've read the contributing guide before doing so.
Please read our contributing guide.
$ claude mcp add go-terradagger \
-- python -m otcore.mcp_server <graph>