Skip to content

Commit

Permalink
Initial update to 3rd edition code
Browse files Browse the repository at this point in the history
  • Loading branch information
brikis98 committed Feb 24, 2022
1 parent f31b91c commit 89e992f
Show file tree
Hide file tree
Showing 379 changed files with 6,699 additions and 1,180 deletions.
4 changes: 2 additions & 2 deletions code/ansible/01-why-terraform/procedural-examples.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- ec2:
count: 10
image: ami-0c55b159cbfafe1f0
image: ami-0fb653ca2d3203ac1
instance_type: t2.micro

- ec2:
count: 5
image: ami-0c55b159cbfafe1f0
image: ami-0fb653ca2d3203ac1
instance_type: t2.micro
80 changes: 80 additions & 0 deletions code/json/02-intro-to-terraform-syntax/iam-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ec2:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "elasticloadbalancing:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "cloudwatch:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "autoscaling:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "iam:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "dynamodb:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "kms:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "lambda:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "application-autoscaling:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "rds:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "sns:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "logs:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "organizations:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "account:*",
"Resource": "*"
}
]
}
13 changes: 13 additions & 0 deletions code/opa/09-testing-terraform-code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# OPA example

This folder contains example [Open Policy Agent (OPA)](https://www.openpolicyagent.org/) policy that enforces all
module source URLs come from the `brikis98` GitHub org.

For more info, please see Chapter 9, "How to test Terraform code", of
*[Terraform: Up and Running](http://www.terraformupandrunning.com)*.

## Quick start

The best way to run this test is with Terratest. See
[opa_test.go](../../terraform/09-testing-terraform-code/test/opa_test.go).

10 changes: 10 additions & 0 deletions code/opa/09-testing-terraform-code/enforce_source.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package enforce_source

allow = true {
count(violation) == 0
}

violation[module_label] {
some module_label, i
startswith(input.module[module_label][i].source, "github.com/brikis98") == false
}
2 changes: 1 addition & 1 deletion code/packer/01-why-terraform/webserver.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"instance_type": "t2.micro",
"region": "us-east-2",
"type": "amazon-ebs",
"source_ami": "ami-0c55b159cbfafe1f0",
"source_ami": "ami-0fb653ca2d3203ac1",
"ssh_username": "ubuntu"
}],
"provisioners": [{
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions code/terraform/.terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.1.4
2 changes: 1 addition & 1 deletion code/terraform/00-preface/hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For more info, please see the preface of *[Terraform: Up and Running](http://www
* You must have [Terraform](https://www.terraform.io/) 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.12.x.
Please note that this code was written for Terraform 1.x.

## Quick start

Expand Down
14 changes: 9 additions & 5 deletions code/terraform/00-preface/hello-world/main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
terraform {
required_version = ">= 0.12, < 0.13"
required_version = ">= 1.0.0, < 2.0.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}

provider "aws" {
region = "us-east-2"

# Allow any 2.x version of the AWS provider
version = "~> 2.0"
}

resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
ami = "ami-0fb653ca2d3203ac1"
instance_type = "t2.micro"
}

2 changes: 1 addition & 1 deletion code/terraform/01-why-terraform/web-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ For more info, please see Chapter 1, "Why Terraform", of
* You must have [Terraform](https://www.terraform.io/) 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.12.x.
Please note that this code was written for Terraform 1.x.

## Quick start

Expand Down
14 changes: 9 additions & 5 deletions code/terraform/01-why-terraform/web-server/main.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
terraform {
required_version = ">= 0.12, < 0.13"
required_version = ">= 1.0.0, < 2.0.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}

provider "aws" {
region = "us-east-2"

# Allow any 2.x version of the AWS provider
version = "~> 2.0"
}

resource "aws_instance" "app" {
instance_type = "t2.micro"
availability_zone = "us-east-2a"
ami = "ami-0c55b159cbfafe1f0"
ami = "ami-0fb653ca2d3203ac1"

user_data = <<-EOF
#!/bin/bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ For more info, please see Chapter 2, "Getting started with Terraform", of
* You must have [Terraform](https://www.terraform.io/) 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.12.x.
Please note that this code was written for Terraform 1.x.

## Quick start

Expand Down
14 changes: 9 additions & 5 deletions code/terraform/02-intro-to-terraform-syntax/one-server/main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
terraform {
required_version = ">= 0.12, < 0.13"
required_version = ">= 1.0.0, < 2.0.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}

provider "aws" {
region = "us-east-2"

# Allow any 2.x version of the AWS provider
version = "~> 2.0"
}

resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
ami = "ami-0fb653ca2d3203ac1"
instance_type = "t2.micro"

tags = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For more info, please see Chapter 2, "Getting started with Terraform", of
* You must have [Terraform](https://www.terraform.io/) 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.12.x.
Please note that this code was written for Terraform 1.x.

## Quick start

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
terraform {
required_version = ">= 0.12, < 0.13"
required_version = ">= 1.0.0, < 2.0.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}

provider "aws" {
region = "us-east-2"

# Allow any 2.x version of the AWS provider
version = "~> 2.0"
}

resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
ami = "ami-0fb653ca2d3203ac1"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.instance.id]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For more info, please see Chapter 2, "Getting started with Terraform", of
* You must have [Terraform](https://www.terraform.io/) 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.12.x.
Please note that this code was written for Terraform 1.x.

## Quick start

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
terraform {
required_version = ">= 0.12, < 0.13"
required_version = ">= 1.0.0, < 2.0.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}

provider "aws" {
region = "us-east-2"

# Allow any 2.x version of the AWS provider
version = "~> 2.0"
}

resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
ami = "ami-0fb653ca2d3203ac1"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.instance.id]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ For more info, please see Chapter 2, "Getting started with Terraform", of
* You must have [Terraform](https://www.terraform.io/) 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.12.x.
Please note that this code was written for Terraform 1.x.

## Quick start

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
terraform {
required_version = ">= 0.12, < 0.13"
required_version = ">= 1.0.0, < 2.0.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}

provider "aws" {
region = "us-east-2"

# Allow any 2.x version of the AWS provider
version = "~> 2.0"
}

resource "aws_launch_configuration" "example" {
image_id = "ami-0c55b159cbfafe1f0"
image_id = "ami-0fb653ca2d3203ac1"
instance_type = "t2.micro"
security_groups = [aws_security_group.instance.id]

Expand All @@ -29,7 +33,7 @@ resource "aws_launch_configuration" "example" {

resource "aws_autoscaling_group" "example" {
launch_configuration = aws_launch_configuration.example.name
vpc_zone_identifier = data.aws_subnet_ids.default.ids
vpc_zone_identifier = data.aws_subnets.default.ids

target_group_arns = [aws_lb_target_group.asg.arn]
health_check_type = "ELB"
Expand Down Expand Up @@ -59,16 +63,19 @@ data "aws_vpc" "default" {
default = true
}

data "aws_subnet_ids" "default" {
vpc_id = data.aws_vpc.default.id
data "aws_subnets" "default" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}
}

resource "aws_lb" "example" {

name = var.alb_name

load_balancer_type = "application"
subnets = data.aws_subnet_ids.default.ids
subnets = data.aws_subnets.default.ids
security_groups = [aws_security_group.alb.id]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For more info, please see Chapter 3, "How to Manage Terraform State", of
* You must have [Terraform](https://www.terraform.io/) 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.12.x.
Please note that this code was written for Terraform 1.x.

## Quick start

Expand Down
Loading

0 comments on commit 89e992f

Please sign in to comment.