User Story 60501: batch-account-with-storage (#194)

* New sample (converted from Bicep via OpenAI)

* Edit per Code Review

* Changes per Code Review
This commit is contained in:
Tom Archer 2023-03-30 17:55:09 -07:00 коммит произвёл GitHub
Родитель 12122dbf3d
Коммит 3987ea0854
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 107 добавлений и 0 удалений

Просмотреть файл

@ -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"
}

Просмотреть файл

@ -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
}

Просмотреть файл

@ -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 {}
}

Просмотреть файл

@ -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 |

Просмотреть файл

@ -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'."
}
}