Last active
June 9, 2017 04:16
-
-
Save HighwayofLife/57ac978e2c2b54a483c25a2bd666b5b8 to your computer and use it in GitHub Desktop.
Azure Storage Account Unique Name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "storageAccountPrefix" { | |
default = "node" | |
} | |
variable "resourceGroupName" { | |
default = "MyResourceGroup" | |
} | |
variable "location" { | |
default = "West US" | |
} | |
variable "nodeCount" { | |
default = 3 | |
} | |
resource "azurerm_resource_group" "main" { | |
name = "${var.resourceGroupName}" | |
location = "${var.location}" | |
} | |
# Storage account name must be globally unique, generate a random id | |
resource "random_id" "storageaccount" { | |
keepers = { | |
name = "nodestorage" | |
} | |
byte_length = 12 | |
} | |
# Example creating a single storage account | |
resource "azurerm_storage_account" "account1" { | |
name = "${format("%.24s", lower("${var.storageAccountPrefix}${random_id.storageaccount.id}"))}" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
location = "${var.location}" | |
account_type = "Standard_GRS" | |
} | |
# Example creating multiple (N) storage accounts | |
resource "azurerm_storage_account" "accountn" { | |
count = "${var.nodeCount}" | |
name = "${format("%.24s", lower("${var.storageAccountPrefix}${count.index}${random_id.storageaccount.id}"))}" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
location = "${var.location}" | |
account_type = "Standard_GRS" | |
} | |
# Create a container for each storage account (N) | |
resource "azurerm_storage_container" "containern" { | |
count = "${var.nodeCount}" | |
name = "vhds" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
storage_account_name = "${element(azurerm_storage_account.accountn.*.name, count.index)}" | |
container_access_type = "private" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment