-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Patrick Wright <[email protected]>
- Loading branch information
Patrick Wright
committed
Aug 16, 2017
1 parent
d52b50c
commit d3048e7
Showing
12 changed files
with
173 additions
and
5 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
acceptance/windows-server-2012r2-once/.acceptance/acceptance-cookbook/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
nodes/ | ||
tmp/ |
2 changes: 2 additions & 0 deletions
2
acceptance/windows-server-2012r2-once/.acceptance/acceptance-cookbook/metadata.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name 'acceptance-cookbook' | ||
|
3 changes: 3 additions & 0 deletions
3
acceptance/windows-server-2012r2-once/.acceptance/acceptance-cookbook/recipes/destroy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
execute "terraform destroy -force" do | ||
cwd "#{node['chef-acceptance']['suite-dir']}/terraform" | ||
end |
12 changes: 12 additions & 0 deletions
12
acceptance/windows-server-2012r2-once/.acceptance/acceptance-cookbook/recipes/provision.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
execute "bundle exec ruby -e \"require 'mixlib/install'; puts Mixlib::Install.install_ps1, 'install -install_strategy once'\" > ../.acceptance_data/powershell_install_once.ps1" do | ||
cwd node['chef-acceptance']['suite-dir'] | ||
end | ||
|
||
execute "terraform plan" do | ||
cwd "#{node['chef-acceptance']['suite-dir']}/terraform" | ||
end | ||
|
||
execute "terraform apply" do | ||
cwd "#{node['chef-acceptance']['suite-dir']}/terraform" | ||
end | ||
|
14 changes: 14 additions & 0 deletions
14
acceptance/windows-server-2012r2-once/.acceptance/acceptance-cookbook/recipes/verify.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ruby_block "get ip" do | ||
block do | ||
tf_state = JSON.parse(File.read("#{node['chef-acceptance']['suite-dir']}/terraform/terraform.tfstate")) | ||
node.default["ip"] = tf_state["modules"].first["resources"]["aws_instance.mixlib_install_ps1"]["primary"]["attributes"]["public_ip"] | ||
end | ||
end | ||
|
||
execute "run inspec" do | ||
command lazy { "inspec exec verify.rb -t winrm://Administrator@#{node['ip']} --password $WINDOWS_PASSWORD" } | ||
cwd "#{node['chef-acceptance']['suite-dir']}/inspec" | ||
environment( | ||
"WINDOWS_PASSWORD" => ENV["TF_VAR_admin_password"] || "Pas5w0rD" | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe package("Chef Client v13*") do | ||
it { should be_installed } | ||
end | ||
|
||
describe command("powershell.exe -file /tmp/install.ps1") do | ||
its("stdout") { should match "Nothing to install" } | ||
end |
89 changes: 89 additions & 0 deletions
89
acceptance/windows-server-2012r2-once/terraform/application.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
data "aws_ami" "windows_ami" { | ||
most_recent = true | ||
|
||
filter { | ||
name = "owner-alias" | ||
values = ["amazon"] | ||
} | ||
|
||
filter { | ||
name = "name" | ||
values = ["Windows_Server-2012-R2*-English-*-Base-*"] | ||
} | ||
|
||
filter { | ||
name = "architecture" | ||
values = ["x86_64"] | ||
} | ||
|
||
filter { | ||
name = "virtualization-type" | ||
values = ["hvm"] | ||
} | ||
|
||
filter { | ||
name = "block-device-mapping.volume-type" | ||
values = ["gp2"] | ||
} | ||
|
||
filter { | ||
name = "image-type" | ||
values = ["machine"] | ||
} | ||
} | ||
|
||
resource "aws_instance" "mixlib_install_ps1" { | ||
count = 1 | ||
|
||
ami = "${data.aws_ami.windows_ami.id}" | ||
instance_type = "${var.aws_instance_type}" | ||
key_name = "es-infrastructure" | ||
|
||
associate_public_ip_address = true | ||
|
||
subnet_id = "subnet-11ac0174" # Planet Releng Public Subnet | ||
source_dest_check = false | ||
|
||
vpc_security_group_ids = [ | ||
"sg-96274af3", | ||
] | ||
|
||
connection { | ||
type = "winrm" | ||
user = "Administrator" | ||
password = "${var.admin_password}" | ||
timeout = "10m" | ||
} | ||
|
||
user_data = <<EOF | ||
<script> | ||
winrm quickconfig -q & winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"} & winrm set winrm/config @{MaxTimeoutms="1800000"} & winrm set winrm/config/service @{AllowUnencrypted="true"} & winrm set winrm/config/service/auth @{Basic="true"} | ||
</script> | ||
<powershell> | ||
Set-ExecutionPolicy -ExecutionPolicy Bypass | ||
netsh advfirewall firewall add rule name="WinRM in" protocol=TCP dir=in profile=any localport=5985 remoteip=any localip=any action=allow | ||
$admin = [adsi]("WinNT://./administrator, user") | ||
$admin.psbase.invoke("SetPassword", "${var.admin_password}") | ||
</powershell> | ||
EOF | ||
|
||
tags { | ||
# ChefOps's AWS standard tags: | ||
X-Dept = "EngServ" | ||
X-Contact = "pwright" | ||
X-Production = "false" | ||
X-Environment = "acceptance" | ||
X-Application = "mixlib-install" | ||
} | ||
|
||
provisioner "file" { | ||
source = "../../.acceptance_data/powershell_install_once.ps1" | ||
destination = "/tmp/install.ps1" | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"powershell.exe -file /tmp/install.ps1", | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Restrict operation of terraform to chef-es profile so that | ||
# we do not create resources in other aws profiles. | ||
# We assume user has configured standard aws credentials | ||
# under ~/.aws/credentials or with $AWS_SHARED_CREDENTIALS_FILE | ||
provider "aws" { | ||
region = "${var.aws_region}" | ||
profile = "chef-aws" | ||
} |
16 changes: 16 additions & 0 deletions
16
acceptance/windows-server-2012r2-once/terraform/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Region to create infrastructure in | ||
variable "aws_region" { | ||
type = "string" | ||
default = "us-west-2" | ||
} | ||
|
||
variable "aws_instance_type" { | ||
type = "string" | ||
default = "t2.micro" | ||
} | ||
|
||
variable "admin_password" { | ||
description = "Set Windows Administrator password" | ||
type = "string" | ||
default = "Pas5w0rD" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,4 +174,4 @@ function Get-WMIQuery { | |
else { | ||
Get-WmiObject $class | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters