From 3987ea0854fb0e5abff1c10b65910ba660f12dbc Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 30 Mar 2023 17:55:09 -0700 Subject: [PATCH] User Story 60501: batch-account-with-storage (#194) * New sample (converted from Bicep via OpenAI) * Edit per Code Review * Changes per Code Review --- .../101-batch-account-with-storage/main.tf | 40 +++++++++++++++++++ .../101-batch-account-with-storage/outputs.tf | 11 +++++ .../providers.tf | 16 ++++++++ .../101-batch-account-with-storage/readme.md | 19 +++++++++ .../variables.tf | 21 ++++++++++ 5 files changed, 107 insertions(+) create mode 100644 quickstart/101-batch-account-with-storage/main.tf create mode 100644 quickstart/101-batch-account-with-storage/outputs.tf create mode 100644 quickstart/101-batch-account-with-storage/providers.tf create mode 100644 quickstart/101-batch-account-with-storage/readme.md create mode 100644 quickstart/101-batch-account-with-storage/variables.tf diff --git a/quickstart/101-batch-account-with-storage/main.tf b/quickstart/101-batch-account-with-storage/main.tf new file mode 100644 index 00000000..51497f8b --- /dev/null +++ b/quickstart/101-batch-account-with-storage/main.tf @@ -0,0 +1,40 @@ +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + name = random_pet.rg_name.id + location = var.resource_group_location +} + +resource "random_string" "azurerm_storage_account_name" { + length = 13 + lower = true + numeric = false + special = false + upper = false +} + +resource "random_string" "azurerm_batch_account_name" { + length = 13 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_storage_account" "storage" { + name = "storage${random_string.azurerm_storage_account_name.result}" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + account_tier = element(split("_", var.storage_account_type), 0) + account_replication_type = element(split("_", var.storage_account_type), 1) +} + +resource "azurerm_batch_account" "batch" { + name = "batch${random_string.azurerm_batch_account_name.result}" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + storage_account_id = azurerm_storage_account.storage.id + storage_account_authentication_mode = "StorageKeys" +} diff --git a/quickstart/101-batch-account-with-storage/outputs.tf b/quickstart/101-batch-account-with-storage/outputs.tf new file mode 100644 index 00000000..5e9bbd41 --- /dev/null +++ b/quickstart/101-batch-account-with-storage/outputs.tf @@ -0,0 +1,11 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "batch_name" { + value = azurerm_batch_account.batch.name +} + +output "storage_name" { + value = azurerm_storage_account.storage.name +} diff --git a/quickstart/101-batch-account-with-storage/providers.tf b/quickstart/101-batch-account-with-storage/providers.tf new file mode 100644 index 00000000..4fd5f6ba --- /dev/null +++ b/quickstart/101-batch-account-with-storage/providers.tf @@ -0,0 +1,16 @@ +terraform { + required_version = ">=1.0" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.0" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/101-batch-account-with-storage/readme.md b/quickstart/101-batch-account-with-storage/readme.md new file mode 100644 index 00000000..2c06c5ed --- /dev/null +++ b/quickstart/101-batch-account-with-storage/readme.md @@ -0,0 +1,19 @@ +# Azure Batch account + +This template creates an Azure Batch account + +## Terraform resource types + +- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) +- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) +- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) +- [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) +- [azurerm_batch_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/batch_account) + +## Variables + +| Name | Description | Default | +|-|-|-| +| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | +| `resource_group_location` | Location of the resource group. | eastus | +| `storage_account_type` | Azure Storage account type. | Standard_LRS | diff --git a/quickstart/101-batch-account-with-storage/variables.tf b/quickstart/101-batch-account-with-storage/variables.tf new file mode 100644 index 00000000..232697ea --- /dev/null +++ b/quickstart/101-batch-account-with-storage/variables.tf @@ -0,0 +1,21 @@ +variable "resource_group_location" { + type = string + default = "eastus" + description = "Location for all resources." +} + +variable "resource_group_name_prefix" { + type = string + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} + +variable "storage_account_type" { + type = string + default = "Standard_LRS" + description = "Azure Storage account type." + validation { + condition = contains(["Premium_LRS", "Premium_ZRS", "Standard_GRS", "Standard_GZRS", "Standard_LRS", "Standard_RAGRS", "Standard_RAGZRS", "Standard_ZRS"], var.storage_account_type) + error_message = "Invalid storage account type. The value should be one of the following: 'Premium_LRS','Premium_ZRS','Standard_GRS','Standard_GZRS','Standard_LRS','Standard_RAGRS','Standard_RAGZRS','Standard_ZRS'." + } +}