Unverified Commit f6e7dafa authored by Stefan Scherer's avatar Stefan Scherer
Browse files

Update Terraform template

parent edfa1318
......@@ -53,9 +53,11 @@ Create the Azure VM with. After 5 minutes the VM should be up and running, and t
terraform apply
```
If you want more than one Packer VM, then use `terraform apply -var count=3`.
## Stage 2: Packer build
Now RDP into the Azure VM. Open a PowerShell terminal and clone my packer-windows repo or any other repo with a Packer template for HyperV.
Now RDP into the Azure VM `pckr-01.westeurope.cloudapp.azure.com` (the dns_prefix is specified in `variables.tf`). Open a PowerShell terminal and clone my packer-windows repo or any other repo with a Packer template for HyperV.
```
git clone https://github.com/StefanScherer/packer-windows
......
......@@ -10,43 +10,44 @@ Function SetupPhase1 {
New-ItemProperty -Path HKCU:\Software\Microsoft\ServerManager -Name DoNotOpenServerManagerAtLogon -PropertyType DWORD -Value "1" -Force
Write-Output "Installing Chocolatey"
Write-Host "Installing Chocolatey"
iex (wget 'https://chocolatey.org/install.ps1' -UseBasicParsing)
choco feature disable --name showDownloadProgress
choco install -y git
choco install -y packer
choco install -y vagrant
Write-Output "Installing Hyper-V"
Write-Host "Installing Hyper-V"
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart
Install-WindowsFeature Hyper-V-Tools
Install-WindowsFeature Hyper-V-PowerShell
#Write-Output Install all Windows Updates
#Write-Host Install all Windows Updates
#Get-Content C:\windows\system32\en-us\WUA_SearchDownloadInstall.vbs | ForEach-Object {
# $_ -replace 'confirm = msgbox.*$', 'confirm = vbNo'
#} | Out-File $env:TEMP\WUA_SearchDownloadInstall.vbs
#"a`na" | cscript $env:TEMP\WUA_SearchDownloadInstall.vbs
Write-Output "Rebooting"
Write-Host "Rebooting"
Restart-Computer
}
Function SetupPhase2 {
Write-Output "Adding NAT"
Write-Host "Adding NAT"
New-VMSwitch -SwitchName "packer-hyperv-iso" -SwitchType Internal
New-NetIPAddress -IPAddress 192.168.0.1 -PrefixLength 24 -InterfaceIndex (Get-NetAdapter -name "vEthernet (packer-hyperv-iso)").ifIndex
New-NetNat -Name MyNATnetwork -InternalIPInterfaceAddressPrefix 192.168.0.0/24
Write-Output "Adding DHCP scope"
Write-Host "Adding DHCP scope"
Install-WindowsFeature DHCP -IncludeManagementTools
Add-DhcpServerv4Scope -Name "Internal" -StartRange 192.168.0.10 -EndRange 192.168.0.250 -SubnetMask 255.255.255.0 -Description "Internal Network"
Set-DhcpServerv4OptionValue -ScopeID 192.168.0 -DNSServer 8.8.8.8 -Router 192.168.0.1
Write-Output "Disabling autologon"
Write-Host "Disabling autologon"
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoAdminLogon -PropertyType DWORD -Value "0" -Force
Write-Output "Removing scheduled job"
Write-Host "Removing scheduled job"
Unregister-ScheduledJob -Name NewServerSetupResume -Force
}
......
......@@ -9,7 +9,6 @@ variable "dns_prefix" {
}
variable "location" {
// default = "northeurope"
default = "westeurope"
}
......@@ -27,13 +26,9 @@ variable "admin_password" {
}
variable "count" {
type = "map"
default = {
windows = "1"
}
default = 1
}
variable "vm_size" {
default = "Standard_D2_v3"
default = "Standard_E2s_v3"
}
......@@ -14,7 +14,7 @@ resource "azurerm_subnet" "windows" {
}
resource "azurerm_network_interface" "windows" {
count = "${var.count["windows"]}"
count = "${var.count}"
name = "windows-${format("%02d", count.index + 1)}-nic"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.global.name}"
......@@ -28,8 +28,8 @@ resource "azurerm_network_interface" "windows" {
}
resource "azurerm_public_ip" "windows" {
count = "${var.count["windows"]}"
domain_name_label = "${var.dns_prefix}-win-${format("%02d", count.index + 1)}"
count = "${var.count}"
domain_name_label = "${var.dns_prefix}-${format("%02d", count.index + 1)}"
idle_timeout_in_minutes = 30
location = "${var.location}"
name = "windows-${format("%02d", count.index + 1)}-publicip"
......@@ -39,14 +39,14 @@ resource "azurerm_public_ip" "windows" {
resource "azurerm_storage_container" "windows" {
container_access_type = "private"
count = "${var.count["windows"]}"
count = "${var.count}"
name = "windows-${format("%02d", count.index + 1)}-storage"
resource_group_name = "${azurerm_resource_group.global.name}"
storage_account_name = "${azurerm_storage_account.global.name}"
}
resource "azurerm_virtual_machine" "windows" {
count = "${var.count["windows"]}"
count = "${var.count}"
name = "windows-${format("%02d", count.index + 1)}-vm"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.global.name}"
......@@ -68,10 +68,10 @@ resource "azurerm_virtual_machine" "windows" {
}
os_profile {
computer_name = "${var.dns_prefix}-win-${format("%02d", count.index + 1)}"
computer_name = "${var.dns_prefix}-${format("%02d", count.index + 1)}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
custom_data = "${base64encode("Param($HostName = \"${var.dns_prefix}-win-${format("%02d", count.index + 1)}.${var.location}.${var.azure_dns_suffix}\", $Username=\"${var.admin_username}\", $Password=\"${var.admin_password}\") ${file("./provision.ps1")}")}"
custom_data = "${base64encode("Param($HostName = \"${var.dns_prefix}-${format("%02d", count.index + 1)}.${var.location}.${var.azure_dns_suffix}\", $Username=\"${var.admin_username}\", $Password=\"${var.admin_password}\") ${file("./provision.ps1")}")}"
}
os_profile_windows_config {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment