Skip to content

Instantly share code, notes, and snippets.

@ImIOImI
Created December 8, 2021 15:45
Show Gist options
  • Save ImIOImI/c62afaf6ee4389c4510637c4b77ca6b5 to your computer and use it in GitHub Desktop.
Save ImIOImI/c62afaf6ee4389c4510637c4b77ca6b5 to your computer and use it in GitHub Desktop.
Azure Storage Account With Private Endpoint
terraform {
required_providers {
}
required_version = "~> 1.0.5"
}
provider "azurerm" {
subscription_id = var.us-dev-subscription-id
alias = "us"
features {}
}
resource "azurerm_resource_group" "example" {
name = "privateendpoint-rg-test"
location = var.location
provider = azurerm.us
}
resource "azurerm_virtual_network" "example" {
name = "${var.environment}-endpoint-test-vnet"
address_space = ["10.10.0.0/22"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
provider = azurerm.us
}
resource "azurerm_subnet" "storage" {
name = "${var.environment}-storage-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.10.1.0/24"]
enforce_private_link_endpoint_network_policies = true
provider = azurerm.us
}
resource "random_integer" "sa_num" {
min = 10000
max = 99999
}
resource "azurerm_storage_account" "example" {
name = "${lower(var.environment)}${random_integer.sa_num.result}endpointtest"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_kind = "StorageV2"
account_replication_type = "LRS"
enable_https_traffic_only = true
provider = azurerm.us
}
resource "azurerm_storage_container" "example" {
name = "acctestcont"
storage_account_name = azurerm_storage_account.example.name
container_access_type = "private"
provider = azurerm.us
}
resource "azurerm_private_endpoint" "example" {
name = "${var.environment}-pe"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
subnet_id = azurerm_subnet.storage.id
private_service_connection {
name = "${var.environment}-psc"
is_manual_connection = false
private_connection_resource_id = azurerm_storage_account.example.id
subresource_names = ["blob"]
}
provider = azurerm.us
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment