All Projects → carlpett → Terraform Provider Sops

carlpett / Terraform Provider Sops

Licence: mpl-2.0
A Terraform provider for reading Mozilla sops files

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Terraform Provider Sops

Terraform Provider Template
Terraform template provider
Stars: ✭ 119 (-42.23%)
Mutual labels:  terraform-provider
Terraform Provider Stripe
A Terraform Provider for Stripe
Stars: ✭ 143 (-30.58%)
Mutual labels:  terraform-provider
Terraform Provider Sentry
Terraform provider for Sentry
Stars: ✭ 183 (-11.17%)
Mutual labels:  terraform-provider
Terraform Provider Google Beta
Terraform Google Cloud Platform Beta provider
Stars: ✭ 123 (-40.29%)
Mutual labels:  terraform-provider
Terraform Provider Scaffolding
Quick start repository for creating a Terraform provider
Stars: ✭ 129 (-37.38%)
Mutual labels:  terraform-provider
Terraform Provider Shell
Terraform provider for executing shell commands and saving output to state file
Stars: ✭ 172 (-16.5%)
Mutual labels:  terraform-provider
Terraform Provider Zerotier
Create, modify and destroy ZeroTier networks and members through Terraform.
Stars: ✭ 113 (-45.15%)
Mutual labels:  terraform-provider
Terraform Provider Gitlab
Terraform GitLab provider
Stars: ✭ 205 (-0.49%)
Mutual labels:  terraform-provider
Terraform Provider Kustomization
Terraform provider for Kustomize
Stars: ✭ 136 (-33.98%)
Mutual labels:  terraform-provider
Terraform Provider Azuread
Terraform provider for Azure Active Directory
Stars: ✭ 178 (-13.59%)
Mutual labels:  terraform-provider
Terraform Provider Mongodbatlas
Terraform provider for MongoDB Atlas
Stars: ✭ 126 (-38.83%)
Mutual labels:  terraform-provider
Terraform Provider Docker
As part of our introduction to self-service publishing in the Terraform Registry, this copy of the provider has been archived, and ownership has been transferred to active maintainers in the community. Please see the new location on the Terraform Registry: https://registry.terraform.io/providers/kreuzwerker/docker/latest
Stars: ✭ 131 (-36.41%)
Mutual labels:  terraform-provider
Terraform Provider Vultr
Terraform Vultr Provider
Stars: ✭ 172 (-16.5%)
Mutual labels:  terraform-provider
Terraform Provider Grafana
Terraform Grafana provider
Stars: ✭ 118 (-42.72%)
Mutual labels:  terraform-provider
Terraform Provider Hcloud
Terraform provider for Hetzner Cloud
Stars: ✭ 138 (-33.01%)
Mutual labels:  terraform-provider
Terraform Provider Databricks
Databricks Terraform Provider
Stars: ✭ 119 (-42.23%)
Mutual labels:  terraform-provider
Terraform Provider Lxd
LXD Resource provider for Terraform
Stars: ✭ 164 (-20.39%)
Mutual labels:  terraform-provider
Terraform Provider Azurerm
Terraform provider for Azure Resource Manager
Stars: ✭ 3,007 (+1359.71%)
Mutual labels:  terraform-provider
Terraform Plugin Sdk
Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions
Stars: ✭ 201 (-2.43%)
Mutual labels:  terraform-provider
Terraform Provider Kubectl
Terraform provider to handle raw kubernetes manifest yaml files
Stars: ✭ 174 (-15.53%)
Mutual labels:  terraform-provider

terraform-sops

A Terraform plugin for using files encrypted with Mozilla sops.

NOTE: To prevent plaintext secrets from being written to disk, you must set up a secure remote state backend. See the official docs on Sensitive Data in State for more information.

Example

NOTE: All examples assume Terraform 0.13 or newer. For information about usage on older versions, see the legacy usage docs.

Encrypt a file using Sops: sops demo-secret.enc.json

{
  "password": "foo",
  "db": {"password": "bar"}
}

sops_file

terraform {
  required_providers {
    sops = {
      source = "carlpett/sops"
      version = "~> 0.5"
    }
  }
}

provider "sops" {}

data "sops_file" "demo-secret" {
  source_file = "demo-secret.enc.json"
}

output "root-value-password" {
  # Access the password variable from the map
  value = data.sops_file.demo-secret.data["password"]
}

output "mapped-nested-value" {
  # Access the password variable that is under db via the terraform map of data
  value = data.sops_file.demo-secret.data["db.password"]
}

output "nested-json-value" {
  # Access the password variable that is under db via the terraform object
  value = jsondecode(data.sops_file.demo-secret.raw).db.password
}

Sops also supports encrypting the entire file when in other formats. Such files can also be used by specifying input_type = "raw":

data "sops_file" "some-file" {
  source_file = "secret-data.txt"
  input_type = "raw"
}

output "do-something" {
  value = data.sops_file.some-file.raw
}

sops_external

For use with reading files that might not be local.

input_type is required with this data source.

terraform {
  required_providers {
    sops = {
      source = "carlpett/sops"
      version = "~> 0.5"
    }
  }
}

provider "sops" {}

# using sops/test-fixtures/basic.yaml as an example
data "local_file" "yaml" {
  filename = "basic.yaml"
}

data "sops_external" "demo-secret" {
  source     = data.local_file.yaml.content
  input_type = "yaml"
}

output "root-value-hello" {
  value = data.sops_external.demo-secret.data.hello
}

output "nested-yaml-value" {
  # Access the password variable that is under db via the terraform object
  value = yamldecode(data.sops_file.demo-secret.raw).db.password
}

Install

For Terraform 0.13 and later, specify the source and version in a required_providers block:

terraform {
  required_providers {
    sops = {
      source = "carlpett/sops"
      version = "~> 0.5"
    }
  }
}

Development

Building and testing is most easily performed with make build and make test respectively.

The PGP key used for encrypting the test cases is found in test/testing-key.pgp. You can import it with gpg --import test/testing-key.pgp.

Transitioning to Terraform 0.13 provider required blocks.

With Terraform 0.13, providers are available/downloaded via the terraform registry via a required_providers block.

terraform {
  required_providers {
    sops = {
      source = "carlpett/sops"
      version = "~> 0.5"
    }
  }
}

A prerequisite when converting is that you must remove the data source block from the previous SOPS provider in your terraform.state file. This can be done via:

terraform state replace-provider registry.terraform.io/-/sops registry.terraform.io/carlpett/sops

If not you will be greeted with:

- Finding latest version of -/sops...

Error: Failed to query available provider packages

Could not retrieve the list of available versions for provider -/sops:
provider registry registry.terraform.io does not have a provider named
registry.terraform.io/-/sops
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].