Compare commits

...

2 Commits

Author SHA1 Message Date
zjhe
caff317c3f fix example 2024-10-05 09:41:28 +08:00
zjhe
af3343e56f bump azurerm to v3 2024-10-05 09:33:39 +08:00
3 changed files with 17 additions and 10 deletions

View File

@ -4,7 +4,7 @@ terraform {
required_providers { required_providers {
azurerm = { azurerm = {
source = "hashicorp/azurerm" source = "hashicorp/azurerm"
version = "~>2.0" version = "~>3.0"
} }
} }
} }
@ -17,6 +17,15 @@ 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
@ -27,7 +36,7 @@ resource "random_string" "fqdn" {
length = 6 length = 6
special = false special = false
upper = false upper = false
number = false numeric = false
} }
resource "azurerm_virtual_network" "vmss" { resource "azurerm_virtual_network" "vmss" {
@ -73,14 +82,12 @@ 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"
@ -127,7 +134,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 = var.admin_password admin_password = local.admin_password
custom_data = file("web.conf") custom_data = file("web.conf")
} }
@ -198,7 +205,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 = var.admin_password admin_password = local.admin_password
} }
os_profile_linux_config { os_profile_linux_config {

View File

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

View File

@ -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 = "ChangeMe123!" default = null
sensitive = true sensitive = true
} }