variable "admin_password" {}
variable "ami" {}
variable "aws_instance_type" {}
variable "key_name" {}
variable "user_data_path" {}
provider "aws" {
region = "us-west-1"
}
data "template_file" "init" {
template = <<EOF
<powershell>
$admin = [ADSI]("WinNT://./administrator, user")
$admin.SetPassword("${var.admin_password}")
Set-DNSClientServerAddress –interfaceIndex 12 –ServerAddresses (“172.31.2.31”,”172.31.22.29”)
$NewComputerName = "win2016-test"
Rename-Computer -NewName $NewComputerName
Start-Sleep -Seconds 5
Restart-Computer -Force
</powershell>
EOF
vars = {
admin_password = "${var.admin_password}"
}
}
resource "aws_instance" "ec2" {
ami = var.ami
instance_type = var.aws_instance_type
key_name = var.key_name
user_data = data.template_file.init.rendered
connection {
host = coalesce(self.public_ip, self.private_ip)
type = "winrm"
user = "Administrator"
password = var.admin_password
}
tags = {
Srv = "windows"
}
}
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/52a55097-94cd-4106-92d4-cd914db78d1bn%40googlegroups.com.
resource "aws_ssm_document" "join_domain_doc" {
name = "join_domain_doc"
document_type = "Command"
content = <<DOC
{
"schemaVersion": "1.0",
"description": "Join an instance to a domain",
"runtimeConfig": {
"aws:domainJoin": {
"properties": {
"directoryId": "${aws_directory_service_directory.AD.id}",
"directoryName": "${var.dir_domain_name}",
"directoryOU": "${var.dir_computer_ou}",
"dnsIpAddresses": ["172.31.2.172", "172.31.31.146"]
}
}
}
}
DOC
depends_on = ["aws_directory_service_directory.AD"]
}
resource "aws_ssm_association" "join_domain_doc" {
name = "join_domain_doc"
instance_id = "${aws_instance.ec2.id}"
depends_on = ["aws_ssm_document.join_domain_doc", "aws_instance.ec2"]
}
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/f2a7919c-b322-4f8e-9587-5cf27e59609dn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CALmkhkoXDAS1hLaHCa7_AE9z4obP_BkBQzpLNvULaZUF95UqbQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/81ab99cd-41fe-44ee-8f8e-53d50a314b1en%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/fbd10ab9-421d-4346-84aa-c09a769da301n%40googlegroups.com.
resource "aws_ssm_document" "join_domain" {
name = "join_domain"
document_type = "Command"
content = <<DOC
{
"schemaVersion": "2.0",
"description": "Run a PowerShell script to securely domain-join a Windows instance",
"mainSteps": [{
"action": "aws:runPowerShellScript",
"name": "runPowerShellWithSecureString",
"inputs": {
"runCommand": [
"$ipdns = (Get-SSMParameterValue -Name /domain/dns_ip).Parameters[0].Value\n",
"$domain = (Get-SSMParameterValue -Name /domain/name).Parameters[0].Value\n",
"$ouPath = (Get-SSMParameterValue -Name /domain/ou_path).Parameters[0].Value\n",
"$username = (Get-SSMParameterValue -Name /domain/username).Parameters[0].Value\n",
"$domain_username = \"$domain\\$username\"\n",
"echo $domain_username\n",
"$password = (Get-SSMParameterValue -Name /domain/password -WithDecryption $True).Parameters[0].Value | ConvertTo-SecureString -asPlainText -Force\n",
"$credential = New-Object System.Management.Automation.PSCredential($domain_username,$password)\n",
"Set-DnsClientServerAddress \"Ethernet\" -ServerAddresses $ipdns\n",
"Add-Computer -DomainName $domain -OUPath \"$ouPath\" -Credential $credential\n",
"Restart-Computer -Force"
]
}
}]
}
DOC
depends_on = ["aws_directory_service_directory.AD"]
}
resource "aws_ssm_association" "join_domain" {
name = "join_domain"
targets {
key = "InstanceIds"
values = ["${aws_instance.ec2.id}"]
}
}
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAJQCwJxTKo0QJfONDgnn%2BefJdh2Aouo_9yCx6yZ76DfirrzkeQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CALmkhkpOY3xktAqJcvFw9Udb1CrnqT7wXSwnSwibmZmwgmhO%2Bw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAM7yfUBsW%3Do48fWsSpyOsDfLqKdczmHaFDp%2Btv6fwbeTi_6EQw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAJQCwJyb%3DdNN41iC_FdoAfbNUr3bR6ECKbq8C5z1ZQ9NuAui-w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CALmkhkpGpaLLAPHukL4Xp9riamF2uibSuuMMUzgJMsc1Xg7EWQ%40mail.gmail.com.