Skip to content

Commit fbc39dc

Browse files
committed
Updated comments
1 parent 282e8ee commit fbc39dc

File tree

13 files changed

+50
-32
lines changed

13 files changed

+50
-32
lines changed

code/05-cluster-webserver/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ provider "aws" {
66
# Data source: query the list of availability zones
77
data "aws_availability_zones" "all" {}
88

9-
# Create a Security Group for an EC2 instance
9+
# Create a Security Group for an EC2 instance
1010
resource "aws_security_group" "instance" {
1111
name = "terraform-example-instance"
1212

code/06-create-s3/outputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Output variable: S3 bucket name
1+
# Output variable: S3 bucket
22
output "s3_bucket_arn" {
33
value = "${aws_s3_bucket.terraform_state.arn}"
44
}

code/08-file-layout-example/global/s3/main.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# Configure the AWS provider
12
provider "aws" {
23
region = "eu-west-1"
34
}
4-
5+
6+
# Create a S3 bucket
57
resource "aws_s3_bucket" "terraform_state" {
68
bucket = "${var.bucket_name}"
79

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Output variable: S3 bucket
12
output "s3_bucket_arn" {
23
value = "${aws_s3_bucket.terraform_state.arn}"
34
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
# Input variable: S3 bucket name
12
variable "bucket_name" {
23
description = "The name of the S3 bucket. Must be globally unique."
3-
default = "terraform-state-afb"
4+
default = "terraform-state-my-bucket"
45
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
output "address" {
2-
value = "${aws_db_instance.example.address}"
3-
}
4-
5-
output "port" {
6-
value = "${aws_db_instance.example.port}"
1+
# Define Terraform backend using a S3 bucket for storing the Terraform state
2+
terraform {
3+
backend "s3" {
4+
bucket = "terraform-state-my-bucket"
5+
key = "file-layout/stage/data-stores/mysql/terraform.tfstate"
6+
region = "eu-west-1"
7+
}
78
}

code/08-file-layout-example/stage/data-stores/mysql/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# Configure the AWS provider
12
provider "aws" {
23
region = "eu-west-1"
34
}
45

6+
# Create a DB instance
57
resource "aws_db_instance" "example" {
68
engine = "mysql"
79
allocated_storage = 10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# Output variable: DB instance address
12
output "address" {
23
value = "${aws_db_instance.example.address}"
34
}
45

6+
# Output variable: DB instance port
57
output "port" {
68
value = "${aws_db_instance.example.port}"
79
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
output "address" {
2-
value = "${aws_db_instance.example.address}"
3-
}
4-
5-
output "port" {
6-
value = "${aws_db_instance.example.port}"
7-
}
1+
# Input variable: DB password
2+
variable "db_password" {
3+
description = "The password for the database"
4+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
backend "s3" {
3-
bucket = "terraform-state-afb"
4-
key = "file-layout-example/stage/services/webserver-cluster/terraform.tfstate"
5-
region = "eu-west-1"
3+
bucket = "terraform-state-my-bucket"
4+
key = "file-layout-example/stage/services/webserver-cluster/terraform.tfstate"
5+
region = "eu-west-1"
66
}
77
}

code/08-file-layout-example/stage/services/webserver-cluster/main.tf

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
# Configure the AWS provider
12
provider "aws" {
23
region = "eu-west-1"
34
}
4-
5+
6+
# Data source: query the list of availability zones
57
data "aws_availability_zones" "all" {}
68

9+
# Data source: DB remote state
710
data "terraform_remote_state" "db" {
811
backend = "s3"
912

@@ -14,23 +17,25 @@ data "terraform_remote_state" "db" {
1417
}
1518
}
1619

20+
# Data source: Template file
1721
data "template_file" "user_data" {
1822
template = "${file("user-data.sh")}"
1923

2024
vars {
2125
server_port = "${var.server_port}"
22-
db_address = "${data.terraform_remote_state.db.address}"
23-
db_port = "${data.terraform_remote_state.db.port}"
26+
db_address = "${data.terraform_remote_state.db.address}"
27+
db_port = "${data.terraform_remote_state.db.port}"
2428
}
2529
}
2630

31+
# Create a Security Group for an EC2 instance
2732
resource "aws_security_group" "instance" {
2833
name = "terraform-example-instance"
2934

3035
ingress {
31-
from_port = "${var.server_port}"
32-
to_port = "${var.server_port}"
33-
protocol = "tcp"
36+
from_port = "${var.server_port}"
37+
to_port = "${var.server_port}"
38+
protocol = "tcp"
3439
cidr_blocks = ["0.0.0.0/0"]
3540
}
3641

@@ -39,26 +44,28 @@ resource "aws_security_group" "instance" {
3944
}
4045
}
4146

47+
# Create a Security Group for an ELB
4248
resource "aws_security_group" "elb" {
4349
name = "terraform-example-elb"
4450

4551
ingress {
4652
from_port = 80
47-
to_port = 80
53+
to_port = 80
4854
protocol = "tcp"
4955
cidr_blocks = ["0.0.0.0/0"]
5056
}
5157

5258
egress {
5359
from_port = 0
54-
to_port = 0
60+
to_port = 0
5561
protocol = "-1"
5662
cidr_blocks = ["0.0.0.0/0"]
5763
}
5864
}
5965

66+
# Create a Launch Configuration
6067
resource "aws_launch_configuration" "example" {
61-
image_id = "ami-785db401"
68+
image_id = "ami-785db401"
6269
instance_type = "t2.micro"
6370
security_groups = ["${aws_security_group.instance.id}"]
6471
user_data = "${data.template_file.user_data.rendered}"
@@ -68,6 +75,7 @@ resource "aws_launch_configuration" "example" {
6875
}
6976
}
7077

78+
# Create an Autoscaling Group
7179
resource "aws_autoscaling_group" "example" {
7280
launch_configuration = "${aws_launch_configuration.example.id}"
7381
availability_zones = ["${data.aws_availability_zones.all.names}"]
@@ -85,6 +93,7 @@ resource "aws_autoscaling_group" "example" {
8593
}
8694
}
8795

96+
# Create an ELB
8897
resource "aws_elb" "example" {
8998
name = "terraform-asg-example"
9099
availability_zones = ["${data.aws_availability_zones.all.names}"]
@@ -105,4 +114,3 @@ resource "aws_elb" "example" {
105114
target = "HTTP:${var.server_port}/"
106115
}
107116
}
108-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Output variable: DNS Name of ELB
12
output "elb_dns_name" {
23
value = "${aws_elb.example.dns_name}"
34
}

code/08-file-layout-example/stage/services/webserver-cluster/vars.tf

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
# Input variable: server port
12
variable "server_port" {
23
description = "The port the server will use for HTTP requests"
3-
default = "8080"
4+
default = "8080"
45
}
56

7+
# Input variable: DB remote state bucket name
68
variable "db_remote_state_bucket" {
79
description = "The name of the S3 bucket used for the database's remote state storage"
8-
default = "terraform-state-afb"
10+
default = "terraform-state-my-bucket"
911
}
1012

13+
# Input variable: DB remote state bucket key
1114
variable "db_remote_state_key" {
1215
description = "The name of the key in the S3 bucket used for the database's remote state storage"
1316
default = "file-layout-example/stage/data-stores/mysql/terraform.tfstate"

0 commit comments

Comments
 (0)