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.
- Loading branch information
Showing
56 changed files
with
2,000 additions
and
148 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,17 @@ | ||
# setup-webserver.sh | ||
|
||
This folder contains an example of a Bash script that can be used to install and Apache, PHP, and a sample PHP app | ||
on an Ubuntu server. | ||
|
||
For more info, please see Chapter 1, "Why Terraform", of | ||
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*. | ||
|
||
## Pre-requisites | ||
|
||
This script should be run on an Ubuntu server. | ||
|
||
## Quick start | ||
|
||
``` | ||
./setup-webserver.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,18 @@ | ||
# run-webserver.sh | ||
|
||
This folder contains an example of a Bash script that can be used to start a web server that listens on port 8080 | ||
and returns the text "Hello, World" for the URL `/`. | ||
|
||
For more info, please see Chapter 2, "An Introduction to Terraform Syntax", of | ||
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*. | ||
|
||
## Pre-requisites | ||
|
||
You must have [busybox](https://busybox.net/) installed on your computer. | ||
|
||
## Quick start | ||
|
||
``` | ||
./run-webserver.sh | ||
curl http://localhost: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,19 @@ | ||
# bash-unit-test-example.sh | ||
|
||
This folder shows how extracting your [User Data | ||
script](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html) into a separate file allows you to write | ||
unit tests for that file. The folder contains a sample `user-data.sh` Bash script, which fires up a web server on port | ||
8080, plus a simple unit test for it, `bash-unit-test-example.sh`, that runs that server and checks that it works. | ||
|
||
For more info, please see Chapter 3, "How to Manage Terraform State", of | ||
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*. | ||
|
||
## Pre-requisites | ||
|
||
You must have [busybox](https://busybox.net/) installed on your computer. | ||
|
||
## Quick start | ||
|
||
``` | ||
./bash-unit-test-example.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
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 @@ | ||
# Packer example | ||
|
||
This folder shows an example [Packer](https://www.packer.io/) template that can be used to create an [Amazon Machine | ||
Image (AMI)](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html) of an Ubuntu server with Apache, PHP, and | ||
a sample PHP app installed. | ||
|
||
For more info, please see Chapter 1, "Why Terraform", of | ||
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*. | ||
|
||
## Pre-requisites | ||
|
||
* You must have [Packer](https://www.packer.io/) installed on your computer. | ||
* You must have an [Amazon Web Services (AWS) account](http://aws.amazon.com/). | ||
|
||
## Quick start | ||
|
||
**Please note that this example will deploy real resources into your AWS account. We have made every effort to ensure | ||
all the resources qualify for the [AWS Free Tier](https://aws.amazon.com/free/), but we are not responsible for any | ||
charges you may incur.** | ||
|
||
Configure your [AWS access | ||
keys](http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) as | ||
environment variables: | ||
|
||
``` | ||
export AWS_ACCESS_KEY_ID=(your access key id) | ||
export AWS_SECRET_ACCESS_KEY=(your secret access key) | ||
``` | ||
|
||
To build the AMI: | ||
|
||
``` | ||
packer build webserver.json | ||
``` |
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,48 @@ | ||
# Terraform automated test example | ||
|
||
This folder shows an example of how to write automated tests for a web server cluster defined in | ||
[Terraform](https://www.terraform.io/) templates. The folder contains a Ruby script, `terraform-test.rb`, that will | ||
apply your Terraform templates and then test the web server cluster URL to make sure it returns "Hello, World". | ||
|
||
For more info, please see Chapter 6, "How to use Terraform as a Team", of | ||
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*. | ||
|
||
## Pre-requisites | ||
|
||
* You must have [Ruby](https://www.ruby-lang.org/) installed on your computer. | ||
* You must have [Terraform](https://www.terraform.io/) installed on your computer. | ||
* You must have an [Amazon Web Services (AWS) account](http://aws.amazon.com/). | ||
|
||
## Quick start | ||
|
||
**Please note that this example will deploy real resources into your AWS account. We have made every effort to ensure | ||
all the resources qualify for the [AWS Free Tier](https://aws.amazon.com/free/), but we are not responsible for any | ||
charges you may incur.** | ||
|
||
Configure your [AWS access | ||
keys](http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) as | ||
environment variables: | ||
|
||
``` | ||
export AWS_ACCESS_KEY_ID=(your access key id) | ||
export AWS_SECRET_ACCESS_KEY=(your secret access key) | ||
``` | ||
|
||
Deploy a test database of some sort that the web server cluster can connect to. For example, you could deploy the | ||
Terraform templates under | ||
[code/terraform/06-terraform-team/live/stage/data-stores/mysql](/code/terraform/06-terraform-team/live/stage/data-stores/mysql). | ||
Make sure to note down the AWS region you're deploying into (e.g. `us-east-1`) as well as the S3 bucket name (e.g. | ||
`my-terraform-state`) and key (e.g. `qa/stage/data-stores/mysql/terraform.tfstate`) you use to store the remote state | ||
data of the database. | ||
|
||
To run the Ruby automated test, navigate to a folder that contains the web server cluster templates, such as | ||
[code/terraform/06-terraform-team/live/stage/services/webserver-cluster](/code/terraform/06-terraform-team/live/stage/services/webserver-cluster), | ||
and run the following: | ||
|
||
``` | ||
ruby \ | ||
../../../../../../ruby/06-terraform-team/terraform-test.rb \ | ||
us-east-1 \ | ||
my-terraform-state \ | ||
qa/stage/data-stores/mysql/terraform.tfstate | ||
``` |
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,46 @@ | ||
# Terraform "Hello, World" example | ||
|
||
This folder contains a "Hello, World" example of a [Terraform](https://www.terraform.io/) template. The template | ||
deploys a single server in an [Amazon Web Services (AWS) account](http://aws.amazon.com/). | ||
|
||
For more info, please see the preface of *[Terraform: Up and Running](http://www.terraformupandrunning.com)*. | ||
|
||
## Pre-requisites | ||
|
||
* You must have [Terraform](https://www.terraform.io/) installed on your computer. | ||
* You must have an [Amazon Web Services (AWS) account](http://aws.amazon.com/). | ||
|
||
Please note that this code was written for Terraform {{ terraform_version }}. | ||
|
||
## Quick start | ||
|
||
**Please note that this example will deploy real resources into your AWS account. We have made every effort to ensure | ||
all the resources qualify for the [AWS Free Tier](https://aws.amazon.com/free/), but we are not responsible for any | ||
charges you may incur.** | ||
|
||
Configure your [AWS access | ||
keys](http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) as | ||
environment variables: | ||
|
||
``` | ||
export AWS_ACCESS_KEY_ID=(your access key id) | ||
export AWS_SECRET_ACCESS_KEY=(your secret access key) | ||
``` | ||
|
||
Validate the templates: | ||
|
||
``` | ||
terraform plan | ||
``` | ||
|
||
Deploy the code: | ||
|
||
``` | ||
terraform apply | ||
``` | ||
|
||
Clean up when you're done: | ||
|
||
``` | ||
terraform destroy | ||
``` |
9 changes: 0 additions & 9 deletions
9
code/terraform/01-why-terraform/declarative-examples/part-1/main.tf
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
code/terraform/01-why-terraform/declarative-examples/part-2/main.tf
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
code/terraform/01-why-terraform/declarative-examples/part-3/main.tf
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
code/terraform/01-why-terraform/multi-provider-example/main.tf
This file was deleted.
Oops, something went wrong.
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 @@ | ||
# Server, DB, ELB Example | ||
|
||
This folder contains an example [Terraform](https://www.terraform.io/) template that deploys a server (using | ||
[EC2](https://aws.amazon.com/ec2/)), database (using [RDS](https://aws.amazon.com/rds/)), and | ||
load balancer (using [ELB](https://aws.amazon.com/elasticloadbalancing/)) in an [Amazon Web Services (AWS) | ||
account](http://aws.amazon.com/). | ||
|
||
For more info, please see Chapter 1, "Why Terraform", of | ||
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*. | ||
|
||
## Pre-requisites | ||
|
||
* You must have [Terraform](https://www.terraform.io/) installed on your computer. | ||
* You must have an [Amazon Web Services (AWS) account](http://aws.amazon.com/). | ||
|
||
Please note that this code was written for Terraform {{ terraform_version }}. | ||
|
||
## Quick start | ||
|
||
**Please note that this example will deploy real resources into your AWS account. We have made every effort to ensure | ||
all the resources qualify for the [AWS Free Tier](https://aws.amazon.com/free/), but we are not responsible for any | ||
charges you may incur.** | ||
|
||
Configure your [AWS access | ||
keys](http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) as | ||
environment variables: | ||
|
||
``` | ||
export AWS_ACCESS_KEY_ID=(your access key id) | ||
export AWS_SECRET_ACCESS_KEY=(your secret access key) | ||
``` | ||
|
||
Validate the templates: | ||
|
||
``` | ||
terraform plan | ||
``` | ||
|
||
Deploy the code: | ||
|
||
``` | ||
terraform apply | ||
``` | ||
|
||
Clean up when you're done: | ||
|
||
``` | ||
terraform destroy | ||
``` |
Oops, something went wrong.