resource "aws_instance" "windows10" { ami = var.ami_id instance_type = var.instance_type key_name = var.key_name subnet_id = var.subnet_id security_groups = var.vpc_security_group_ids user_data = <<-EOF # Enable RDP Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" -Value 0 Enable-NetFirewallRule -DisplayGroup "Remote Desktop" # Set the Domain Name and Credentials $domain = "${var.domain_name}" $username = "${var.domain_admin_user}" $password = ConvertTo-SecureString "${var.domain_admin_password}" -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ("$domain\\$username", $password) # Join the domain Add-Computer -DomainName $domain -Credential $credential -Force -Restart EOF tags = { Name = "Windows10-DomainJoined" } }