Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Key Management Service
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Keys
    • Key version
    • Data encryption
  • Concepts
    • Overview
    • Keys
    • Key version
    • Encryption
    • Envelope encryption
    • Key consistency
    • Quotas and limits
  • Use cases
    • All use cases
    • Data encryption
      • Which encryption method should I choose?
      • Encrypting data using the Yandex.Cloud CLI and API
      • Encrypting data using the Yandex.Cloud SDK
      • Encrypting data using the AWS Encryption SDK
      • Encrypting data using Google Tink
    • Encrypting secrets in Managed Service for Kubernetes
    • KMS key management with Hashicorp Terraform
    • Encrypting secrets in Hashicorp Terraform
  • Access management
  • Pricing policy
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • SymmetricCryptoService
      • SymmetricKeyService
      • OperationService
    • REST
      • Overview
      • SymmetricCrypto
        • Overview
        • decrypt
        • encrypt
        • generateDataKey
        • reEncrypt
      • SymmetricKey
        • Overview
        • cancelVersionDestruction
        • create
        • delete
        • get
        • list
        • listAccessBindings
        • listOperations
        • listVersions
        • rotate
        • scheduleVersionDestruction
        • setAccessBindings
        • setPrimaryVersion
        • update
        • updateAccessBindings
  • Questions and answers
  1. Use cases
  2. Encrypting secrets in Hashicorp Terraform

Encrypting secrets in Hashicorp Terraform

  • Recommendations for safely storing secret data
  • See also

The Terraform provider for Yandex.Cloud lets you encrypt secrets with a KMS key to use them later in a Terraform configuration.

Specify the plaintext and KMS key to be used for encryption in the yandex_kms_secret_ciphertext block:

resource "yandex_kms_secret_ciphertext" "encrypted_strong_password" {
  key_id      = "<key ID>"
  aad_context = "additional authenticated data"
  plaintext   = "strong password"
}

You can then access the ciphertext via the variable ${yandex_kms_secret_ciphertext.encrypted_strong_password.ciphertext}.

Warning

Using yandex_kms_secret_ciphertext lets you hide secrets when deploying an infrastructure. However, in general, it's not safe to openly specify the plaintext and aad_context in a configuration file. Secrets can be read from configuration files or execution logs and can end up in the Terraform state.

Recommendations for safely storing secret data

  • Don't explicitly specify the secret values in the configuration file. Read them from storage with restricted access (for example, use secret storage).
  • Consider storing the Terraform state remotely.

See also

  • Getting started with Terraform in Yandex.Cloud.
  • Yandex.Cloud provider documentation.
  • Sensitive Data in State.
In this article:
  • Recommendations for safely storing secret data
  • See also
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC