-
-
Notifications
You must be signed in to change notification settings - Fork 358
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
11 changed files
with
235 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,34 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
crash.*.log | ||
|
||
# Exclude all .tfvars files, which are likely to contain sensitive data, such as | ||
# password, private keys, and other secrets. These should not be part of version | ||
# control as they are data points which are potentially sensitive and subject | ||
# to change depending on the environment. | ||
*.tfvars | ||
*.tfvars.json | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
|
||
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc |
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,33 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.0" | ||
} | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = "eu-west-2" | ||
access_key = var.aws_access_key_id | ||
secret_key = var.aws_secret_access_key | ||
} | ||
|
||
# module "vpc" { | ||
# source = "./modules/vpc" | ||
# cidr_block = "10.0.0.0/16" | ||
# } | ||
|
||
# module "security" { | ||
# source = "./modules/security" | ||
# vpc_id = module.vpc.my_vpc.id | ||
# } | ||
|
||
module "backend_instance" { | ||
source = "./modules/ec2" | ||
# ami_id = "ami-123456" | ||
# instance_type = "t2.micro" | ||
# subnet_id = module.vpc.private_subnet.id | ||
# security_group_id = module.security.allow_web.id | ||
# instance_name = "backend_instance" | ||
} |
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,37 @@ | ||
resource "aws_instance" "app_instance" { | ||
ami = var.ami_id | ||
instance_type = var.instance_type | ||
subnet_id = var.subnet_id | ||
security_groups = [var.security_group_id] | ||
key_name = "d-key" | ||
|
||
tags = { | ||
Name = "my_video_server" | ||
} | ||
} | ||
|
||
resource "null_resource" "name" { | ||
provisioner "remote-exec" { | ||
connection { | ||
type = "ssh" | ||
user = "ec2-user" | ||
private_key = file("/Users/dorissiu/Desktop/d-key.pem") | ||
host = aws_instance.app_instance.public_ip | ||
} | ||
|
||
inline = [ | ||
"sudo yum update -y", | ||
"sudo yum install docker -y", | ||
"sudo systemctl start docker", | ||
"sudo systemctl enable docker", | ||
"sudo docker pull doris321/video-app:latest", | ||
"sudo docker run -dp 80:5000 doris321/video-app" | ||
] | ||
} | ||
# wait for ec2 to be created | ||
depends_on = [aws_instance.app_instance] | ||
} | ||
|
||
|
||
|
||
|
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 @@ | ||
variable "ami_id" { | ||
type = string | ||
description = "AWS ec2 ami_id" | ||
default = "ami-0171207a7acd2a570" | ||
} | ||
|
||
variable "instance_type" { | ||
type = string | ||
description = "AWS ec2 instance_type" | ||
default = "t2.micro" | ||
} | ||
|
||
variable "subnet_id" { | ||
type = string | ||
description = "AWS ec2 subnet_id" | ||
default = "subnet-0dd915739859e4a31" | ||
} | ||
|
||
variable "security_group_id" { | ||
type = string | ||
description = "AWS ec2 security_group_id" | ||
default = "sg-04c4f80b88dfa07ee" | ||
} | ||
|
||
|
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,33 @@ | ||
resource "aws_security_group" "ec2_backend_sg" { | ||
name = "ec2_backend_sg" | ||
description = "SG for backend server" | ||
vpc_id = var.vpc_id | ||
|
||
egress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { | ||
from_port = 80 | ||
to_port = 80 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { | ||
from_port = 22 | ||
to_port = 22 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { | ||
from_port = 3389 | ||
to_port = 3389 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
} |
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,5 @@ | ||
variable "vpc_id" { | ||
type = string | ||
description = "AWS vpc_id" | ||
default = "vpc-0d0953aaac41d4376" | ||
} |
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,9 @@ | ||
resource "aws_vpc" "my_vpc" { | ||
cidr_block = var.cidr_block | ||
enable_dns_support = true | ||
enable_dns_hostnames = true | ||
|
||
tags = { | ||
Name = "my_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,5 @@ | ||
variable "cidr_block" { | ||
type = string | ||
description = "AWS VPC cidr_block" | ||
default = "10.0.0.0/16" | ||
} |
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 @@ | ||
variable "aws_access_key_id" { | ||
type = string | ||
description = "AWS Access Key ID" | ||
} | ||
|
||
variable "aws_secret_access_key" { | ||
type = string | ||
sensitive = true | ||
description = "AWS Secret Access Key" | ||
} |