201-confidential-vmss patch (#142)

* fix 201-confidential-vmss example
This commit is contained in:
Dingjia Chen 2023-02-13 23:37:44 -06:00 committed by GitHub
parent 44e546e979
commit 77c841daa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 19 deletions

View File

@ -1,33 +1,33 @@
resource "azurerm_resource_group" "example" {
name = "${var.name_prefix}-rg"
name = "${random_pet.random_prefix.id}-rg"
location = var.location
}
resource "azurerm_virtual_network" "example" {
name = "${var.name_prefix}-vnet"
name = "${random_pet.random_prefix.id}-vnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_subnet" "example" {
name = "${var.name_prefix}-subnet"
name = "${random_pet.random_prefix.id}-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_windows_virtual_machine_scale_set" "example" {
name = "${var.name_prefix}-vmss"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
resource "azurerm_windows_virtual_machine_scale_set" "main" {
name = "${random_pet.random_prefix.id}-vmss"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
# Available skus for Confidential VMSS can be found at: https://docs.microsoft.com/azure/confidential-computing/confidential-vm-overview
sku = "Standard_DC2as_v5"
sku = "Standard_DC2as_v5"
instances = 2
admin_username = "adminuser"
admin_password = var.admin_password
admin_password = random_password.password.result
computer_name_prefix = "vmss"
source_image_reference {
@ -56,3 +56,16 @@ resource "azurerm_windows_virtual_machine_scale_set" "example" {
vtpm_enabled = true
secure_boot_enabled = true
}
resource "random_password" "password" {
length = 20
min_lower = 1
min_upper = 1
min_numeric = 1
min_special = 1
special = true
}
resource "random_pet" "random_prefix" {
prefix = var.name_prefix
}

View File

@ -0,0 +1,20 @@
output "admin_password" {
sensitive = true
value = azurerm_windows_virtual_machine_scale_set.main.admin_password
}
output "resource_group_name" {
value = azurerm_resource_group.example.name
}
output "virtual_network_name" {
value = azurerm_virtual_network.example.name
}
output "subnet_name" {
value = azurerm_subnet.example.name
}
output "windows_virtual_machine_scale_set_name" {
value = azurerm_windows_virtual_machine_scale_set.main.name
}

View File

@ -1,10 +1,14 @@
terraform {
required_version = ">=1.0"
required_version = ">= 1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.8"
version = ">= 3.0, < 4.0"
}
random = {
source = "hashicorp/random"
version = ">= 3.0"
}
}
}

View File

@ -1,15 +1,11 @@
variable "admin_password" {
type = string
sensitive = true
description = "Admin password of the virtual machine scale set"
}
variable "location" {
type = string
default = "westus"
description = "Location where resources will be created"
}
variable "name_prefix" {
type = string
default = "201-confidential-vmss"
description = "Prefix of the resource name"
}
}