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
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"master"
]
}
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"
}
58 changes: 58 additions & 0 deletions terraform/07-backend-state/backend-state/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
provider "aws" {
region = "us-east-1"
//version = "~> 2.46"
}

//S3 bucket
resource "aws_s3_bucket" "enterprise_backend_state" {
bucket = "kkgdev-applications-backend-state-in28minutes-abc"

lifecycle {
prevent_destroy = true
}

# versioning {
# enabled = true
# }
#
# server_side_encryption_configuration {
# rule {
# apply_server_side_encryption_by_default {
# sse_algorithm = "AES256"
# }
# }
# }

}

resource "aws_s3_bucket_versioning" "versioning_example" {
bucket = aws_s3_bucket.enterprise_backend_state.id
versioning_configuration {
status = "Enabled"
}
}

resource "aws_s3_bucket_server_side_encryption_configuration" "example" {
bucket = aws_s3_bucket.enterprise_backend_state.bucket

rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}

//Locking - Dynamo DB

resource "aws_dynamodb_table" "enterprise_backend_lock" {
name = "dev_application_locks"
billing_mode = "PAY_PER_REQUEST"

hash_key = "LockID"

attribute {
name = "LockID"
type = "S"
}

}
19 changes: 19 additions & 0 deletions terraform/07-backend-state/users/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
backend "s3" {
bucket = "kkgdev-applications-backend-state-in28minutes-abc"
#key = "07-backend-state-users-dev"
key = "dev/07-backend-state/users/backend-state"
region = "us-east-1"
dynamodb_table = "dev_application_locks"
encrypt = true
}
}

provider "aws" {
region = "us-east-1"
// version = "~> 2.46"
}

resource "aws_iam_user" "my_iam_user" {
name = "${terraform.workspace}_my_iam_user_abc"
}
3 changes: 3 additions & 0 deletions terraform/07-backend-state/users/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "my_iam_user_complete_details" {
value = aws_iam_user.my_iam_user
}
3 changes: 3 additions & 0 deletions terraform/07-backend-state/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"
}
4 changes: 4 additions & 0 deletions terraform/08-modules/dev/users/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "user_module" {
source = "../../terraform-modules/users"
environment = "dev"
}
4 changes: 4 additions & 0 deletions terraform/08-modules/qa/users/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "user_module" {
source = "../../terraform-modules/users"
environment = "qa"
}
16 changes: 16 additions & 0 deletions terraform/08-modules/terraform-modules/users/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
variable "environment" {
default = "default"
}

provider "aws" {
region = "us-east-1"
// version = "~> 2.46"
}

resource "aws_iam_user" "my_iam_user" {
name = "${local.iam_user_extension}_${var.environment}"
}

locals {
iam_user_extension = "my_iam_user_abc"
}
3 changes: 3 additions & 0 deletions terraform/08-modules/terraform-modules/users/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "my_iam_user_complete_details" {
value = aws_iam_user.my_iam_user
}
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
}
}
Loading