forked from brikis98/terraform-up-and-running-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request brikis98#36 from brikis98/2nd-edition
2nd edition
- Loading branch information
Showing
356 changed files
with
7,942 additions
and
1,743 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
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 @@ | ||
[webservers] | ||
11.11.11.11 | ||
11.11.11.12 | ||
11.11.11.13 | ||
11.11.11.14 | ||
11.11.11.15 |
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 @@ | ||
- hosts: webservers | ||
roles: | ||
- webserver |
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 @@ | ||
- ec2: | ||
count: 10 | ||
image: ami-0c55b159cbfafe1f0 | ||
instance_type: t2.micro | ||
|
||
- ec2: | ||
count: 5 | ||
image: ami-0c55b159cbfafe1f0 | ||
instance_type: t2.micro |
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,17 @@ | ||
- name: Update the apt-get cache | ||
apt: | ||
update_cache: yes | ||
|
||
- name: Install PHP | ||
apt: | ||
name: php | ||
|
||
- name: Install Apache | ||
apt: | ||
name: apache2 | ||
|
||
- name: Copy the code from the repository | ||
git: repo=https://github.com/brikis98/php-app.git dest=/var/www/html/app | ||
|
||
- name: Start Apache | ||
service: name=apache2 state=started enabled=yes |
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
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 @@ | ||
def example_function() | ||
puts "Hello, World" | ||
end | ||
|
||
# Other places in your code | ||
example_function() |
6 changes: 6 additions & 0 deletions
6
code/ruby/04-terraform-modules/function-with-input-and-output-params-example.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,6 @@ | ||
def example_function(param1, param2) | ||
return "Hello, #{param1} #{param2}" | ||
end | ||
|
||
# Other places in your code | ||
return_value = example_function("foo", "bar") |
6 changes: 6 additions & 0 deletions
6
code/ruby/04-terraform-modules/function-with-input-params-example.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,6 @@ | ||
def example_function(param1, param2) | ||
puts "Hello, #{param1} #{param2}" | ||
end | ||
|
||
# Other places in your code | ||
example_function("foo", "bar") |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
code/ruby/07-testing-terraform-code/web-server-basic-test.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,49 @@ | ||
require_relative "web-server-basic" | ||
require "test/unit" | ||
require 'webrick' | ||
require 'net/http' | ||
|
||
class TestWebServer < Test::Unit::TestCase | ||
def test_integration_hello | ||
do_integration_test('/', lambda { |response| | ||
assert_equal(200, response.code.to_i) | ||
assert_equal('text/plain', response['Content-Type']) | ||
assert_equal('Hello, World', response.body) | ||
}) | ||
end | ||
|
||
def test_integration_api | ||
do_integration_test('/api', lambda { |response| | ||
assert_equal(201, response.code.to_i) | ||
assert_equal('application/json', response['Content-Type']) | ||
assert_equal('{"foo":"bar"}', response.body) | ||
}) | ||
end | ||
|
||
def test_integration_404 | ||
do_integration_test('/invalid-path', lambda { |response| | ||
assert_equal(404, response.code.to_i) | ||
assert_equal('text/plain', response['Content-Type']) | ||
assert_equal('Not Found', response.body) | ||
}) | ||
end | ||
|
||
def do_integration_test(path, check_response) | ||
port = 8002 | ||
server = WEBrick::HTTPServer.new :Port => port | ||
server.mount '/', WebServer | ||
|
||
begin | ||
thread = Thread.new do | ||
server.start | ||
end | ||
|
||
uri = URI("http://localhost:#{port}#{path}") | ||
response = Net::HTTP.get_response(uri) | ||
check_response.call(response) | ||
ensure | ||
server.shutdown | ||
thread.join | ||
end | ||
end | ||
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,34 @@ | ||
require 'webrick' | ||
|
||
class WebServer < WEBrick::HTTPServlet::AbstractServlet | ||
def do_GET(request, response) | ||
case request.path | ||
when "/" | ||
response.status = 200 | ||
response['Content-Type'] = 'text/plain' | ||
response.body = 'Hello, World' | ||
when "/api" | ||
response.status = 201 | ||
response['Content-Type'] = 'application/json' | ||
response.body = '{"foo":"bar"}' | ||
else | ||
response.status = 404 | ||
response['Content-Type'] = 'text/plain' | ||
response.body = 'Not Found' | ||
end | ||
end | ||
end | ||
|
||
# This will only run if this script was called directly from the CLI, but | ||
# not if it was required from another file | ||
if __FILE__ == $0 | ||
# Run the server on localhost at port 8000 | ||
server = WEBrick::HTTPServer.new :Port => 8000 | ||
server.mount '/', WebServer | ||
|
||
# Shut down the server on CTRL+C | ||
trap 'INT' do server.shutdown end | ||
|
||
# Start the server | ||
server.start | ||
end |
Oops, something went wrong.