Skip to content

equinor/terraform-azurerm-storage

Repository files navigation

Azure Storage Terraform Module

SCM Compliance Equinor Terraform Baseline Conventional Commits

Terraform module which creates an Azure Storage account.

Features

  • Microsoft Entra ID authorization enforced by default.
  • Public network access denied by default.
  • Read-access geo-redundant storage (RA-GRS) configured by default.
  • Blob soft-delete retention set to 7 days by default.
  • Blob point-in-time restore enabled by default.
  • File soft-delete retention set to 7 days by default.
  • Audit logs sent to given Log Analytics workspace by default.

Prerequisites

Usage

  1. Login to Azure:

    az login
  2. Create a Terraform configuration file main.tf and add the following example configuration:

    provider "azurerm" {
      storage_use_azuread = true
    
      features {}
    }
    
    resource "azurerm_resource_group" "example" {
      name     = "example-resources"
      location = "westeurope"
    }
    
    module "log_analytics" {
      source  = "equinor/log-analytics/azurerm"
      version = "~> 2.0"
    
      workspace_name      = "example-workspace"
      resource_group_name = azurerm_resource_group.example.name
      location            = azurerm_resource_group.example.location
    }
    
    module "storage" {
      source  = "equinor/storage/azurerm"
      version = "~> 12.0"
    
      account_name               = "example-storage"
      resource_group_name        = azurerm_resource_group.example.name
      location                   = azurerm_resource_group.example.location
      log_analytics_workspace_id = module.log_analytics.workspace_id
    
      network_rules_ip_rules = ["1.1.1.1", "2.2.2.2", "3.3.3.3/30"]
    }
  3. Install required provider plugins and modules:

    terraform init
  4. Apply the Terraform configuration:

    terraform apply

Development

  1. Login to Azure:

    az login
  2. Set environment variables:

    export ARM_SUBSCRIPTION_ID="<SUBSCRIPTION_ID>"
    export TF_VAR_resource_group_name="<RESOURCE_GROUP_NAME>"
    export TF_VAR_location="<LOCATION>"

Testing

  1. Initialize working directory:

    terraform init
  2. Execute tests:

    terraform test

    See terraform test command documentation for options.

Contributing

See Contributing guidelines.