# ==========================================================
# SCRIPTING TAAK 2 - IIS Web Server Automation (Timed Access)
# Author : Lorenzo Meli
# Target : Windows Server 2025
# Description : IIS site runs only Mon-Fri from 08:00–20:00
# ==========================================================
terraform {
required_providers {
local = { source = "hashicorp/local" }
null = { source = "hashicorp/null" }
}
}
provider "local" {}
provider "null" {}
# 1️⃣Create IIS installation PowerShell script
resource "local_file" "install_script" {
filename = "C:/Terraform_IIS_Lorenzo/install_iis.ps1"
content = <<-EOT
Import-Module ServerManager
Write-Host "Installing IIS..."
Install-WindowsFeature -Name Web-Server -IncludeManagementTools
# Create simple homepage
$html = @"
<html>
<head><title>IIS Terraform Automation</title></head>
<body style='font-family:Arial; text-align:center; margin-top:100px;'>
<h1>Hello from Terraform!</h1>
<h2>SCRIPTING TAAK 2 - Lorenzo Meli</h2>
<p>Website active during working hours (08:00–20:00, Mon–Fri).</p>
</body>
</html>
"@
$path = "C:\\inetpub\\wwwroot\\index.html"
$html | Out-File $path -Encoding UTF8 -Force
Start-Service W3SVC
Write-Host "✅ IIS installed and started successfully."
EOT
}
# 2️⃣ Script to start IIS (for scheduler)
resource "local_file" "start_script" {
filename = "C:/Terraform_IIS_Lorenzo/start_iis.ps1"
content = <<-EOT
Import-Module WebAdministration
Start-Service W3SVC
Start-Website -Name "Default Web Site"
Write-Host "IIS started (weekday start script)."
EOT
}
# 3️⃣Script to stop IIS (for scheduler)
resource "local_file" "stop_script" {
filename = "C:/Terraform_IIS_Lorenzo/stop_iis.ps1"
content = <<-EOT
# SCRIPTING TAAK 2 - IIS Web Server Automation (Timed Access)
# Author : Lorenzo Meli
# Target : Windows Server 2025
# Description : IIS site runs only Mon-Fri from 08:00–20:00
# ==========================================================
terraform {
required_providers {
local = { source = "hashicorp/local" }
null = { source = "hashicorp/null" }
}
}
provider "local" {}
provider "null" {}
# 1️⃣Create IIS installation PowerShell script
resource "local_file" "install_script" {
filename = "C:/Terraform_IIS_Lorenzo/install_iis.ps1"
content = <<-EOT
Import-Module ServerManager
Write-Host "Installing IIS..."
Install-WindowsFeature -Name Web-Server -IncludeManagementTools
# Create simple homepage
$html = @"
<html>
<head><title>IIS Terraform Automation</title></head>
<body style='font-family:Arial; text-align:center; margin-top:100px;'>
<h1>Hello from Terraform!</h1>
<h2>SCRIPTING TAAK 2 - Lorenzo Meli</h2>
<p>Website active during working hours (08:00–20:00, Mon–Fri).</p>
</body>
</html>
"@
$path = "C:\\inetpub\\wwwroot\\index.html"
$html | Out-File $path -Encoding UTF8 -Force
Start-Service W3SVC
Write-Host "✅ IIS installed and started successfully."
EOT
}
# 2️⃣ Script to start IIS (for scheduler)
resource "local_file" "start_script" {
filename = "C:/Terraform_IIS_Lorenzo/start_iis.ps1"
content = <<-EOT
Import-Module WebAdministration
Start-Service W3SVC
Start-Website -Name "Default Web Site"
Write-Host "IIS started (weekday start script)."
EOT
}
# 3️⃣Script to stop IIS (for scheduler)
resource "local_file" "stop_script" {
filename = "C:/Terraform_IIS_Lorenzo/stop_iis.ps1"
content = <<-EOT