DEV Community

Cover image for Rotate on a periodic basis using Terraform
Antoine
Antoine

Posted on

1 1

Rotate on a periodic basis using Terraform

Photo by Jeremy Perkins on Unsplash

One key component of modern security is rotating secret.

Hashicorp has a good product that can generate secrets based on a master one : Vault.

I though it was very difficult to achieve this through Terraform.
But Terraform has a provider that can provide a change at the defined frequency basis : time_rotating.

Example:


terraform {
  required_providers {
    time = {
      source = "hashicorp/time"
      version = "0.5.0"
    }
  }
}

resource "time_rotating" "example" {
  rotation_days = 30
}

resource "random_id" "server" {
  keepers = {
    # Generate a new password each time time rotates
    rotation = time_rotating.example
  }

  byte_length = 8
}

Hope this helps !

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay