DEV Community

Cover image for Update Content with Terraform
Antoine
Antoine

Posted on

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 !

Top comments (0)