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.
Regenerate code with zero-downtime deployment
- Loading branch information
Showing
66 changed files
with
745 additions
and
74 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 |
---|---|---|
|
@@ -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}" | ||
|
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions
54
...-tips-and-tricks/zero-downtime-deployment/live/prod/data-stores/mysql/README.md
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,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 | ||
``` |
12 changes: 12 additions & 0 deletions
12
...terraform/05-tips-and-tricks/zero-downtime-deployment/live/prod/data-stores/mysql/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_db_instance" "example" { | ||
engine = "mysql" | ||
allocated_storage = 10 | ||
instance_class = "db.t2.micro" | ||
name = "example_database_prod" | ||
username = "admin" | ||
password = "${var.db_password}" | ||
} |
7 changes: 7 additions & 0 deletions
7
...raform/05-tips-and-tricks/zero-downtime-deployment/live/prod/data-stores/mysql/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,7 @@ | ||
output "address" { | ||
value = "${aws_db_instance.example.address}" | ||
} | ||
|
||
output "port" { | ||
value = "${aws_db_instance.example.port}" | ||
} |
3 changes: 3 additions & 0 deletions
3
...terraform/05-tips-and-tricks/zero-downtime-deployment/live/prod/data-stores/mysql/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,3 @@ | ||
variable "db_password" { | ||
description = "The password for the database" | ||
} |
74 changes: 74 additions & 0 deletions
74
...-tricks/zero-downtime-deployment/live/prod/services/webserver-cluster/README.md
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,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 | ||
``` |
20 changes: 20 additions & 0 deletions
20
.../05-tips-and-tricks/zero-downtime-deployment/live/prod/services/webserver-cluster/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" | ||
} | ||
|
||
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 | ||
} |
3 changes: 3 additions & 0 deletions
3
...-tips-and-tricks/zero-downtime-deployment/live/prod/services/webserver-cluster/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 "elb_dns_name" { | ||
value = "${module.webserver_cluster.elb_dns_name}" | ||
} |
7 changes: 7 additions & 0 deletions
7
.../05-tips-and-tricks/zero-downtime-deployment/live/prod/services/webserver-cluster/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,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" | ||
} |
54 changes: 54 additions & 0 deletions
54
...tips-and-tricks/zero-downtime-deployment/live/stage/data-stores/mysql/README.md
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,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 | ||
``` |
12 changes: 12 additions & 0 deletions
12
...erraform/05-tips-and-tricks/zero-downtime-deployment/live/stage/data-stores/mysql/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_db_instance" "example" { | ||
engine = "mysql" | ||
allocated_storage = 10 | ||
instance_class = "db.t2.micro" | ||
name = "example_database_stage" | ||
username = "admin" | ||
password = "${var.db_password}" | ||
} |
7 changes: 7 additions & 0 deletions
7
...aform/05-tips-and-tricks/zero-downtime-deployment/live/stage/data-stores/mysql/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,7 @@ | ||
output "address" { | ||
value = "${aws_db_instance.example.address}" | ||
} | ||
|
||
output "port" { | ||
value = "${aws_db_instance.example.port}" | ||
} |
Oops, something went wrong.