Skip to content

Commit

Permalink
Regenerate code with zero-downtime deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
brikis98 committed Nov 19, 2016
1 parent daa2235 commit 65faac5
Show file tree
Hide file tree
Showing 66 changed files with 745 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ resource "aws_instance" "example" {
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
#!/bin/bash
echo "Hello, World" > index.html
nohup busybox httpd -f -p "${var.server_port}" &
EOF

tags {
Name = "terraform-example"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ provider "aws" {
}

module "webserver_cluster" {
source = "[email protected]:brikis98/terraform-up-and-running-code.git//code/terraform/04-terraform-module/module-example/modules/services/webserver-cluster?ref=v0.0.1"
source = "[email protected]:brikis98/terraform-up-and-running-code.git//
code/terraform/04-terraform-module/module-example/modules/
services/webserver-cluster?ref=v0.0.1"

cluster_name = "webservers-stage"
db_remote_state_bucket = "${var.db_remote_state_bucket}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This folder contains example [Terraform](https://www.terraform.io/) templates th
these templates is to set the name of the IAM user to a name that already exists in your AWS account so you can
practice importing existing resources into Terraform state.

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, and Gotchas", of
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Pre-requisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This folder contains example [Terraform](https://www.terraform.io/) templates that create an
[IAM](https://aws.amazon.com/iam/) user in an [Amazon Web Services (AWS) account](http://aws.amazon.com/).

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, and Gotchas", of
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Pre-requisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This folder contains example [Terraform](https://www.terraform.io/) templates that create several
[IAM](https://aws.amazon.com/iam/) users in an [Amazon Web Services (AWS) account](http://aws.amazon.com/).

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, and Gotchas", of
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Pre-requisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This folder contains example [Terraform](https://www.terraform.io/) templates that create several
[IAM](https://aws.amazon.com/iam/) users in an [Amazon Web Services (AWS) account](http://aws.amazon.com/).

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, and Gotchas", of
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Pre-requisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This folder contains example [Terraform](https://www.terraform.io/) templates that deploy a MySQL database (using
[RDS](https://aws.amazon.com/rds/) in an [Amazon Web Services (AWS) account](http://aws.amazon.com/).

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, and Gotchas", of
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Pre-requisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ account](http://aws.amazon.com/). The load balancer listens on port 80 and retur
`/` URL. The code for the cluster and load balancer are defined as a Terraform module in
[modules/services/webserver-cluster](../../../../modules/services/webserver-cluster).

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, and Gotchas", of
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Pre-requisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This folder contains example [Terraform](https://www.terraform.io/) templates that deploy a MySQL database (using
[RDS](https://aws.amazon.com/rds/) in an [Amazon Web Services (AWS) account](http://aws.amazon.com/).

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, and Gotchas", of
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Pre-requisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This folder contains example [Terraform](https://www.terraform.io/) templates th
(using [EC2](https://aws.amazon.com/ec2/)). The goal of these templates is to demonstrate how to use the +count+
parameter in Terraform, as well as some of its limitations.

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, and Gotchas", of
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Pre-requisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ provider "aws" {
region = "us-east-1"
}

data "aws_availability_zones" "all" {}

resource "aws_instance" "example" {
count = 3
ami = "ami-40d28157"
instance_type = "t2.micro"
}

data "aws_availability_zones" "all" {}

resource "aws_instance" "example" {
count = "${var.num_availability_zones}"
availability_zone = "${element(data.aws_availability_zones.all.names, count.index)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ account](http://aws.amazon.com/). The load balancer listens on port 80 and retur
`/` URL. The code for the cluster and load balancer are defined as a Terraform module in
[modules/services/webserver-cluster](../../../../modules/services/webserver-cluster).

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, and Gotchas", of
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Pre-requisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Scaling](https://aws.amazon.com/autoscaling/)) and a load balancer (using
[ELB](https://aws.amazon.com/elasticloadbalancing/)) in an [Amazon Web Services (AWS) account](http://aws.amazon.com/).
The load balancer listens on port 80 and returns the text "Hello, World" for the `/` URL.

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, and Gotchas", of
For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Quick start
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# MySQL on RDS example (production environment)

This folder contains example [Terraform](https://www.terraform.io/) templates that deploy a MySQL database (using
[RDS](https://aws.amazon.com/rds/) in an [Amazon Web Services (AWS) account](http://aws.amazon.com/).

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", 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 [terragrunt](https://github.com/gruntwork-io/terragrunt) 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 0.7.x.

## 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)
```

Fill in the name of an [S3](https://aws.amazon.com/s3/) bucket to use for remote state storage in `.terragrunt`:

```hcl
bucket = "(YOUR_BUCKET_NAME)"
```

Validate the templates:

```
terragrunt plan
```

Deploy the code:

```
terragrunt apply
```

Clean up when you're done:

```
terragrunt destroy
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
provider "aws" {
region = "us-east-1"
}

resource "aws_db_instance" "example" {
engine = "mysql"
allocated_storage = 10
instance_class = "db.t2.micro"
name = "example_database_prod"
username = "admin"
password = "${var.db_password}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "address" {
value = "${aws_db_instance.example.address}"
}

output "port" {
value = "${aws_db_instance.example.port}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "db_password" {
description = "The password for the database"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Web server cluster example (production environment)

This folder contains example [Terraform](https://www.terraform.io/) templates that deploy a cluster of web servers
(using [EC2](https://aws.amazon.com/ec2/) and [Auto Scaling](https://aws.amazon.com/autoscaling/)) and a load balancer
(using [ELB](https://aws.amazon.com/elasticloadbalancing/)) in an [Amazon Web Services (AWS)
account](http://aws.amazon.com/). The load balancer listens on port 80 and returns the text "Hello, World" for the
`/` URL. The Auto Scaling Group will do a zero-downtime deployment whenever you change any parameters in this
module. The code for the cluster and load balancer are defined as a Terraform module in
[modules/services/webserver-cluster](../../../../modules/services/webserver-cluster).

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", 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 [terragrunt](https://github.com/gruntwork-io/terragrunt) installed on your computer.
* You must have an [Amazon Web Services (AWS) account](http://aws.amazon.com/).
* You must deploy the MySQL database in [data-stores/mysql](../../data-stores/mysql) BEFORE deploying the
templates in this folder.

Please note that this code was written for Terraform 0.7.x.

## 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)
```

Fill in the name of an [S3](https://aws.amazon.com/s3/) bucket to use for remote state storage in `.terragrunt`:

```hcl
bucket = "(YOUR_BUCKET_NAME)"
```

In `vars.tf`, fill in the name of the S3 bucket and key where the remote state is stored for the MySQL database
(you must deploy the templates in [data-stores/mysql](../../data-stores/mysql) first):

```hcl
variable "db_remote_state_bucket" {
description = "The name of the S3 bucket used for the database's remote state storage"
}
variable "db_remote_state_key" {
description = "The name of the key in the S3 bucket used for the database's remote state storage"
}
```

Validate the templates:

```
terragrunt plan
```

Deploy the code:

```
terragrunt apply
```

Clean up when you're done:

```
terragrunt destroy
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
provider "aws" {
region = "us-east-1"
}

module "webserver_cluster" {
source = "../../../../modules/services/webserver-cluster"

ami = "ami-40d28157"
server_text = "Hello, World"

cluster_name = "webservers-prod"
db_remote_state_bucket = "${var.db_remote_state_bucket}"
db_remote_state_key = "${var.db_remote_state_key}"

instance_type = "m4.large"
min_size = 2
max_size = 10

enable_autoscaling = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "elb_dns_name" {
value = "${module.webserver_cluster.elb_dns_name}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "db_remote_state_bucket" {
description = "The name of the S3 bucket used for the database's remote state storage"
}

variable "db_remote_state_key" {
description = "The name of the key in the S3 bucket used for the database's remote state storage"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# MySQL on RDS example (staging environment)

This folder contains example [Terraform](https://www.terraform.io/) templates that deploy a MySQL database (using
[RDS](https://aws.amazon.com/rds/) in an [Amazon Web Services (AWS) account](http://aws.amazon.com/).

For more info, please see Chapter 5, "Terraform Tips & Tricks: Loops, If-Statements, Deployment, and Gotchas", 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 [terragrunt](https://github.com/gruntwork-io/terragrunt) 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 0.7.x.

## 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)
```

Fill in the name of an [S3](https://aws.amazon.com/s3/) bucket to use for remote state storage in `.terragrunt`:

```hcl
bucket = "(YOUR_BUCKET_NAME)"
```

Validate the templates:

```
terragrunt plan
```

Deploy the code:

```
terragrunt apply
```

Clean up when you're done:

```
terragrunt destroy
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
provider "aws" {
region = "us-east-1"
}

resource "aws_db_instance" "example" {
engine = "mysql"
allocated_storage = 10
instance_class = "db.t2.micro"
name = "example_database_stage"
username = "admin"
password = "${var.db_password}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "address" {
value = "${aws_db_instance.example.address}"
}

output "port" {
value = "${aws_db_instance.example.port}"
}
Loading

0 comments on commit 65faac5

Please sign in to comment.