Compare commits
2 Commits
201-vmss-j
...
UserStory2
Author | SHA1 | Date | |
---|---|---|---|
7908433829 | |||
5620b3e327 |
21
quickstart/101-batch-pools-with-job/README.md
Normal file
21
quickstart/101-batch-pools-with-job/README.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Azure Batch
|
||||||
|
|
||||||
|
Deploy an Azure Batch account and two batch pools.
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
- [azurerm_batch_pool](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/batch_pool)
|
||||||
|
|
||||||
|
## 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 |
|
||||||
|
|
||||||
|
## Example
|
114
quickstart/101-batch-pools-with-job/main.tf
Normal file
114
quickstart/101-batch-pools-with-job/main.tf
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
resource "random_pet" "rg_name" {
|
||||||
|
prefix = var.resource_group_name_prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_resource_group" "rg" {
|
||||||
|
location = var.resource_group_location
|
||||||
|
name = random_pet.rg_name.id
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "random_string" "storage_account_name" {
|
||||||
|
length = 8
|
||||||
|
lower = true
|
||||||
|
numeric = false
|
||||||
|
special = false
|
||||||
|
upper = false
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_storage_account" "example" {
|
||||||
|
name = random_string.storage_account_name.result
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
location = azurerm_resource_group.rg.location
|
||||||
|
account_tier = "Standard"
|
||||||
|
account_replication_type = "LRS"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "random_string" "batch_account_name" {
|
||||||
|
length = 8
|
||||||
|
lower = true
|
||||||
|
numeric = false
|
||||||
|
special = false
|
||||||
|
upper = false
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_batch_account" "example" {
|
||||||
|
name = random_string.batch_account_name.result
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
location = azurerm_resource_group.rg.location
|
||||||
|
storage_account_id = azurerm_storage_account.example.id
|
||||||
|
storage_account_authentication_mode = "StorageKeys"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "random_pet" "azurerm_batch_pool_name" {
|
||||||
|
prefix = "pool"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_batch_pool" "fixed" {
|
||||||
|
name = "${random_pet.azurerm_batch_pool_name.id}-fixed-pool"
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
account_name = azurerm_batch_account.example.name
|
||||||
|
display_name = "Fixed Scale Pool"
|
||||||
|
vm_size = "Standard_A1"
|
||||||
|
node_agent_sku_id = "batch.node.ubuntu 22.04"
|
||||||
|
|
||||||
|
fixed_scale {
|
||||||
|
target_dedicated_nodes = 2
|
||||||
|
resize_timeout = "PT15M"
|
||||||
|
}
|
||||||
|
|
||||||
|
storage_image_reference {
|
||||||
|
publisher = "Canonical"
|
||||||
|
offer = "0001-com-ubuntu-server-jammy"
|
||||||
|
sku = "22_04-lts"
|
||||||
|
version = "latest"
|
||||||
|
}
|
||||||
|
|
||||||
|
start_task {
|
||||||
|
command_line = "echo 'Hello World from $env'"
|
||||||
|
task_retry_maximum = 1
|
||||||
|
wait_for_success = true
|
||||||
|
|
||||||
|
common_environment_properties = {
|
||||||
|
env = "TEST"
|
||||||
|
}
|
||||||
|
|
||||||
|
user_identity {
|
||||||
|
auto_user {
|
||||||
|
elevation_level = "NonAdmin"
|
||||||
|
scope = "Task"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
"tagName" = "Example tag"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_batch_pool" "autopool" {
|
||||||
|
name = "${random_pet.azurerm_batch_pool_name.id}-autoscale-pool"
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
account_name = azurerm_batch_account.example.name
|
||||||
|
display_name = "Auto Scale Pool"
|
||||||
|
vm_size = "Standard_A1"
|
||||||
|
node_agent_sku_id = "batch.node.ubuntu 22.04"
|
||||||
|
|
||||||
|
auto_scale {
|
||||||
|
evaluation_interval = "PT15M"
|
||||||
|
|
||||||
|
formula = <<EOF
|
||||||
|
startingNumberOfVMs = 1;
|
||||||
|
maxNumberofVMs = 25;
|
||||||
|
pendingTaskSamplePercent = $PendingTasks.GetSamplePercent(180 * TimeInterval_Second);
|
||||||
|
pendingTaskSamples = pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 * TimeInterval_Second));
|
||||||
|
$TargetDedicatedNodes=min(maxNumberofVMs, pendingTaskSamples);
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
storage_image_reference {
|
||||||
|
publisher = "Canonical"
|
||||||
|
offer = "0001-com-ubuntu-server-jammy"
|
||||||
|
sku = "22_04-lts"
|
||||||
|
version = "latest"
|
||||||
|
}
|
||||||
|
}
|
19
quickstart/101-batch-pools-with-job/outputs.tf
Normal file
19
quickstart/101-batch-pools-with-job/outputs.tf
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
output "resource_group_name" {
|
||||||
|
value = azurerm_resource_group.rg.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "storage_account_name" {
|
||||||
|
value = azurerm_storage_account.example.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "batch_account_name" {
|
||||||
|
value = azurerm_batch_account.example.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "batch_pool_fixed_name" {
|
||||||
|
value = azurerm_batch_pool.fixed.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "batch_pool_autopool_name" {
|
||||||
|
value = azurerm_batch_pool.autopool.name
|
||||||
|
}
|
18
quickstart/101-batch-pools-with-job/providers.tf
Normal file
18
quickstart/101-batch-pools-with-job/providers.tf
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
terraform {
|
||||||
|
required_version = ">=1.0"
|
||||||
|
|
||||||
|
required_providers {
|
||||||
|
azurerm = {
|
||||||
|
source = "hashicorp/azurerm"
|
||||||
|
version = "~>3.0"
|
||||||
|
}
|
||||||
|
random = {
|
||||||
|
source = "hashicorp/random"
|
||||||
|
version = "~>3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "azurerm" {
|
||||||
|
features {}
|
||||||
|
}
|
11
quickstart/101-batch-pools-with-job/variables.tf
Normal file
11
quickstart/101-batch-pools-with-job/variables.tf
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
variable "resource_group_location" {
|
||||||
|
type = string
|
||||||
|
default = "eastus"
|
||||||
|
description = "Location of the resource group."
|
||||||
|
}
|
||||||
|
|
||||||
|
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."
|
||||||
|
}
|
21
quickstart/101-batch-pools-with-start-task/README.md
Normal file
21
quickstart/101-batch-pools-with-start-task/README.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Azure Batch with start task
|
||||||
|
|
||||||
|
Deploy an Azure Batch account and two batch pools, one of which has a "start task".
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
- [azurerm_batch_pool](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/batch_pool)
|
||||||
|
|
||||||
|
## 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 |
|
||||||
|
|
||||||
|
## Example
|
114
quickstart/101-batch-pools-with-start-task/main.tf
Normal file
114
quickstart/101-batch-pools-with-start-task/main.tf
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
resource "random_pet" "rg_name" {
|
||||||
|
prefix = var.resource_group_name_prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_resource_group" "rg" {
|
||||||
|
location = var.resource_group_location
|
||||||
|
name = random_pet.rg_name.id
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "random_string" "storage_account_name" {
|
||||||
|
length = 8
|
||||||
|
lower = true
|
||||||
|
numeric = false
|
||||||
|
special = false
|
||||||
|
upper = false
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_storage_account" "example" {
|
||||||
|
name = random_string.storage_account_name.result
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
location = azurerm_resource_group.rg.location
|
||||||
|
account_tier = "Standard"
|
||||||
|
account_replication_type = "LRS"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "random_string" "batch_account_name" {
|
||||||
|
length = 8
|
||||||
|
lower = true
|
||||||
|
numeric = false
|
||||||
|
special = false
|
||||||
|
upper = false
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_batch_account" "example" {
|
||||||
|
name = random_string.batch_account_name.result
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
location = azurerm_resource_group.rg.location
|
||||||
|
storage_account_id = azurerm_storage_account.example.id
|
||||||
|
storage_account_authentication_mode = "StorageKeys"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "random_pet" "azurerm_batch_pool_name" {
|
||||||
|
prefix = "pool"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_batch_pool" "fixed" {
|
||||||
|
name = "${random_pet.azurerm_batch_pool_name.id}-fixed-pool"
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
account_name = azurerm_batch_account.example.name
|
||||||
|
display_name = "Fixed Scale Pool"
|
||||||
|
vm_size = "Standard_D4_v3"
|
||||||
|
node_agent_sku_id = "batch.node.ubuntu 22.04"
|
||||||
|
|
||||||
|
fixed_scale {
|
||||||
|
target_dedicated_nodes = 2
|
||||||
|
resize_timeout = "PT15M"
|
||||||
|
}
|
||||||
|
|
||||||
|
storage_image_reference {
|
||||||
|
publisher = "Canonical"
|
||||||
|
offer = "0001-com-ubuntu-server-jammy"
|
||||||
|
sku = "22_04-lts"
|
||||||
|
version = "latest"
|
||||||
|
}
|
||||||
|
|
||||||
|
start_task {
|
||||||
|
command_line = "echo 'Hello World from $env'"
|
||||||
|
task_retry_maximum = 1
|
||||||
|
wait_for_success = true
|
||||||
|
|
||||||
|
common_environment_properties = {
|
||||||
|
env = "TEST"
|
||||||
|
}
|
||||||
|
|
||||||
|
user_identity {
|
||||||
|
auto_user {
|
||||||
|
elevation_level = "NonAdmin"
|
||||||
|
scope = "Task"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
"tagName" = "Example tag"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_batch_pool" "autopool" {
|
||||||
|
name = "${random_pet.azurerm_batch_pool_name.id}-autoscale-pool"
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
account_name = azurerm_batch_account.example.name
|
||||||
|
display_name = "Auto Scale Pool"
|
||||||
|
vm_size = "Standard_D4_v3"
|
||||||
|
node_agent_sku_id = "batch.node.ubuntu 22.04"
|
||||||
|
|
||||||
|
auto_scale {
|
||||||
|
evaluation_interval = "PT15M"
|
||||||
|
|
||||||
|
formula = <<EOF
|
||||||
|
startingNumberOfVMs = 1;
|
||||||
|
maxNumberofVMs = 25;
|
||||||
|
pendingTaskSamplePercent = $PendingTasks.GetSamplePercent(180 * TimeInterval_Second);
|
||||||
|
pendingTaskSamples = pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 * TimeInterval_Second));
|
||||||
|
$TargetDedicatedNodes=min(maxNumberofVMs, pendingTaskSamples);
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
storage_image_reference {
|
||||||
|
publisher = "Canonical"
|
||||||
|
offer = "0001-com-ubuntu-server-jammy"
|
||||||
|
sku = "22_04-lts"
|
||||||
|
version = "latest"
|
||||||
|
}
|
||||||
|
}
|
19
quickstart/101-batch-pools-with-start-task/outputs.tf
Normal file
19
quickstart/101-batch-pools-with-start-task/outputs.tf
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
output "resource_group_name" {
|
||||||
|
value = azurerm_resource_group.rg.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "storage_account_name" {
|
||||||
|
value = azurerm_storage_account.example.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "batch_account_name" {
|
||||||
|
value = azurerm_batch_account.example.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "batch_pool_fixed_name" {
|
||||||
|
value = azurerm_batch_pool.fixed.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "batch_pool_autopool_name" {
|
||||||
|
value = azurerm_batch_pool.autopool.name
|
||||||
|
}
|
18
quickstart/101-batch-pools-with-start-task/providers.tf
Normal file
18
quickstart/101-batch-pools-with-start-task/providers.tf
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
terraform {
|
||||||
|
required_version = ">=1.0"
|
||||||
|
|
||||||
|
required_providers {
|
||||||
|
azurerm = {
|
||||||
|
source = "hashicorp/azurerm"
|
||||||
|
version = "~>3.0"
|
||||||
|
}
|
||||||
|
random = {
|
||||||
|
source = "hashicorp/random"
|
||||||
|
version = "~>3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "azurerm" {
|
||||||
|
features {}
|
||||||
|
}
|
11
quickstart/101-batch-pools-with-start-task/variables.tf
Normal file
11
quickstart/101-batch-pools-with-start-task/variables.tf
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
variable "resource_group_location" {
|
||||||
|
type = string
|
||||||
|
default = "eastus"
|
||||||
|
description = "Location of the resource group."
|
||||||
|
}
|
||||||
|
|
||||||
|
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."
|
||||||
|
}
|
@ -4,7 +4,7 @@ terraform {
|
|||||||
required_providers {
|
required_providers {
|
||||||
azurerm = {
|
azurerm = {
|
||||||
source = "hashicorp/azurerm"
|
source = "hashicorp/azurerm"
|
||||||
version = "~>3.0"
|
version = "~>2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -17,15 +17,6 @@ provider "azurerm" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "random_password" "password" {
|
|
||||||
count = var.admin_password == null ? 1 : 0
|
|
||||||
length = 20
|
|
||||||
}
|
|
||||||
|
|
||||||
locals {
|
|
||||||
admin_password = try(random_password.password[0].result, var.admin_password)
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "azurerm_resource_group" "vmss" {
|
resource "azurerm_resource_group" "vmss" {
|
||||||
name = var.resource_group_name
|
name = var.resource_group_name
|
||||||
location = var.location
|
location = var.location
|
||||||
@ -36,7 +27,7 @@ resource "random_string" "fqdn" {
|
|||||||
length = 6
|
length = 6
|
||||||
special = false
|
special = false
|
||||||
upper = false
|
upper = false
|
||||||
numeric = false
|
number = false
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_virtual_network" "vmss" {
|
resource "azurerm_virtual_network" "vmss" {
|
||||||
@ -82,12 +73,14 @@ resource "azurerm_lb_backend_address_pool" "bpepool" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_lb_probe" "vmss" {
|
resource "azurerm_lb_probe" "vmss" {
|
||||||
|
resource_group_name = azurerm_resource_group.vmss.name
|
||||||
loadbalancer_id = azurerm_lb.vmss.id
|
loadbalancer_id = azurerm_lb.vmss.id
|
||||||
name = "ssh-running-probe"
|
name = "ssh-running-probe"
|
||||||
port = var.application_port
|
port = var.application_port
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_lb_rule" "lbnatrule" {
|
resource "azurerm_lb_rule" "lbnatrule" {
|
||||||
|
resource_group_name = azurerm_resource_group.vmss.name
|
||||||
loadbalancer_id = azurerm_lb.vmss.id
|
loadbalancer_id = azurerm_lb.vmss.id
|
||||||
name = "http"
|
name = "http"
|
||||||
protocol = "Tcp"
|
protocol = "Tcp"
|
||||||
@ -134,7 +127,7 @@ resource "azurerm_virtual_machine_scale_set" "vmss" {
|
|||||||
os_profile {
|
os_profile {
|
||||||
computer_name_prefix = "vmlab"
|
computer_name_prefix = "vmlab"
|
||||||
admin_username = var.admin_user
|
admin_username = var.admin_user
|
||||||
admin_password = local.admin_password
|
admin_password = var.admin_password
|
||||||
custom_data = file("web.conf")
|
custom_data = file("web.conf")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +198,7 @@ resource "azurerm_virtual_machine" "jumpbox" {
|
|||||||
os_profile {
|
os_profile {
|
||||||
computer_name = "jumpbox"
|
computer_name = "jumpbox"
|
||||||
admin_username = var.admin_user
|
admin_username = var.admin_user
|
||||||
admin_password = local.admin_password
|
admin_password = var.admin_password
|
||||||
}
|
}
|
||||||
|
|
||||||
os_profile_linux_config {
|
os_profile_linux_config {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
output "vmss_public_ip_fqdn" {
|
output "vmss_public_ip_fqdn" {
|
||||||
value = azurerm_public_ip.vmss.fqdn
|
value = azurerm_public_ip.vmss.fqdn
|
||||||
}
|
}
|
||||||
|
|
||||||
output "jumpbox_public_ip_fqdn" {
|
output "jumpbox_public_ip_fqdn" {
|
||||||
value = azurerm_public_ip.jumpbox.fqdn
|
value = azurerm_public_ip.jumpbox.fqdn
|
||||||
}
|
}
|
||||||
|
|
||||||
output "jumpbox_public_ip" {
|
output "jumpbox_public_ip" {
|
||||||
value = azurerm_public_ip.jumpbox.ip_address
|
value = azurerm_public_ip.jumpbox.ip_address
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ variable "admin_user" {
|
|||||||
|
|
||||||
variable "admin_password" {
|
variable "admin_password" {
|
||||||
description = "Default password for admin account"
|
description = "Default password for admin account"
|
||||||
default = null
|
default = "ChangeMe123!"
|
||||||
sensitive = true
|
sensitive = true
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user