-
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
ff4390e
commit d52b50c
Showing
14 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
acceptance/ubuntu_install_command_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,8 @@ | ||
nodes/ | ||
tmp/ | ||
|
||
# Terraform | ||
*.tfstate | ||
*.tfstate.backup | ||
*_override.tf | ||
|
2 changes: 2 additions & 0 deletions
2
acceptance/ubuntu_install_command_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/ubuntu_install_command_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 |
11 changes: 11 additions & 0 deletions
11
acceptance/ubuntu_install_command_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,11 @@ | ||
execute "bundle exec ruby -e \"require 'mixlib/install'; puts Mixlib::Install.new(product_name: 'chef', product_version: :latest, channel: :stable, install_command_options: {install_strategy: 'once'}).install_command\" > ../.acceptance_data/ubuntu_install_command_once.sh" 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 |
11 changes: 11 additions & 0 deletions
11
acceptance/ubuntu_install_command_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,11 @@ | ||
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_sh"]["primary"]["attributes"]["public_ip"] | ||
end | ||
end | ||
|
||
execute "run inspec" do | ||
command lazy { "inspec exec verify.rb -t ssh://ubuntu@#{node['ip']} -i ~/.ssh/es-infrastructure.pem" } | ||
cwd "#{node['chef-acceptance']['suite-dir']}/inspec" | ||
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") do | ||
it { should be_installed } | ||
end | ||
|
||
describe command("/tmp/install.sh") do | ||
its("stdout") { should match "Nothing to install" } | ||
end |
78 changes: 78 additions & 0 deletions
78
acceptance/ubuntu_install_command_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,78 @@ | ||
data "aws_ami" "ubuntu_14_ami" { | ||
most_recent = true | ||
|
||
filter { | ||
name = "owner-id" | ||
values = ["099720109477"] | ||
} | ||
|
||
filter { | ||
name = "name" | ||
values = ["ubuntu/images/*/ubuntu-*-14.04-*-server-*"] | ||
} | ||
|
||
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_sh" { | ||
count = 1 | ||
|
||
ami = "${data.aws_ami.ubuntu_14_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 { | ||
user = "ubuntu" | ||
private_key = "${file("${var.connection_private_key}")}" | ||
agent = "${var.connection_agent}" | ||
timeout = "10m" | ||
} | ||
|
||
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/ubuntu_install_command_once.sh" | ||
destination = "/tmp/install.sh" | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"chmod +x /tmp/install.sh", | ||
"sudo bash /tmp/install.sh", | ||
] | ||
} | ||
} |
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" | ||
} |
27 changes: 27 additions & 0 deletions
27
acceptance/ubuntu_install_command_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,27 @@ | ||
# Region to create infrastructure in | ||
variable "aws_region" { | ||
type = "string" | ||
default = "us-west-2" | ||
} | ||
|
||
variable "aws_instance_type" { | ||
type = "string" | ||
default = "t2.micro" | ||
} | ||
|
||
# Used to indicidate whether the environment should be treated as "prod" | ||
# This is mainly used for the `X-Production` AWS tag. | ||
variable "production" { | ||
default = "false" | ||
} | ||
|
||
# SSH Connection info used for remote provisioning instances | ||
variable "connection_agent" { | ||
description = "Set to false to disable using ssh-agent to authenticate" | ||
default = false | ||
} | ||
|
||
variable "connection_private_key" { | ||
description = "File path to AWS keypair private key to provision with" | ||
default = "~/.ssh/es-infrastructure.pem" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
if test -d "/opt/$project" && test "x$install_strategy" = "xonce"; then | ||
echo "$project installation detected" | ||
echo "install_strategy set to 'once'" | ||
echo "Nothing to install" | ||
exit | ||
fi |
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
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