Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The process for uploading files to Azure Storage using Terraform in Azure Pipeline involves the following steps:

  1. Define the Azure Storage account and the storage container in your Terraform code.
  2. Add your Terraform code to your Azure Pipeline repository.
  3. Configure your Azure Pipeline to run Terraform.
  4. Add the Azure Resource Manager (ARM) provider to your Terraform file.
  5. Use the Terraform "azurermstorageblob" resource to create a new blob container.
  6. Use the Terraform "azurermstorageblob" resource to upload the files to the blob container.

Here's an example of what the Terraform code might look like:

provider "azurerm" {
  features {}
}

resource "azurerm_storage_account" "storage_account" {
  name                     = "my-storage-account"
  resource_group_name      = "my-resource-group"
  location                 = "westus2"
  account_kind             = "StorageV2"
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_storage_container" "blob_container" {
  name                  = "my-blob-container"
  storage_account_name  = azurerm_storage_account.storage_account.name
  container_access_type = "private"
}

resource "azurerm_storage_blob" "example" {
  name                   = "example.txt"
  storage_account_name   = azurerm_storage_account.storage_account.name
  storage_container_name = azurerm_storage_container.blob_container.name
  type                   = "Block"
  source                 = "./example.txt"
  content_type           = "text/plain"
}

Once you've added this code to your Azure Pipeline repository and configured your pipeline to run Terraform, the pipeline will automatically create the storage account, the blob container, and upload the example.txt file to the blob container.