-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
222 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
|
||
# Exclude all .tfvars files, which are likely to contain sensitive data, such as passwords | ||
*.tfvars | ||
|
||
# Ignore override files as they are usually used to override resources locally and should not be shared | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include .terraformrc and terraform.rc files as they are user-specific configuration files | ||
.terraformrc | ||
terraform.rc | ||
|
||
# Ignore any plan output files | ||
*.tfplan |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,46 @@ | ||
provider "aws" { | ||
region = "us-west-2" | ||
} | ||
|
||
module "vpc" { | ||
source = "./modules/vpc" | ||
cidr_block = "10.0.0.0/16" | ||
} | ||
|
||
module "subnet" { | ||
source = "./modules/subnet" | ||
vpc_id = module.vpc.vpc_id | ||
cidr_block = "10.0.1.0/24" | ||
availability_zone = "us-west-2a" | ||
} | ||
|
||
module "security_group" { | ||
source = "./modules/security-group" | ||
vpc_id = module.vpc.vpc_id | ||
} | ||
|
||
|
||
data "aws_ami" "example" { | ||
most_recent = true | ||
|
||
filter { | ||
name = "name" | ||
values = ["amzn2-ami-hvm-*-x86_64-gp2"] | ||
} | ||
|
||
filter { | ||
name = "virtualization-type" | ||
values = ["hvm"] | ||
} | ||
|
||
owners = ["amazon"] | ||
} | ||
|
||
module "ec2" { | ||
source = "./modules/ec2" | ||
ami = data.aws_ami.example.id | ||
instance_type = "t2.micro" | ||
subnet_id = module.subnet.subnet_id | ||
security_group_id = module.security_group.security_group_id | ||
key_name = var.key_name | ||
} |
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_instance" "main" { | ||
ami = var.ami | ||
instance_type = var.instance_type | ||
subnet_id = var.subnet_id | ||
security_groups = [var.security_group_id] | ||
key_name = var.key_name | ||
|
||
tags = { | ||
Name = "MyEC2Instance" | ||
} | ||
} |
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,3 @@ | ||
output "instance_id" { | ||
value = aws_instance.main.id | ||
} |
24 changes: 24 additions & 0 deletions
24
tf-ec2-with-modules/terraform-project/modules/ec2/variables.tf
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,24 @@ | ||
variable "ami" { | ||
description = "The AMI ID for the EC2 instance" | ||
type = string | ||
} | ||
|
||
variable "instance_type" { | ||
description = "The instance type for the EC2 instance" | ||
type = string | ||
} | ||
|
||
variable "subnet_id" { | ||
description = "The ID of the subnet" | ||
type = string | ||
} | ||
|
||
variable "security_group_id" { | ||
description = "The ID of the security group" | ||
type = string | ||
} | ||
|
||
variable "key_name" { | ||
description = "value of the key pair" | ||
type = string | ||
} |
21 changes: 21 additions & 0 deletions
21
tf-ec2-with-modules/terraform-project/modules/security-group/main.tf
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,21 @@ | ||
resource "aws_security_group" "main" { | ||
vpc_id = var.vpc_id | ||
|
||
ingress { | ||
from_port = 22 | ||
to_port = 22 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
egress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
tags = { | ||
Name = "allow_ssh" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tf-ec2-with-modules/terraform-project/modules/security-group/outputs.tf
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,3 @@ | ||
output "security_group_id" { | ||
value = aws_security_group.main.id | ||
} |
4 changes: 4 additions & 0 deletions
4
tf-ec2-with-modules/terraform-project/modules/security-group/variables.tf
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,4 @@ | ||
variable "vpc_id" { | ||
description = "The ID of the VPC" | ||
type = string | ||
} |
24 changes: 24 additions & 0 deletions
24
tf-ec2-with-modules/terraform-project/modules/subnet/main.tf
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,24 @@ | ||
resource "aws_subnet" "main" { | ||
vpc_id = var.vpc_id | ||
cidr_block = var.cidr_block | ||
availability_zone = var.availability_zone | ||
map_public_ip_on_launch = true | ||
} | ||
|
||
resource "aws_internet_gateway" "main" { | ||
vpc_id = var.vpc_id | ||
} | ||
|
||
resource "aws_route_table" "public" { | ||
vpc_id = var.vpc_id | ||
|
||
route { | ||
cidr_block = "0.0.0.0/0" | ||
gateway_id = aws_internet_gateway.main.id | ||
} | ||
} | ||
|
||
resource "aws_route_table_association" "public" { | ||
subnet_id = aws_subnet.main.id | ||
route_table_id = aws_route_table.public.id | ||
} |
3 changes: 3 additions & 0 deletions
3
tf-ec2-with-modules/terraform-project/modules/subnet/outputs.tf
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,3 @@ | ||
output "subnet_id" { | ||
value = aws_subnet.main.id | ||
} |
14 changes: 14 additions & 0 deletions
14
tf-ec2-with-modules/terraform-project/modules/subnet/variables.tf
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,14 @@ | ||
variable "vpc_id" { | ||
description = "The ID of the VPC" | ||
type = string | ||
} | ||
|
||
variable "cidr_block" { | ||
description = "The CIDR block for the subnet" | ||
type = string | ||
} | ||
|
||
variable "availability_zone" { | ||
description = "The availability zone for the subnet" | ||
type = string | ||
} |
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,3 @@ | ||
resource "aws_vpc" "main" { | ||
cidr_block = var.cidr_block | ||
} |
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,3 @@ | ||
output "vpc_id" { | ||
value = aws_vpc.main.id | ||
} |
4 changes: 4 additions & 0 deletions
4
tf-ec2-with-modules/terraform-project/modules/vpc/variables.tf
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,4 @@ | ||
variable "cidr_block" { | ||
description = "The CIDR block for the VPC" | ||
type = string | ||
} |
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,3 @@ | ||
output "instance_id" { | ||
value = module.ec2.instance_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Define any global variables if needed | ||
variable "key_name" { | ||
description = "value of the key pair" | ||
type = string | ||
default = "your-pem-key-name" | ||
} | ||
|