Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test project #22

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion projects/hello-world/hello-world-nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const process = require('process');

var expressapp = express()
expressapp.get('/', function (req, res) {
res.send('{"message":"Hello World JavaScript v1"}')
res.send('{"message":"Hello World JavaScript v2"}')
})
expressapp.listen(5000, function () {
console.log('Ready on port 5000!')
Expand Down
2 changes: 1 addition & 1 deletion projects/hello-world/hello-world-python/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
helloworld = Flask(__name__)
@helloworld.route("/")
def run():
return "{\"message\":\"Hello World Python v1\"}"
return "{\"message\":\"Hello World Python v2\"}"
if __name__ == "__main__":
helloworld.run(host="0.0.0.0", port=int("5000"), debug=True)
64 changes: 64 additions & 0 deletions terraform/05-ec2-instances/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
provider "aws" {
region = "us-east-1"
}

resource "aws_default_vpc" "default" {

}

resource "aws_security_group" "http_server_sg" {
name = "http_server_sg"
//vpc_id = "vpc-02523c91a94e96bca"
vpc_id = aws_default_vpc.default.id

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"]
}

egress {
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
name = "http_server_sg"
}
}

resource "aws_instance" "http_server" {
#ami = "ami-0b5eea76982371e91"
ami = data.aws_ami.aws_linux_2_latest.id
key_name = "default-ec2"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.http_server_sg.id]

//subnet_id = "subnet-3f7b2563"
subnet_id = data.aws_subnets.default_subnets.ids[0]

connection {
type = "ssh"
host = self.public_ip
user = "ec2-user"
private_key = file(var.aws_key_pair)
}

provisioner "remote-exec" {
inline = [
"sudo yum install httpd -y",
"sudo service httpd start",
"echo Welcome to in28minutes - Virtual Server is at ${self.public_dns} | sudo tee /var/www/html/index.html"
]
}
}
7 changes: 7 additions & 0 deletions terraform/05-ec2-instances/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "aws_security_group_http_server_details" {
value = "aws_security_group_http_server_sg"
}

output "http_server_public_dns" {
value = aws_instance.http_server.public_dns
}
3 changes: 3 additions & 0 deletions terraform/05-ec2-instances/output1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "aws_security_group_http_server_details" {
value = aws_security_group_http_server_sg
}
15 changes: 15 additions & 0 deletions terraform/06-ec2-with-elb/data-providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
data "aws_subnets" "default_subnets" {
filter {
name = "vpc-id"
values = [aws_default_vpc.default.id]
}
}

data "aws_ami" "aws_linux_2_latest" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm-*"]
}
}
104 changes: 104 additions & 0 deletions terraform/06-ec2-with-elb/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
provider "aws" {
region = "us-east-1"
}

resource "aws_default_vpc" "default" {

}

resource "aws_security_group" "http_server_sg" {
name = "http_server_sg"
//vpc_id = "vpc-02523c91a94e96bca"
vpc_id = aws_default_vpc.default.id

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"]
}

egress {
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
name = "http_server_sg"
}
}

resource "aws_security_group" "elb_sg" {
name = "elb_sg"
vpc_id = aws_default_vpc.default.id

ingress {
from_port = 80
to_port = 80
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"]
}

}

resource "aws_elb" "elb" {
name = "elb"
subnets = data.aws_subnets.default_subnets.ids
security_groups = [aws_security_group.elb_sg.id]
instances = values(aws_instance.http_servers).*.id

listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
}

resource "aws_instance" "http_servers" {
#ami = "ami-0b5eea76982371e91"
ami = data.aws_ami.aws_linux_2_latest.id
key_name = "default-ec2"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.http_server_sg.id]

#for_each = data.aws_subnet_ids.default_subnets.ids
for_each = toset(data.aws_subnets.default_subnets.ids)
subnet_id = each.value

tags = {
name : "http_servers_${each.value}"
}

connection {
type = "ssh"
host = self.public_ip
user = "ec2-user"
private_key = file(var.aws_key_pair)
}

provisioner "remote-exec" {
inline = [
"sudo yum install httpd -y",
"sudo service httpd start",
"echo Welcome to in28minutes - Virtual Server is at ${self.public_dns} | sudo tee /var/www/html/index.html"
]
}
}

11 changes: 11 additions & 0 deletions terraform/06-ec2-with-elb/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "aws_security_group_http_server_details" {
value = "aws_security_group_http_server_sg"
}

output "http_server_public_dns" {
value = values(aws_instance.http_servers).*.id
}

output "elb_public_dns" {
value = aws_elb.elb
}
3 changes: 3 additions & 0 deletions terraform/06-ec2-with-elb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "aws_key_pair" {
default = "C:/Users/gemes/Downloads/terraform/aws_key_pair/default-ec2.pem"
}
21 changes: 21 additions & 0 deletions terraform/Terraform/01-terraform-basics/04-maps/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variable "users" {
default = {
ravs : { country : "Netherlands", department : "ABC" },
tom : { country : "US", department : "DEF" },
jane : { country : "India", department : "XYZ" }
}
}

provider "aws" {
region = "us-east-1"
}

resource "aws_iam_user" "my_iam_users" {
for_each = var.users
name = each.key
tags = {
#country:each.value
country : each.value.country
department : each.value.department
}
}
14 changes: 14 additions & 0 deletions terraform/Terraform/01-terraform-basics/05-ec2-instances/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "names" {
default = ["ravs","sats","ranga", "tom","jane"]
}

provider "aws" {
region = "us-east-1"
}

resource "aws_iam_user" "my_iam_users" {
# count = length(var.names)
# name = var.names[count.index]
for_each = toset(var.names)
name = each.value
}
Binary file not shown.
9 changes: 9 additions & 0 deletions terraform/Terraform/01-terraform-basics/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
provider "aws" {
region = "us-east-1"
}

# resource "aws_s3_bucket_versioning""versioning_example"{
# bucket="aws_s3_bucket.my_s3_bucket.id"
#versioning_configuration {
# status= "Enabled"
#}
9 changes: 9 additions & 0 deletions terraform/Terraform/01-terraform-basics/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "my_s3_bucket_versioning" {
value = aws_s3_bucket.my_s3_bucket.versioning[0].enabled
}
output "my_s3_bucket_complete_details" {
value = aws_s3_bucket.my_s3_bucket
}
output "my_iam_user_complete_details" {
value = aws_iam_user.my_iam_user
}
10 changes: 10 additions & 0 deletions terraform/Terraform/01-terraform-basics/resources.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#plan-execute
resource "aws_s3_bucket" "my_s3_bucket" {
bucket = "my-s3-bucket-in28minutes-kahg-002"
versioning {
enabled = true
}
}
resource "aws_iam_user" "my_iam_user" {
name = "my_iam_user_gkk_update"
}
Loading