-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
107 changed files
with
1,945 additions
and
0 deletions.
There are no files selected for viewing
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,19 @@ | ||
#!/bin/bash | ||
# A script that configures a web server | ||
|
||
set -e | ||
|
||
# Update the apt-get cache | ||
sudo apt-get update | ||
|
||
# Install PHP | ||
sudo apt-get install -y php | ||
|
||
# Install Apache | ||
sudo apt-get install -y apache2 | ||
|
||
# Copy the code from repository | ||
sudo git clone https://github.com/brikis98/php-app.git /var/www/html/app | ||
|
||
# Start Apache | ||
sudo service apache2 start |
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 @@ | ||
#!/bin/bash | ||
echo "Hello, World" > index.html | ||
nohup busybox httpd -f -p 8080 & |
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,13 @@ | ||
#!/bin/bash | ||
|
||
export db_address=12.34.56.78 | ||
export db_port=5555 | ||
export server_port=8888 | ||
|
||
./user-data.sh | ||
|
||
output=$(curl "http://localhost:$server_port") | ||
|
||
if [[ $output != *"Hello, World"* ]]; then | ||
echo "Did not get back expected text 'Hello, World'" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
cat > index.html <<EOF | ||
<h1>Hello, World</h1> | ||
<p>DB address: ${db_address}</p> | ||
<p>DB port: ${db_port}</p> | ||
EOF | ||
|
||
nohup busybox httpd -f -p "${server_port}" & |
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,19 @@ | ||
{ | ||
"builders": [{ | ||
"ami_name": "packer-example", | ||
"instance_type": "t2.micro", | ||
"region": "us-east-1", | ||
"type": "amazon-ebs", | ||
"source_ami": "ami-40d28157", | ||
"ssh_username": "ubuntu" | ||
}], | ||
"provisioners": [{ | ||
"type": "shell", | ||
"inline": [ | ||
"sudo apt-get update", | ||
"sudo apt-get install -y php", | ||
"sudo apt-get install -y apache2", | ||
"sudo git clone https://github.com/brikis98/php-app.git /var/www/html/app" | ||
] | ||
}] | ||
} |
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,44 @@ | ||
require 'net/http' | ||
|
||
if ARGV.length != 3 | ||
raise 'Invalid args. Usage: terraform-test.rb REGION DB_BUCKET DB_KEY' | ||
end | ||
|
||
vars = { | ||
# A unique (ish) 6-char string: http://stackoverflow.com/a/88341/483528 | ||
:cluster_name => (0...6).map { (65 + rand(26)).chr }.join, | ||
:aws_region => ARGV[0], | ||
:db_remote_state_bucket => ARGV[1], | ||
:db_remote_state_key => ARGV[2], | ||
} | ||
vars_string = vars.map{|key, value| "-var '#{key} = \"#{value}\"'"}.join(', ') | ||
|
||
begin | ||
puts "Deploying code in #{Dir.pwd}" | ||
puts `terraform get 2>&1` | ||
puts `terraform apply #{vars_string} 2>&1` | ||
|
||
elb_dns_name = `terraform output -no-color elb_dns_name` | ||
url = "http://#{elb_dns_name}/" | ||
|
||
retries = 0 | ||
loop do | ||
retries += 1 | ||
raise "Didn't get expected response after 10 retries" if retries > 10 | ||
|
||
puts "Checking #{url}" | ||
output = Net::HTTP.get(url) | ||
puts "Output: #{output}" | ||
|
||
if output.include? 'Hello, World' | ||
puts 'Success!' | ||
break | ||
end | ||
|
||
puts 'Sleeping for 30 seconds and trying again' | ||
sleep(30.seconds) | ||
end | ||
ensure | ||
puts "Undeploying code in #{Dir.pwd}" | ||
puts `terraform destroy -force #{vars_string} 2>&1` | ||
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,8 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
resource "aws_instance" "example" { | ||
ami = "ami-40d28157" | ||
instance_type = "t2.micro" | ||
} |
9 changes: 9 additions & 0 deletions
9
code/terraform/01-why-terraform/declarative-examples/part-1/main.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,9 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
resource "aws_instance" "example" { | ||
count = 10 | ||
ami = "ami-40d28157" | ||
instance_type = "t2.micro" | ||
} |
9 changes: 9 additions & 0 deletions
9
code/terraform/01-why-terraform/declarative-examples/part-2/main.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,9 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
resource "aws_instance" "example" { | ||
count = 15 | ||
ami = "ami-40d28157" | ||
instance_type = "t2.micro" | ||
} |
9 changes: 9 additions & 0 deletions
9
code/terraform/01-why-terraform/declarative-examples/part-3/main.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,9 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
resource "aws_instance" "example" { | ||
count = 15 | ||
ami = "ami-408c7f28" | ||
instance_type = "t2.micro" | ||
} |
20 changes: 20 additions & 0 deletions
20
code/terraform/01-why-terraform/multi-provider-example/main.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,20 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
provider "dnsimple" { | ||
token = "fake-token" | ||
email = "fake-email" | ||
} | ||
|
||
resource "aws_instance" "example" { | ||
ami = "ami-40d28157" | ||
instance_type = "t2.micro" | ||
} | ||
|
||
resource "dnsimple_record" "example" { | ||
domain = "example.com" | ||
name = "test" | ||
value = "${aws_instance.example.public_ip}" | ||
type = "A" | ||
} |
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,36 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
resource "aws_instance" "app" { | ||
instance_type = "t2.micro" | ||
availability_zone = "us-east-1a" | ||
ami = "ami-40d28157" | ||
|
||
user_data = <<-EOF | ||
#!/bin/bash | ||
sudo service apache2 start | ||
EOF | ||
} | ||
|
||
resource "aws_db_instance" "db" { | ||
allocated_storage = 10 | ||
engine = "mysql" | ||
instance_class = "db.t2.micro" | ||
name = "mydb" | ||
username = "admin" | ||
password = "password" | ||
} | ||
|
||
resource "aws_elb" "load_balancer" { | ||
name = "frontend-load-balancer" | ||
instances = ["${aws_instance.app.id}"] | ||
availability_zones = ["us-east-1a"] | ||
|
||
listener { | ||
instance_port = 8000 | ||
instance_protocol = "http" | ||
lb_port = 80 | ||
lb_protocol = "http" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
code/terraform/02-intro-to-terraform-syntax/one-server/main.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,12 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
resource "aws_instance" "example" { | ||
ami = "ami-40d28157" | ||
instance_type = "t2.micro" | ||
|
||
tags { | ||
name = "terraform-example" | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
code/terraform/02-intro-to-terraform-syntax/one-webserver-with-vars/main.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,30 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
resource "aws_instance" "example" { | ||
ami = "ami-40d28157" | ||
instance_type = "t2.micro" | ||
vpc_security_group_ids = ["${aws_security_group.instance.id}"] | ||
|
||
user_data = <<EOF | ||
#!/bin/bash | ||
echo "Hello, World" > index.html | ||
nohup busybox httpd -f -p "${var.server_port}" & | ||
EOF | ||
|
||
tags { | ||
Name = "terraform-example" | ||
} | ||
} | ||
|
||
resource "aws_security_group" "instance" { | ||
name = "terraform-example-instance" | ||
|
||
ingress { | ||
from_port = "${var.server_port}" | ||
to_port = "${var.server_port}" | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
code/terraform/02-intro-to-terraform-syntax/one-webserver-with-vars/outputs.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,3 @@ | ||
output "public_ip" { | ||
value = "${aws_instance.example.public_ip}" | ||
} |
21 changes: 21 additions & 0 deletions
21
code/terraform/02-intro-to-terraform-syntax/one-webserver-with-vars/vars.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,21 @@ | ||
variable "server_port" { | ||
description = "The port the server will use for HTTP requests" | ||
default = 8080 | ||
} | ||
|
||
variable "list_example" { | ||
description = "An example of a list in Terraform" | ||
type = "list" | ||
default = [1, 2, 3] | ||
} | ||
|
||
variable "map_example" { | ||
description = "An example of a map in Terraform" | ||
type = "map" | ||
|
||
default = { | ||
key1 = "value1" | ||
key2 = "value2" | ||
key3 = "value3" | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
code/terraform/02-intro-to-terraform-syntax/one-webserver/main.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,34 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
resource "aws_instance" "example" { | ||
ami = "ami-40d28157" | ||
instance_type = "t2.micro" | ||
vpc_security_group_ids = ["${aws_security_group.instance.id}"] | ||
|
||
user_data = <<-EOF | ||
#!/bin/bash | ||
echo "Hello, World" > index.html | ||
nohup busybox httpd -f -p 8080 & | ||
EOF | ||
|
||
tags { | ||
Name = "terraform-example" | ||
} | ||
} | ||
|
||
resource "aws_security_group" "instance" { | ||
name = "terraform-example-instance" | ||
|
||
ingress { | ||
from_port = 8080 | ||
to_port = 8080 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
} | ||
|
||
output "public_ip" { | ||
value = "${aws_instance.example.public_ip}" | ||
} |
Oops, something went wrong.