DEV Community

Cover image for Update Content with Terraform
Antoine
Antoine

Posted on

2 2

Update Content with Terraform

Photo by Markus Winkler on Unsplash

Introduction

We are using Terraform to deploy infrastructure. But we are using it too, to deploy content (such as secrets, files etc ...).

In order to update such content, we have to specify extra data per type of content.

Key Vault Secrets

In order to update content for Azure Key Vault secrets, we can use tags, filed using current date with timestamp.

example:

resource "azurerm_key_vault_secret" "secret_sample" {
  name      = "secret_sample"
  value     = "example"
  key_vault_id = azurerm_key_vault.mykeyvault.id
  tags = {
    time        = timestamp()
  }
}
Enter fullscreen mode Exit fullscreen mode

Blob / Files

In order to update content for blob / files, we can use content_md5, filed using function filemd5.

example:

resource "azurerm_storage_blob" "source_files" {
  for_each = fileset("${path.module}/source_files", "/*.png")
  name                   = each.value
  storage_account_name   = azurerm_storage_account.storageaccount.name
  storage_container_name = "test"
  type                   = "Block"
  source                 = "source_files/${each.value}"
  content_md5            = filemd5("source_files/${each.value}")
}
Enter fullscreen mode Exit fullscreen mode

Hope this helps !

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs