Skip to content

sops_decrypt_file

unitstack

Usage

sops_decrypt_file(file_path: string) --> string

sops_decrypt_file decrypts a file encrypted with SOPS, so a repository can hold secrets encrypted with AWS KMS, GCP KMS, Azure Key Vault, HashiCorp Vault, age, or PGP. It reads the file as YAML, JSON, INI, or dotenv by its extension, and any other file as text. Decode the result to use it:

prod/app/terragrunt.hcl
locals {
secrets_file = find_in_parent_folders("secrets.yaml")
secrets = yamldecode(sops_decrypt_file(local.secrets_file))
}
inputs = merge(local.secrets, {
instance_type = "t3.micro"
})

It fails when the file doesn’t exist, can’t be decrypted, or decrypts to content that isn’t valid UTF-8. To fall back to a default, wrap the call in try:

terragrunt.hcl
locals {
secrets = try(jsondecode(sops_decrypt_file("secrets.json")), {})
}

Terragrunt decrypts each file once per command, and units that read the same file share the result.

Parameters

file_pathstring

The encrypted file. A relative path resolves from the unit’s directory, even in an included file.

Examples

terragrunt.hcl
locals {
secrets = yamldecode(sops_decrypt_file("secrets.yaml"))
}