forked from bregman-arie/devops-exercises
-
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.
Add different solutions to AWS exercises
Not only console solutions, but also Terraform and Pulumi. In addition, this change fixes issues bregman-arie#279 and bregman-arie#280
- Loading branch information
abregman
committed
Aug 24, 2022
1 parent
591ef74
commit 03a92d5
Showing
17 changed files
with
210 additions
and
46 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
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
## AWS VPC - My First VPC | ||
# My First VPC | ||
|
||
### Objectives | ||
## Objectives | ||
|
||
1. Create a new VPC | ||
1. It should have a CIDR that supports using at least 60,000 hosts | ||
1. It should have a CIDR that supports using at least 60,000 hosts | ||
2. It should be named "exercise-vpc" | ||
|
||
## Solution | ||
|
||
Click [here](solution.md) to view the solution |
Empty file.
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,10 @@ | ||
import pulumi | ||
import pulumi_awsx as awsx | ||
|
||
vpc = awsx.ec2.Vpc("exercise-vpc", cidr_block="10.0.0.0/16") | ||
|
||
pulumi.export("vpc_id", vpc.vpc_id) | ||
pulumi.export("publicSubnetIds", vpc.public_subnet_ids) | ||
pulumi.export("privateSubnetIds", vpc.private_subnet_ids) | ||
|
||
# Run 'pulumi up' to create it |
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 |
---|---|---|
@@ -1,17 +1,30 @@ | ||
## AWS VPC - My First VPC | ||
# My First VPC | ||
|
||
### Objectives | ||
## Objectives | ||
|
||
1. Create a new VPC | ||
1. It should have a CIDR that supports using at least 60,000 hosts | ||
1. It should have a CIDR that supports using at least 60,000 hosts | ||
2. It should be named "exercise-vpc" | ||
|
||
### Solution | ||
## Solution | ||
|
||
#### Console | ||
### Console | ||
|
||
1. Under "Virtual Private Cloud" click on "Your VPCs" | ||
2. Click on "Create VPC" | ||
3. Insert a name (e.g. someVPC) | ||
3. Insert a name - "exercise-vpc" | ||
4. Insert IPv4 CIDR block: 10.0.0.0/16 | ||
5. Keep "Tenancy" at Default | ||
6. Click on "Create VPC" | ||
|
||
### Terraform | ||
|
||
Click [here](terraform/main.tf) to view the solution | ||
|
||
### Pulumi - Python | ||
|
||
Click [here](pulumi/__main__.py) to view the solution | ||
|
||
### Verify Solution | ||
|
||
To verify you've create the VPC, you can run: `aws ec2 describe-vpcs -filters Name=tag:Name,Values=exercise-vpc` |
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,11 @@ | ||
resource "aws_vpc" "exercise-vpc" { | ||
cidr_block = "10.0.0.0/16" | ||
|
||
tags = { | ||
Name = "exercise-vpc" | ||
} | ||
} | ||
|
||
output "vpc-id" { | ||
value = aws_vpc.exercise-vpc.id | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pulumi | ||
import pulumi_aws as aws | ||
|
||
availableZones = pulumi_aws.get_availability_zones(state="available") | ||
|
||
aws.ec2.Subnet("NewSubnet1", | ||
vpc_id=aws_vpc["main"]["id"], | ||
cidr_block="10.0.0.0/24", | ||
availability_zone=availableZones.names[0], | ||
tags={"Name": "NewSubnet1"} | ||
) | ||
|
||
aws.ec2.Subnet("NewSubnet2", | ||
vpc_id=aws_vpc["main"]["id"], | ||
cidr_block="10.0.1.0/24", | ||
availability_zone=availableZones.names[1] | ||
tags={"Name": "NewSubnet2"} | ||
) | ||
|
||
aws.ec2.Subnet("NewSubnet3", | ||
vpc_id=aws_vpc["main"]["id"], | ||
cidr_block="10.0.2.0/24", | ||
availability_zone=availableZones.names[2] | ||
tags={"Name": "NewSubnet3"} | ||
) | ||
|
||
# Run "pulumi up" |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Variables | ||
|
||
variable "vpc_id" { | ||
type = string | ||
} | ||
|
||
# AWS Subnets | ||
|
||
resource "aws_subnet" "NewSubnet1" { | ||
cidr_block = "10.0.0.0/24" | ||
vpc_id = var.vpc_id | ||
availability_zone = data.aws_availability_zones.all.names[0] | ||
tags = { | ||
Purpose: exercise | ||
Name: "NewSubnet1" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "NewSubnet2" { | ||
cidr_block = "10.0.1.0/24" | ||
vpc_id = var.vpc_id | ||
availability_zone = data.aws_availability_zones.all.names[1] | ||
tags = { | ||
Purpose: exercise | ||
Name: "NewSubnet2" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "NewSubnet3" { | ||
cidr_block = "10.0.2.0/24" | ||
vpc_id = var.vpc_id | ||
availability_zone = data.aws_availability_zones.all.names[2] | ||
tags = { | ||
Purpose: exercise | ||
Name: "NewSubnet3" | ||
} | ||
} | ||
|
||
# Outputs | ||
|
||
output "NewSubnet1-id" { | ||
value = aws_subnet.NewSubnet1.id | ||
} | ||
output "NewSubnet2-id" { | ||
value = aws_subnet.NewSubnet2.id | ||
} | ||
output "NewSubnet3-id" { | ||
value = aws_subnet.NewSubnet3.id | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.