Skip to content

Commit 503ab1f

Browse files
authored
Merge pull request #79 from brikis98/3rd-edition
3rd edition
2 parents f31b91c + b378217 commit 503ab1f

File tree

384 files changed

+6810
-1229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

384 files changed

+6810
-1229
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
# Terraform: Up & Running Code
22

3-
This repo contains the code samples for the book *[Terraform: Up and Running](http://www.terraformupandrunning.com)*,
4-
2nd edition, by [Yevgeniy Brikman](http://www.ybrikman.com).
3+
This repo contains the code samples for the book *[Terraform: Up and Running](http://www.terraformupandrunning.com)*,
4+
by [Yevgeniy Brikman](http://www.ybrikman.com).
55

66

77

88

9-
## Quick start
10-
11-
All the code is in the [code](/code) folder. It is organized by language (terraform, bash, ruby, etc) and within each
12-
language, by chapter. Since this code comes from a book about Terraform, the vast majority of the code consists of
13-
Terraform examples in the [code/terraform folder](/code/terraform).
9+
## Looking for the 1st, 2nd, or 3rd edition?
1410

15-
For instructions on running the code, please consult the README in each folder, and, of course, the
16-
*[Terraform: Up and Running](http://www.terraformupandrunning.com)* book.
11+
*Terraform: Up & Running* is now on its **3rd edition**; all the code in `master` is for this edition. If you're looking
12+
for code examples for other editions, please see the following branches:
1713

14+
* [1st-edition branch](https://github.com/brikis98/terraform-up-and-running-code/tree/1st-edition).
15+
* [2nd-edition branch](https://github.com/brikis98/terraform-up-and-running-code/tree/2nd-edition).
16+
* [3rd-edition branch](https://github.com/brikis98/terraform-up-and-running-code/tree/3rd-edition).
1817

1918

20-
## More examples
21-
22-
The example code in *Terraform: Up and Running* are mostly for Amazon Web Services (AWS). There is a project underway
23-
to translate these examples to their equivalents on other cloud providers, such as Google Cloud and Azure, here:
24-
https://github.com/mjuenema/Terraform-Up-and-Running-Code-Samples-Translated/.
2519

20+
## Quick start
2621

22+
All the code is in the [code](/code) folder. The code examples are organized first by the tool or language and then
23+
by chapter. For example, if you're looking at an example of Terraform code in Chapter 2, you'll find it in the
24+
[code/terraform/02-intro-to-terraform-syntax](code/terraform/02-intro-to-terraform-syntax) folder; if you're looking at
25+
an OPA (Rego) example in Chapter 9, you'll find it in the
26+
[code/terraform/09-testing-terraform-code](code/terraform/09-testing-terraform-code) folder.
2727

28-
## Looking for the 1st edition?
28+
Since this code comes from a book about Terraform, the vast majority of the code consists of Terraform examples in the
29+
[code/terraform folder](/code/terraform).
2930

30-
All the code examples in the `master` branch are for the 2nd edition of *Terraform: Up & Running*. If you're looking
31-
for the code examples from the 1st edition, please head over to the
32-
[1st-edition branch](https://github.com/brikis98/terraform-up-and-running-code/tree/1st-edition).
31+
For instructions on running the code, please consult the README in each folder, and, of course, the
32+
*[Terraform: Up and Running](http://www.terraformupandrunning.com)* book.
3333

3434

3535

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
- ec2:
22
count: 10
3-
image: ami-0c55b159cbfafe1f0
3+
image: ami-0fb653ca2d3203ac1
44
instance_type: t2.micro
55

66
- ec2:
77
count: 5
8-
image: ami-0c55b159cbfafe1f0
8+
image: ami-0fb653ca2d3203ac1
99
instance_type: t2.micro
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Effect": "Allow",
6+
"Action": "ec2:*",
7+
"Resource": "*"
8+
},
9+
{
10+
"Effect": "Allow",
11+
"Action": "elasticloadbalancing:*",
12+
"Resource": "*"
13+
},
14+
{
15+
"Effect": "Allow",
16+
"Action": "cloudwatch:*",
17+
"Resource": "*"
18+
},
19+
{
20+
"Effect": "Allow",
21+
"Action": "autoscaling:*",
22+
"Resource": "*"
23+
},
24+
{
25+
"Effect": "Allow",
26+
"Action": "iam:*",
27+
"Resource": "*"
28+
},
29+
{
30+
"Effect": "Allow",
31+
"Action": "s3:*",
32+
"Resource": "*"
33+
},
34+
{
35+
"Effect": "Allow",
36+
"Action": "dynamodb:*",
37+
"Resource": "*"
38+
},
39+
{
40+
"Effect": "Allow",
41+
"Action": "kms:*",
42+
"Resource": "*"
43+
},
44+
{
45+
"Effect": "Allow",
46+
"Action": "lambda:*",
47+
"Resource": "*"
48+
},
49+
{
50+
"Effect": "Allow",
51+
"Action": "application-autoscaling:*",
52+
"Resource": "*"
53+
},
54+
{
55+
"Effect": "Allow",
56+
"Action": "rds:*",
57+
"Resource": "*"
58+
},
59+
{
60+
"Effect": "Allow",
61+
"Action": "sns:*",
62+
"Resource": "*"
63+
},
64+
{
65+
"Effect": "Allow",
66+
"Action": "logs:*",
67+
"Resource": "*"
68+
},
69+
{
70+
"Effect": "Allow",
71+
"Action": "organizations:*",
72+
"Resource": "*"
73+
},
74+
{
75+
"Effect": "Allow",
76+
"Action": "account:*",
77+
"Resource": "*"
78+
}
79+
]
80+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# OPA example
2+
3+
This folder contains example [Open Policy Agent (OPA)](https://www.openpolicyagent.org/) policy that enforces all
4+
resources include a specific tag.
5+
6+
For more info, please see Chapter 9, "How to test Terraform code", of
7+
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.
8+
9+
## Quick start
10+
11+
Please see the README in the companion Terraform module at
12+
[09-testing-terraform-code/examples/opa](../../terraform/09-testing-terraform-code/examples/opa) for instructions on
13+
how to use this policy to test that module.
14+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package tuar
2+
3+
allow {
4+
resource_change := input.resource_changes[_]
5+
resource_change.change.after.tags["ManagedBy"]
6+
}

code/packer/01-why-terraform/webserver.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"builders": [{
3-
"ami_name": "packer-example",
3+
"ami_name": "packer-example-{{isotime | clean_resource_name}}",
44
"instance_type": "t2.micro",
55
"region": "us-east-2",
66
"type": "amazon-ebs",
7-
"source_ami": "ami-0c55b159cbfafe1f0",
7+
"source_ami": "ami-0fb653ca2d3203ac1",
88
"ssh_username": "ubuntu"
99
}],
1010
"provisioners": [{
@@ -16,6 +16,7 @@
1616
],
1717
"environment_vars": [
1818
"DEBIAN_FRONTEND=noninteractive"
19-
]
19+
],
20+
"pause_before": "60s"
2021
}]
2122
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# Define the function in one place
12
def example_function()
23
puts "Hello, World"
34
end
45

5-
# Other places in your code
6+
# Use the function in multiple other places
67
example_function()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# A function that returns a value
12
def example_function(param1, param2)
23
return "Hello, #{param1} #{param2}"
34
end
45

5-
# Other places in your code
6+
# Call the function and get the return value
67
return_value = example_function("foo", "bar")
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# A function with two input parameters
12
def example_function(param1, param2)
23
puts "Hello, #{param1} #{param2}"
34
end
45

5-
# Other places in your code
6+
# Pass two input parameters to the function
67
example_function("foo", "bar")

code/ruby/07-testing-terraform-code/web-server-basic-test.rb renamed to code/ruby/09-testing-terraform-code/web-server-basic-test.rb

File renamed without changes.

0 commit comments

Comments
 (0)