diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..6c2ff60b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "master" + ] +} \ No newline at end of file diff --git a/projects/hello-world/hello-world-nodejs/index.js b/projects/hello-world/hello-world-nodejs/index.js index 3d23b495..9e7306e1 100755 --- a/projects/hello-world/hello-world-nodejs/index.js +++ b/projects/hello-world/hello-world-nodejs/index.js @@ -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!') diff --git a/projects/hello-world/hello-world-python/launch.py b/projects/hello-world/hello-world-python/launch.py index 3a161a5e..1ac542e4 100755 --- a/projects/hello-world/hello-world-python/launch.py +++ b/projects/hello-world/hello-world-python/launch.py @@ -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) \ No newline at end of file diff --git a/terraform/05-ec2-instances/main.tf b/terraform/05-ec2-instances/main.tf new file mode 100644 index 00000000..7c6190b5 --- /dev/null +++ b/terraform/05-ec2-instances/main.tf @@ -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" + ] + } +} \ No newline at end of file diff --git a/terraform/05-ec2-instances/output.tf b/terraform/05-ec2-instances/output.tf new file mode 100644 index 00000000..06aa9b82 --- /dev/null +++ b/terraform/05-ec2-instances/output.tf @@ -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 +} \ No newline at end of file diff --git a/terraform/05-ec2-instances/output1 b/terraform/05-ec2-instances/output1 new file mode 100644 index 00000000..551c357d --- /dev/null +++ b/terraform/05-ec2-instances/output1 @@ -0,0 +1,3 @@ + output "aws_security_group_http_server_details" { + value = aws_security_group_http_server_sg + } \ No newline at end of file diff --git a/terraform/06-ec2-with-elb/data-providers.tf b/terraform/06-ec2-with-elb/data-providers.tf new file mode 100644 index 00000000..ea1bafa4 --- /dev/null +++ b/terraform/06-ec2-with-elb/data-providers.tf @@ -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-*"] + } +} diff --git a/terraform/06-ec2-with-elb/main.tf b/terraform/06-ec2-with-elb/main.tf new file mode 100644 index 00000000..cc74b08e --- /dev/null +++ b/terraform/06-ec2-with-elb/main.tf @@ -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" + ] + } +} + diff --git a/terraform/06-ec2-with-elb/output.tf b/terraform/06-ec2-with-elb/output.tf new file mode 100644 index 00000000..72783d6a --- /dev/null +++ b/terraform/06-ec2-with-elb/output.tf @@ -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 +} \ No newline at end of file diff --git a/terraform/06-ec2-with-elb/variables.tf b/terraform/06-ec2-with-elb/variables.tf new file mode 100644 index 00000000..84cecbe0 --- /dev/null +++ b/terraform/06-ec2-with-elb/variables.tf @@ -0,0 +1,3 @@ +variable "aws_key_pair" { + default = "C:/Users/gemes/Downloads/terraform/aws_key_pair/default-ec2.pem" +} \ No newline at end of file diff --git a/terraform/07-backend-state/backend-state/main.tf b/terraform/07-backend-state/backend-state/main.tf new file mode 100644 index 00000000..af51b452 --- /dev/null +++ b/terraform/07-backend-state/backend-state/main.tf @@ -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" + } + +} \ No newline at end of file diff --git a/terraform/07-backend-state/users/main.tf b/terraform/07-backend-state/users/main.tf new file mode 100644 index 00000000..74752fb5 --- /dev/null +++ b/terraform/07-backend-state/users/main.tf @@ -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" +} diff --git a/terraform/07-backend-state/users/outputs.tf b/terraform/07-backend-state/users/outputs.tf new file mode 100644 index 00000000..5ecf7a5d --- /dev/null +++ b/terraform/07-backend-state/users/outputs.tf @@ -0,0 +1,3 @@ +output "my_iam_user_complete_details" { + value = aws_iam_user.my_iam_user +} \ No newline at end of file diff --git a/terraform/07-backend-state/variables.tf b/terraform/07-backend-state/variables.tf new file mode 100644 index 00000000..84cecbe0 --- /dev/null +++ b/terraform/07-backend-state/variables.tf @@ -0,0 +1,3 @@ +variable "aws_key_pair" { + default = "C:/Users/gemes/Downloads/terraform/aws_key_pair/default-ec2.pem" +} \ No newline at end of file diff --git a/terraform/08-modules/dev/users/main.tf b/terraform/08-modules/dev/users/main.tf new file mode 100644 index 00000000..403a4941 --- /dev/null +++ b/terraform/08-modules/dev/users/main.tf @@ -0,0 +1,4 @@ +module "user_module" { + source = "../../terraform-modules/users" + environment = "dev" +} \ No newline at end of file diff --git a/terraform/08-modules/qa/users/main.tf b/terraform/08-modules/qa/users/main.tf new file mode 100644 index 00000000..44ddf353 --- /dev/null +++ b/terraform/08-modules/qa/users/main.tf @@ -0,0 +1,4 @@ +module "user_module" { + source = "../../terraform-modules/users" + environment = "qa" +} \ No newline at end of file diff --git a/terraform/08-modules/terraform-modules/users/main.tf b/terraform/08-modules/terraform-modules/users/main.tf new file mode 100644 index 00000000..c8b17c3d --- /dev/null +++ b/terraform/08-modules/terraform-modules/users/main.tf @@ -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" +} \ No newline at end of file diff --git a/terraform/08-modules/terraform-modules/users/outputs.tf b/terraform/08-modules/terraform-modules/users/outputs.tf new file mode 100644 index 00000000..f1ea9899 --- /dev/null +++ b/terraform/08-modules/terraform-modules/users/outputs.tf @@ -0,0 +1,3 @@ +output "my_iam_user_complete_details" { + value = aws_iam_user.my_iam_user +} \ No newline at end of file diff --git a/terraform/Terraform/01-terraform-basics/04-maps/main.tf b/terraform/Terraform/01-terraform-basics/04-maps/main.tf new file mode 100644 index 00000000..16f62333 --- /dev/null +++ b/terraform/Terraform/01-terraform-basics/04-maps/main.tf @@ -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 + } +} \ No newline at end of file diff --git a/terraform/Terraform/01-terraform-basics/05-ec2-instances/main.tf b/terraform/Terraform/01-terraform-basics/05-ec2-instances/main.tf new file mode 100644 index 00000000..7332e9b4 --- /dev/null +++ b/terraform/Terraform/01-terraform-basics/05-ec2-instances/main.tf @@ -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 +} \ No newline at end of file diff --git a/terraform/Terraform/01-terraform-basics/iam.tfplan b/terraform/Terraform/01-terraform-basics/iam.tfplan new file mode 100644 index 00000000..13a37301 Binary files /dev/null and b/terraform/Terraform/01-terraform-basics/iam.tfplan differ diff --git a/terraform/Terraform/01-terraform-basics/main.tf b/terraform/Terraform/01-terraform-basics/main.tf new file mode 100644 index 00000000..e0f83622 --- /dev/null +++ b/terraform/Terraform/01-terraform-basics/main.tf @@ -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" +#} diff --git a/terraform/Terraform/01-terraform-basics/outputs.tf b/terraform/Terraform/01-terraform-basics/outputs.tf new file mode 100644 index 00000000..e4a2a6a6 --- /dev/null +++ b/terraform/Terraform/01-terraform-basics/outputs.tf @@ -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 +} \ No newline at end of file diff --git a/terraform/Terraform/01-terraform-basics/resources.tf b/terraform/Terraform/01-terraform-basics/resources.tf new file mode 100644 index 00000000..89a55642 --- /dev/null +++ b/terraform/Terraform/01-terraform-basics/resources.tf @@ -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" +} \ No newline at end of file diff --git a/terraform/Terraform/01-terraform-basics/terraform.tfstate copy.backup b/terraform/Terraform/01-terraform-basics/terraform.tfstate copy.backup new file mode 100644 index 00000000..5fc7a07a --- /dev/null +++ b/terraform/Terraform/01-terraform-basics/terraform.tfstate copy.backup @@ -0,0 +1,103 @@ +{ + "version": 4, + "terraform_version": "1.3.6", + "serial": 19, + "lineage": "d9c75993-9bb6-efe5-f34a-bd19bc924d88", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "aws_iam_user", + "name": "my_iam_users", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "index_key": "jane", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::355852034624:user/jane", + "force_destroy": false, + "id": "jane", + "name": "jane", + "path": "/", + "permissions_boundary": null, + "tags": null, + "tags_all": {}, + "unique_id": "AIDAVFWTPEJAMCULGW6SN" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + }, + { + "index_key": "ranga", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::355852034624:user/ranga", + "force_destroy": false, + "id": "ranga", + "name": "ranga", + "path": "/", + "permissions_boundary": null, + "tags": null, + "tags_all": {}, + "unique_id": "AIDAVFWTPEJAO4FJMFFZB" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + }, + { + "index_key": "ravs", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::355852034624:user/ravs", + "force_destroy": false, + "id": "ravs", + "name": "ravs", + "path": "/", + "permissions_boundary": null, + "tags": null, + "tags_all": {}, + "unique_id": "AIDAVFWTPEJAG42DV5GUV" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + }, + { + "index_key": "sats", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::355852034624:user/sats", + "force_destroy": false, + "id": "sats", + "name": "sats", + "path": "/", + "permissions_boundary": null, + "tags": null, + "tags_all": {}, + "unique_id": "AIDAVFWTPEJAGJDVS3IWP" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + }, + { + "index_key": "tom", + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::355852034624:user/tom", + "force_destroy": false, + "id": "tom", + "name": "tom", + "path": "/", + "permissions_boundary": null, + "tags": null, + "tags_all": {}, + "unique_id": "AIDAVFWTPEJAJNNDAAHPS" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": null +} diff --git a/terraform/Terraform/02-more-terraform-basics/main.tf b/terraform/Terraform/02-more-terraform-basics/main.tf new file mode 100644 index 00000000..bb30f92e --- /dev/null +++ b/terraform/Terraform/02-more-terraform-basics/main.tf @@ -0,0 +1,13 @@ +variable "iam_user_name_prefix" { + type = string #any, number, bool, list, map, set, object, tuple + default = "my_iam_user" +} + +provider "aws" { + region = "us-east-1" +} + +resource "aws_iam_user" "my_iam_users" { + count = 1 + name = "${var.iam_user_name_prefix}_${count.index}" +} \ No newline at end of file diff --git a/terraform/Terraform/02-more-terraform-basics/terraform.tfvars b/terraform/Terraform/02-more-terraform-basics/terraform.tfvars new file mode 100644 index 00000000..5e3e390e --- /dev/null +++ b/terraform/Terraform/02-more-terraform-basics/terraform.tfvars @@ -0,0 +1 @@ +iam_user_name_prefix = "VALUE_FORM_TERRAFORM_TFVARS" \ No newline at end of file diff --git a/terraform/Terraform/03-lists-and-sets/main.tf b/terraform/Terraform/03-lists-and-sets/main.tf new file mode 100644 index 00000000..7332e9b4 --- /dev/null +++ b/terraform/Terraform/03-lists-and-sets/main.tf @@ -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 +} \ No newline at end of file diff --git a/terraform/Terraform/04-maps/04-maps/main.tf b/terraform/Terraform/04-maps/04-maps/main.tf new file mode 100644 index 00000000..7332e9b4 --- /dev/null +++ b/terraform/Terraform/04-maps/04-maps/main.tf @@ -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 +} \ No newline at end of file diff --git a/terraform/Terraform/05-ec2-instances b/terraform/Terraform/05-ec2-instances new file mode 100644 index 00000000..68638998 --- /dev/null +++ b/terraform/Terraform/05-ec2-instances @@ -0,0 +1,5 @@ +US East (N. Virginia) +Amazon Machine Image (AMI) ami-0b5eea76982371e91 +Instance Type - t2.micro +VPC - vpc-02523c91a94e96bca +Security Group \ No newline at end of file