Skip to content

Commit e65bb35

Browse files
committed
Add missing code from final chapter
1 parent 1e1a696 commit e65bb35

File tree

29 files changed

+934
-0
lines changed

29 files changed

+934
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ALB example
2+
3+
This folder contains a [Terraform](https://www.terraform.io/) configuration that shows an example of how to
4+
use the [alb module](../../modules/networking/alb) to deploy a load balancer
5+
(using [ELB](https://aws.amazon.com/elasticloadbalancing/)) in an [Amazon Web Services (AWS)
6+
account](http://aws.amazon.com/).
7+
8+
For more info, please see Chapter 8, "How to use Terraform as a Team", of
9+
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.
10+
11+
## Pre-requisites
12+
13+
* You must have [Terraform](https://www.terraform.io/) installed on your computer.
14+
* You must have an [Amazon Web Services (AWS) account](http://aws.amazon.com/).
15+
16+
Please note that this code was written for Terraform 0.12.x.
17+
18+
## Quick start
19+
20+
**Please note that this example will deploy real resources into your AWS account. We have made every effort to ensure
21+
all the resources qualify for the [AWS Free Tier](https://aws.amazon.com/free/), but we are not responsible for any
22+
charges you may incur.**
23+
24+
Configure your [AWS access
25+
keys](http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) as
26+
environment variables:
27+
28+
```
29+
export AWS_ACCESS_KEY_ID=(your access key id)
30+
export AWS_SECRET_ACCESS_KEY=(your secret access key)
31+
```
32+
33+
Deploy the code:
34+
35+
```
36+
terraform init
37+
terraform apply
38+
```
39+
40+
Clean up when you're done:
41+
42+
```
43+
terraform destroy
44+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
data "aws_vpc" "default" {
2+
default = true
3+
}
4+
5+
data "aws_subnet_ids" "default" {
6+
vpc_id = data.aws_vpc.default.id
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_version = ">= 0.12, < 0.13"
3+
}
4+
5+
provider "aws" {
6+
region = "us-east-2"
7+
8+
# Allow any 2.x version of the AWS provider
9+
version = "~> 2.0"
10+
}
11+
12+
module "alb" {
13+
source = "../../modules/networking/alb"
14+
15+
alb_name = var.alb_name
16+
17+
subnet_ids = data.aws_subnet_ids.default.ids
18+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "alb_dns_name" {
2+
value = module.alb.alb_dns_name
3+
description = "The domain name of the load balancer"
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ---------------------------------------------------------------------------------------------------------------------
2+
# OPTIONAL PARAMETERS
3+
# These parameters have reasonable defaults.
4+
# ---------------------------------------------------------------------------------------------------------------------
5+
6+
variable "alb_name" {
7+
description = "The name of the ALB and all its resources"
8+
type = string
9+
default = "terraform-up-and-running"
10+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ASG example
2+
3+
This folder contains a [Terraform](https://www.terraform.io/) configuration that shows an example of how to
4+
use the [asg-rolling-deploy module](../../modules/cluster/asg-rolling-deploy) to deploy a cluster of web servers
5+
(using [EC2](https://aws.amazon.com/ec2/) and [Auto Scaling](https://aws.amazon.com/autoscaling/)) in an
6+
[Amazon Web Services (AWS) account](http://aws.amazon.com/).
7+
8+
For more info, please see Chapter 8, "How to use Terraform as a Team", of
9+
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.
10+
11+
## Pre-requisites
12+
13+
* You must have [Terraform](https://www.terraform.io/) installed on your computer.
14+
* You must have an [Amazon Web Services (AWS) account](http://aws.amazon.com/).
15+
16+
Please note that this code was written for Terraform 0.12.x.
17+
18+
## Quick start
19+
20+
**Please note that this example will deploy real resources into your AWS account. We have made every effort to ensure
21+
all the resources qualify for the [AWS Free Tier](https://aws.amazon.com/free/), but we are not responsible for any
22+
charges you may incur.**
23+
24+
Configure your [AWS access
25+
keys](http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) as
26+
environment variables:
27+
28+
```
29+
export AWS_ACCESS_KEY_ID=(your access key id)
30+
export AWS_SECRET_ACCESS_KEY=(your secret access key)
31+
```
32+
33+
Deploy the code:
34+
35+
```
36+
terraform init
37+
terraform apply
38+
```
39+
40+
Clean up when you're done:
41+
42+
```
43+
terraform destroy
44+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
data "aws_vpc" "default" {
2+
default = true
3+
}
4+
5+
data "aws_subnet_ids" "default" {
6+
vpc_id = data.aws_vpc.default.id
7+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
terraform {
2+
required_version = ">= 0.12, < 0.13"
3+
}
4+
5+
provider "aws" {
6+
region = "us-east-2"
7+
8+
# Allow any 2.x version of the AWS provider
9+
version = "~> 2.0"
10+
}
11+
12+
module "asg" {
13+
source = "../../modules/cluster/asg-rolling-deploy"
14+
15+
cluster_name = var.cluster_name
16+
17+
ami = "ami-0c55b159cbfafe1f0"
18+
instance_type = "t2.micro"
19+
20+
min_size = 1
21+
max_size = 1
22+
enable_autoscaling = false
23+
24+
subnet_ids = data.aws_subnet_ids.default.ids
25+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "asg_name" {
2+
value = module.asg.asg_name
3+
description = "The name of the Auto Scaling Group"
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ---------------------------------------------------------------------------------------------------------------------
2+
# OPTIONAL PARAMETERS
3+
# These parameters have reasonable defaults.
4+
# ---------------------------------------------------------------------------------------------------------------------
5+
6+
variable "cluster_name" {
7+
description = "The name of the ASG and all its resources"
8+
type = string
9+
default = "terraform-up-and-running"
10+
}

0 commit comments

Comments
 (0)