diff --git a/AWS Module/EC2 Instance/Variable.tf b/AWS Module/EC2 Instance/Variable.tf new file mode 100644 index 0000000..fe0bf75 --- /dev/null +++ b/AWS Module/EC2 Instance/Variable.tf @@ -0,0 +1,48 @@ +variable "access_key" { + description = "Access key to AWS console" + type = Secret + +} +variable "secret_key" { + description = "Secret key to AWS console" + type = secret_key +} + +variable "region" { + type = string +} + +variable "instance_name" { + description = "Value of the Name tag for the EC2 instance" + type = string +} + +variable "instance_name" { + description = "Name of the instance to be created" + type = string +} + +variable "instance_type" { + description = "type of instance " + default = "t2.micro" +} + +variable "subnet_id" { + description = "The VPC subnet the instance(s) will be created in" + type = string +} + +variable "ami_id" { + description = "The AMI to use" + type = string +} + +variable "number_of_instances" { + description = "number of instances to be created" + default = 1 +} + + +variable "ami_key_pair_name" { + description = "name of your keypair" +} \ No newline at end of file diff --git a/AWS Module/EC2 Instance/main.tf b/AWS Module/EC2 Instance/main.tf new file mode 100644 index 0000000..2e5e1b7 --- /dev/null +++ b/AWS Module/EC2 Instance/main.tf @@ -0,0 +1,19 @@ +provider "aws" { + access_key = "${var.access_key}" + secret_key = "${var.secret_key}" + region = "${var.region}" +} + +resource "aws_instance" "ec2_instance" { + ami = "${var.ami_id}" + count = "${var.number_of_instances}" + subnet_id = "${var.subnet_id}" + instance_type = "${var.instance_type}" + key_name = "${var.ami_key_pair_name}" + security_groups = [ "value" ] + + + tags = { + Name = "${var.instance_name}" + } +} \ No newline at end of file diff --git a/AWS Module/EC2 Instance/output.tf b/AWS Module/EC2 Instance/output.tf new file mode 100644 index 0000000..191de2d --- /dev/null +++ b/AWS Module/EC2 Instance/output.tf @@ -0,0 +1,16 @@ +output "Private_ip" { + value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2instance.*.private_ip) +} + +output "Public_ip" { + value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2instance.*.private_ip) +} + + +output "public_dns" { + value = zipmap(aws_instance.ec2instance.*.tags.Name, aws_eip.eip.*.public_dns) +} + +output "private_dns" { + value = zipmap(aws_instance.ec2instance.*.tags.Name, aws_instance.ec2instance.*.private_dns) +} \ No newline at end of file diff --git a/AWS Module/EC2 Instance/terraform.tfvars b/AWS Module/EC2 Instance/terraform.tfvars new file mode 100644 index 0000000..8e9ea21 --- /dev/null +++ b/AWS Module/EC2 Instance/terraform.tfvars @@ -0,0 +1,2 @@ +access_key = "Access Key of IAM User" +secret_key = "Secret Key of IAM User" \ No newline at end of file diff --git a/AWS Module/Load Balancer/main.tf b/AWS Module/Load Balancer/main.tf new file mode 100644 index 0000000..5587b4b --- /dev/null +++ b/AWS Module/Load Balancer/main.tf @@ -0,0 +1,52 @@ +resource "aws_lb" "alb" { + name = "${var.alb_name}" + internal = true + load_balancer_type = "applcation" + security_groups = ["value"] + subnets = [ "value" ] + enable_http2 = false + enable_deletion_protection = false + + tags = { + name = "${var.alb_name}" + } +} + + +resource "aws_lb_target_group" "target_group" { + name = "${var.tg_name}" + port = 80 + protocol = "HTTP" + target_type = "instance" + vpc_id = [] + + health_check { + path = "/" + protocol = "HTTP" + matcher = "200" + interval = 15 + healthy_threshold = 3 + timeout = 3 + unhealthy_threshold = 3 + } + +} + +resource "aws_lb_target_group_attachment" "tg_atch" { + target_group_arn = aws_lb_target_group.target_group.arn + target_id = aws_lb_target_group.target_group.id + port = 80 +} + +resource "aws_lb_listener" "front_end" { + load_balancer_arn = aws_lb.alb.arn + port = "80" + protocol = "HTTP" + + default_action { + type = "forward" + target_group_arn = aws_lb_target_group.target_group.arn + } + +} + diff --git a/AWS Module/Load Balancer/output.tf b/AWS Module/Load Balancer/output.tf new file mode 100644 index 0000000..0f8b7ce --- /dev/null +++ b/AWS Module/Load Balancer/output.tf @@ -0,0 +1,3 @@ +output "alb_id" { + value = aws_lb.lb.dns_name +} \ No newline at end of file diff --git a/AWS Module/Load Balancer/variable.tf b/AWS Module/Load Balancer/variable.tf new file mode 100644 index 0000000..98c79a1 --- /dev/null +++ b/AWS Module/Load Balancer/variable.tf @@ -0,0 +1,5 @@ +variable "alb_name" { + description ="name of the application load balancer" + type = string +} + diff --git a/AWS Module/Route 53/main.tf b/AWS Module/Route 53/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/AWS Module/Route 53/output.tf b/AWS Module/Route 53/output.tf new file mode 100644 index 0000000..e69de29 diff --git a/AWS Module/Route 53/variable.tf b/AWS Module/Route 53/variable.tf new file mode 100644 index 0000000..e69de29 diff --git a/AWS Module/Security Group/main.tf b/AWS Module/Security Group/main.tf new file mode 100644 index 0000000..1e0204f --- /dev/null +++ b/AWS Module/Security Group/main.tf @@ -0,0 +1,29 @@ +resource "aws_security_group" "security_group" { + + name = "${var.security_group}" + vpc_id = [value] + + ingress = [ { + cidr_blocks = [ "value" ] + description = "value" + from_port = 1 + ipv6_cidr_blocks = [ "value" ] + prefix_list_ids = [ "value" ] + protocol = "value" + security_groups = ["value"] + self = false + to_port = 1 + } ] + + egress = [ { + cidr_blocks = [ "value" ] + description = "value" + from_port = 1 + ipv6_cidr_blocks = [ "value" ] + prefix_list_ids = [ "value" ] + protocol = "value" + security_groups = [ "value" ] + self = false + to_port = 1 + } ] +} \ No newline at end of file diff --git a/AWS Module/Security Group/output.tf b/AWS Module/Security Group/output.tf new file mode 100644 index 0000000..6413c9b --- /dev/null +++ b/AWS Module/Security Group/output.tf @@ -0,0 +1,3 @@ +output "security_group" { + value = aws_security_group.security_group.id +} \ No newline at end of file diff --git a/AWS Module/Security Group/variable.tf b/AWS Module/Security Group/variable.tf new file mode 100644 index 0000000..ac71327 --- /dev/null +++ b/AWS Module/Security Group/variable.tf @@ -0,0 +1,4 @@ +variable "security_group" { + description = "name of the sequrity group" + type = string +} \ No newline at end of file diff --git a/AWS Module/VPC/main.tf b/AWS Module/VPC/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/AWS Module/VPC/output.tf b/AWS Module/VPC/output.tf new file mode 100644 index 0000000..e69de29 diff --git a/AWS Module/VPC/variable.tf b/AWS Module/VPC/variable.tf new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index bffd293..46f96ad 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# Terraform \ No newline at end of file +# Terraform diff --git a/aws_module/ec2_instance/.gitignore b/aws_module/ec2_instance/.gitignore new file mode 100644 index 0000000..a0c07d9 --- /dev/null +++ b/aws_module/ec2_instance/.gitignore @@ -0,0 +1,28 @@ +# Ignore .terraform directory +.terraform/ + +# Ignore any generated files +*.tfstate +*.tfstate.backup +*.tfvars + +# Ignore any override files +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Ignore any local files +terraform.tfstate +terraform.tfstate.backup + +# Ignore any plan files +*.tfplan + +# Ignore any log files +*.log +*.out +*.aux + +# Ignore any .DS_Store files (macOS specific) +.DS_Store diff --git a/aws_module/ec2_instance/main.tf b/aws_module/ec2_instance/main.tf new file mode 100644 index 0000000..cdba70e --- /dev/null +++ b/aws_module/ec2_instance/main.tf @@ -0,0 +1,37 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.16" + } + } + + required_version = ">= 1.2.0" +} + +provider "aws" { + region = "us-east-1" +} + + + +resource "aws_instance" "ec2_instance" { + ami = var.ami_id + subnet_id = var.subnet_id + instance_type = var.instance_type + + #key_name = var.ami_key_pair_name + #security_groups = aws_security_group.security_group.id + #count = var.number_of_instances + + + tags = { + Name = "${var.instance_name}" + } +} + + +resource "aws_eip" "elastic_ip" { + instance = aws_instance.ec2_instance.id + vpc = true +} \ No newline at end of file diff --git a/aws_module/ec2_instance/output.tf b/aws_module/ec2_instance/output.tf new file mode 100644 index 0000000..f731daf --- /dev/null +++ b/aws_module/ec2_instance/output.tf @@ -0,0 +1,17 @@ +output "Private_ip" { + value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2_instance.*.private_ip) +} + +output "Public_ip" { + value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2_instance.*.private_ip) +} + + +#output "public_dns" { +# value = zipmap(aws_instance.ec2instance.*.tags.Name, aws_eip.eip.*.public_dns) +#} + + +output "private_dns" { + value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2_instance.*.private_dns) +} \ No newline at end of file diff --git a/aws_module/ec2_instance/terraform.tfvars b/aws_module/ec2_instance/terraform.tfvars new file mode 100644 index 0000000..8e9ea21 --- /dev/null +++ b/aws_module/ec2_instance/terraform.tfvars @@ -0,0 +1,2 @@ +access_key = "Access Key of IAM User" +secret_key = "Secret Key of IAM User" \ No newline at end of file diff --git a/aws_module/ec2_instance/variable.tf b/aws_module/ec2_instance/variable.tf new file mode 100644 index 0000000..021637d --- /dev/null +++ b/aws_module/ec2_instance/variable.tf @@ -0,0 +1,38 @@ + +variable "region" { + type = string + default = "us-east-1" +} + +variable "instance_name" { + description = "Name of the instance to be created" + type = string + default = "hostapace_ec2" +} + +variable "instance_type" { + description = "type of instance " + default = "t2.micro" +} + +variable "subnet_id" { + description = "The VPC subnet the instance(s) will be created in" + type = string +} + +variable "ami_id" { + description = "The AMI to use" + type = string + default = "ami-006dcf34c09e50022" +} + +variable "number_of_instances" { + description = "number of instances to be created" + default = 1 +} + + +variable "ami_key_pair_name" { + description = "name of your keypair" + default = "./mykeypair.pem" +} \ No newline at end of file diff --git a/aws_module/load_balancer/main.tf b/aws_module/load_balancer/main.tf new file mode 100644 index 0000000..ca61660 --- /dev/null +++ b/aws_module/load_balancer/main.tf @@ -0,0 +1,52 @@ +resource "aws_lb" "alb" { + name = "${var.alb_name}" + internal = true + load_balancer_type = "applcation" + security_groups = aws_security_group.security_group.id + subnets = [ "value" ] + enable_http2 = false + enable_deletion_protection = false + + tags = { + name = "${var.alb_name}" + } +} + + +resource "aws_lb_target_group" "target_group" { + name = "${var.tg_name}" + port = 80 + protocol = "HTTP" + target_type = "instance" + vpc_id = [] + + health_check { + path = "/" + protocol = "HTTP" + matcher = "200" + interval = 15 + healthy_threshold = 3 + timeout = 3 + unhealthy_threshold = 3 + } + +} + +resource "aws_lb_target_group_attachment" "tg_atch" { + target_group_arn = aws_lb_target_group.target_group.arn + target_id = aws_lb_target_group.target_group.id + port = 80 +} + +resource "aws_lb_listener" "front_end" { + load_balancer_arn = aws_lb.alb.arn + port = "80" + protocol = "HTTP" + + default_action { + type = "forward" + target_group_arn = aws_lb_target_group.target_group.arn + } + +} + diff --git a/aws_module/load_balancer/output.tf b/aws_module/load_balancer/output.tf new file mode 100644 index 0000000..0f8b7ce --- /dev/null +++ b/aws_module/load_balancer/output.tf @@ -0,0 +1,3 @@ +output "alb_id" { + value = aws_lb.lb.dns_name +} \ No newline at end of file diff --git a/aws_module/load_balancer/variable.tf b/aws_module/load_balancer/variable.tf new file mode 100644 index 0000000..98c79a1 --- /dev/null +++ b/aws_module/load_balancer/variable.tf @@ -0,0 +1,5 @@ +variable "alb_name" { + description ="name of the application load balancer" + type = string +} + diff --git a/aws_module/route53/main.tf b/aws_module/route53/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/aws_module/route53/output.tf b/aws_module/route53/output.tf new file mode 100644 index 0000000..e69de29 diff --git a/aws_module/route53/variable.tf b/aws_module/route53/variable.tf new file mode 100644 index 0000000..e69de29 diff --git a/aws_module/security_group/main.tf b/aws_module/security_group/main.tf new file mode 100644 index 0000000..1e0204f --- /dev/null +++ b/aws_module/security_group/main.tf @@ -0,0 +1,29 @@ +resource "aws_security_group" "security_group" { + + name = "${var.security_group}" + vpc_id = [value] + + ingress = [ { + cidr_blocks = [ "value" ] + description = "value" + from_port = 1 + ipv6_cidr_blocks = [ "value" ] + prefix_list_ids = [ "value" ] + protocol = "value" + security_groups = ["value"] + self = false + to_port = 1 + } ] + + egress = [ { + cidr_blocks = [ "value" ] + description = "value" + from_port = 1 + ipv6_cidr_blocks = [ "value" ] + prefix_list_ids = [ "value" ] + protocol = "value" + security_groups = [ "value" ] + self = false + to_port = 1 + } ] +} \ No newline at end of file diff --git a/aws_module/security_group/output.tf b/aws_module/security_group/output.tf new file mode 100644 index 0000000..6413c9b --- /dev/null +++ b/aws_module/security_group/output.tf @@ -0,0 +1,3 @@ +output "security_group" { + value = aws_security_group.security_group.id +} \ No newline at end of file diff --git a/aws_module/security_group/variable.tf b/aws_module/security_group/variable.tf new file mode 100644 index 0000000..19c06a2 --- /dev/null +++ b/aws_module/security_group/variable.tf @@ -0,0 +1,5 @@ +variable "security_group" { + description = "name of the sequrity group" + type = string + default = "hostspace" +} \ No newline at end of file diff --git a/aws_module/vpc/main.tf b/aws_module/vpc/main.tf new file mode 100644 index 0000000..dcaa920 --- /dev/null +++ b/aws_module/vpc/main.tf @@ -0,0 +1,24 @@ +data "aws_availability_zones" "available"{} + +locals { + name = var.vpc_name + +} + +module "vpc" { + source = "terraform-aws-modules/vpc/aws" + name = "${var.name}" + cidr = "10.0.0.0/16" + + azs = slice(data.aws_availability_zones.available.names, 0, 3) + private_subnet = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] + public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] + + enable_nat_gateway = true + single_nat_gateway = true + enable_dns_hostnames = true + + tags = { + + } +} \ No newline at end of file diff --git a/aws_module/vpc/output.tf b/aws_module/vpc/output.tf new file mode 100644 index 0000000..e69de29 diff --git a/aws_module/vpc/variable.tf b/aws_module/vpc/variable.tf new file mode 100644 index 0000000..e69de29 diff --git a/eks/.gitignore b/eks/.gitignore new file mode 100644 index 0000000..a0c07d9 --- /dev/null +++ b/eks/.gitignore @@ -0,0 +1,28 @@ +# Ignore .terraform directory +.terraform/ + +# Ignore any generated files +*.tfstate +*.tfstate.backup +*.tfvars + +# Ignore any override files +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Ignore any local files +terraform.tfstate +terraform.tfstate.backup + +# Ignore any plan files +*.tfplan + +# Ignore any log files +*.log +*.out +*.aux + +# Ignore any .DS_Store files (macOS specific) +.DS_Store diff --git a/eks/.terraform.lock.hcl b/eks/.terraform.lock.hcl new file mode 100644 index 0000000..8219ed1 --- /dev/null +++ b/eks/.terraform.lock.hcl @@ -0,0 +1,122 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/gavinbunney/kubectl" { + version = "1.14.0" + constraints = ">= 1.14.0" + hashes = [ + "h1:gLFn+RvP37sVzp9qnFCwngRjjFV649r6apjxvJ1E/SE=", + "zh:0350f3122ff711984bbc36f6093c1fe19043173fad5a904bce27f86afe3cc858", + "zh:07ca36c7aa7533e8325b38232c77c04d6ef1081cb0bac9d56e8ccd51f12f2030", + "zh:0c351afd91d9e994a71fe64bbd1662d0024006b3493bb61d46c23ea3e42a7cf5", + "zh:39f1a0aa1d589a7e815b62b5aa11041040903b061672c4cfc7de38622866cbc4", + "zh:428d3a321043b78e23c91a8d641f2d08d6b97f74c195c654f04d2c455e017de5", + "zh:4baf5b1de2dfe9968cc0f57fd4be5a741deb5b34ee0989519267697af5f3eee5", + "zh:6131a927f9dffa014ab5ca5364ac965fe9b19830d2bbf916a5b2865b956fdfcf", + "zh:c62e0c9fd052cbf68c5c2612af4f6408c61c7e37b615dc347918d2442dd05e93", + "zh:f0beffd7ce78f49ead612e4b1aefb7cb6a461d040428f514f4f9cc4e5698ac65", + ] +} + +provider "registry.terraform.io/hashicorp/aws" { + version = "4.57.0" + constraints = ">= 3.63.0, >= 3.72.0" + hashes = [ + "h1:0bd5IKkEF1TGE4tgm0VuVMFQg2s6GOXJBU+/b/siYKw=", + "zh:07d89ad94267b7d6285fd65fbd67f8680e111abf9bbcbcac2e30154262fbbe46", + "zh:0eeee044e6fc285c20241d3de7f9b79450cab2df1452a9c18c0bed1090085a25", + "zh:306ba8ac99a0d9f9eba0386cb11459323696e69dcb28bc5e55b6fb2de28640cd", + "zh:40afc24b94e7cae387f22dd3045b09311a120e429aa4f06168d7498995a98f67", + "zh:5a2c846a2cc463841ca2353fb734ba6f9502e662196c85fd3332a4e18acec72e", + "zh:854fbf7d058e4e31ce4ed882e2085bd94c53be4b38b15f3b5d3d897a2c5102df", + "zh:89a7a5e7de6400662804d5dc43251172e3f0522853dcab304d637a7bbb266654", + "zh:89ef96a1b36396f555e80505f55fd29432be3dc518bd75b72a1aae29e8171b4a", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:b28516cc8e614fad40738ec73ce70528e2a817dae3118895333c1d63f1e22a89", + "zh:c3f1c6a7d56b0838da2f880a74e19df65ca9006cb3ebdc34403cb9d6e4ee046d", + "zh:d036a7355494792e2347b92d766431ba91cb399a4bd2bb719db3025542c0e674", + "zh:d3299b9507085238aaf24f38faffb5d6226a31f916e47320b31d728c7062be16", + "zh:d9f5c04f4648d593d91be2a66c6c61f6c52512c78ac6fb3077f0911a6b95fa2f", + "zh:f84143ee0cff2ad0af8ad40074fb5dcd83bfb8a514c7f43ca23c7422caa42330", + ] +} + +provider "registry.terraform.io/hashicorp/cloudinit" { + version = "2.3.2" + constraints = ">= 2.0.0" + hashes = [ + "h1:Vl0aixAYTV/bjathX7VArC5TVNkxBCsi3Vq7R4z1uvc=", + "zh:2487e498736ed90f53de8f66fe2b8c05665b9f8ff1506f751c5ee227c7f457d1", + "zh:3d8627d142942336cf65eea6eb6403692f47e9072ff3fa11c3f774a3b93130b3", + "zh:434b643054aeafb5df28d5529b72acc20c6f5ded24decad73b98657af2b53f4f", + "zh:436aa6c2b07d82aa6a9dd746a3e3a627f72787c27c80552ceda6dc52d01f4b6f", + "zh:458274c5aabe65ef4dbd61d43ce759287788e35a2da004e796373f88edcaa422", + "zh:54bc70fa6fb7da33292ae4d9ceef5398d637c7373e729ed4fce59bd7b8d67372", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:893ba267e18749c1a956b69be569f0d7bc043a49c3a0eb4d0d09a8e8b2ca3136", + "zh:95493b7517bce116f75cdd4c63b7c82a9d0d48ec2ef2f5eb836d262ef96d0aa7", + "zh:9ae21ab393be52e3e84e5cce0ef20e690d21f6c10ade7d9d9d22b39851bfeddc", + "zh:cc3b01ac2472e6d59358d54d5e4945032efbc8008739a6d4946ca1b621a16040", + "zh:f23bfe9758f06a1ec10ea3a81c9deedf3a7b42963568997d84a5153f35c5839a", + ] +} + +provider "registry.terraform.io/hashicorp/helm" { + version = "2.9.0" + constraints = ">= 2.6.0" + hashes = [ + "h1:D5BLFN82WndhQZQleXE5rO0hUDnlyqb60XeUJKDhuo4=", + "zh:1471cb45908b426104687c962007b2980cfde294fa3530fabc4798ce9fb6c20c", + "zh:1572e9cec20591ec08ece797b3630802be816a5adde36ca91a93359f2430b130", + "zh:1b10ae03cf5ab1ae21ffaac2251de99797294ae4242b156b3b0beebbdbcb7e0f", + "zh:3bd043b68de967d8d0b549d3f71485193d81167d5656f5507d743dedfe60e352", + "zh:538911921c729185900176cc22eb8edcb822bc8d22b9ebb48103a1d9bb53cc38", + "zh:69a6a2d40c0463662c3fb1621e37a3ee65024ea4479adf4d5f7f19fb0dea48c2", + "zh:94b58daa0c351a49d01f6d8f1caae46c95c2d6c3f29753e2b9ea3e3c0e7c9ab4", + "zh:9d0543331a4a32241e1ab5457f30b41df745acb235a0391205c725a5311e4809", + "zh:a6789306524ca121512a95e873e3949b4175114a6c5db32bed2df2551a79368f", + "zh:d146b94cd9502cca7f2044797a328d71c7ec2a98e2d138270d8a28c872f04289", + "zh:d14ccd14511f0446eacf43a9243f22de7c1427ceb059cf67d7bf9803be2cb15d", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} + +provider "registry.terraform.io/hashicorp/kubernetes" { + version = "2.18.1" + constraints = ">= 2.10.0" + hashes = [ + "h1:h4ezMuMNyKRMRhlrErph7QOUToc77U+rVKdR48w6tr8=", + "zh:09d69d244f5e688d9b1582112aa5d151c5336278e43d39c88ae920c26536b753", + "zh:0df4c988056f7d84d9161c6c955ad7346364c261d100ef510a6cc7fa4a235197", + "zh:2d3d0cb2931b6153a7971ce8c6fae92722b1116e16f42abbaef115dba895c8d8", + "zh:47830e8fc1760860bfa4aaf418627ff3c6ffcac6cebbbc490e5e0e6b31287d80", + "zh:49467177b514bada0fb3b6982897a347498af8ef9ef8d9fd611fe21dfded2e25", + "zh:5c7eae2c51ba175822730a63ad59cf41604c76c46c5c97332506ab42023525ce", + "zh:6efae755f02df8ab65ce7a831f33bd4817359db205652fd4bc4b969302072b15", + "zh:7e6e97b79fecd25aaf0f4fb91da945a65c36fe2ba2a4313288a60ede55506aad", + "zh:b75f2c9dd24b355ffe73e7b2fcd3145fc32735068f0ec2eba2df63f792dd16e8", + "zh:dbef9698d842eb49a846db6d7694f159ae5154ffbb7a753a9d4cab88c462a6d4", + "zh:f1b1fd580d92eedd9c8224d463997ccff1a62851fea65106aac299efe9ab622a", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} + +provider "registry.terraform.io/hashicorp/tls" { + version = "4.0.4" + constraints = ">= 3.0.0" + hashes = [ + "h1:pe9vq86dZZKCm+8k1RhzARwENslF3SXb9ErHbQfgjXU=", + "zh:23671ed83e1fcf79745534841e10291bbf34046b27d6e68a5d0aab77206f4a55", + "zh:45292421211ffd9e8e3eb3655677700e3c5047f71d8f7650d2ce30242335f848", + "zh:59fedb519f4433c0fdb1d58b27c210b27415fddd0cd73c5312530b4309c088be", + "zh:5a8eec2409a9ff7cd0758a9d818c74bcba92a240e6c5e54b99df68fff312bbd5", + "zh:5e6a4b39f3171f53292ab88058a59e64825f2b842760a4869e64dc1dc093d1fe", + "zh:810547d0bf9311d21c81cc306126d3547e7bd3f194fc295836acf164b9f8424e", + "zh:824a5f3617624243bed0259d7dd37d76017097dc3193dac669be342b90b2ab48", + "zh:9361ccc7048be5dcbc2fafe2d8216939765b3160bd52734f7a9fd917a39ecbd8", + "zh:aa02ea625aaf672e649296bce7580f62d724268189fe9ad7c1b36bb0fa12fa60", + "zh:c71b4cd40d6ec7815dfeefd57d88bc592c0c42f5e5858dcc88245d371b4b8b1e", + "zh:dabcd52f36b43d250a3d71ad7abfa07b5622c69068d989e60b79b2bb4f220316", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} diff --git a/eks/eks.tf b/eks/eks.tf new file mode 100644 index 0000000..d23da2e --- /dev/null +++ b/eks/eks.tf @@ -0,0 +1,102 @@ +module "eks" { + source = "terraform-aws-modules/eks/aws" + version = "18.29.0" + + cluster_name = "hostspace-eks" + cluster_version = "1.23" + + cluster_endpoint_private_access = true + cluster_endpoint_public_access = true + + vpc_id = module.vpc.vpc_id + subnet_ids = module.vpc.private_subnets + + enable_irsa = true + + eks_managed_node_group_defaults = { + disk_size = 50 + } + + + + eks_managed_node_groups = { + general = { + desired_size = 1 + min_size = 1 + max_size = 10 + + labels = { + role = "general" + } + + instance_types = ["t3.small"] + capacity_type = "ON_DEMAND" + } + + spot = { + desired_size = 1 + min_size = 1 + max_size = 10 + + labels = { + role = "spot" + } + + taints = [{ + key = "market" + value = "spot" + effect = "NO_SCHEDULE" + }] + + instance_types = ["t3.micro"] + capacity_type = "SPOT" + } + } + + + manage_aws_auth_configmap = true + aws_auth_roles = [ + { + rolearn = module.eks_admins_iam_role.iam_role_arn + username = module.eks_admins_iam_role.iam_role_name + groups = ["system:masters"] + }, + ] + + node_security_group_additional_rules = { + ingress_allow_access_from_control_plane = { + type = "ingress" + protocol = "tcp" + from_port = 9443 + to_port = 9443 + source_cluster_security_group = true + description = "Allow access from control plane to webhook port of AWS load balancer controller" + } + } + + + tags = { + Environment = "dev" + } +} + +# https://github.com/terraform-aws-modules/terraform-aws-eks/issues/2009 +data "aws_eks_cluster" "default" { + name = module.eks.cluster_id +} + +data "aws_eks_cluster_auth" "default" { + name = module.eks.cluster_id +} + +provider "kubernetes" { + host = data.aws_eks_cluster.default.endpoint + cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data) + # token = data.aws_eks_cluster_auth.default.token + + exec { + api_version = "client.authentication.k8s.io/v1beta1" + args = ["eks", "get-token", "--cluster-name", data.aws_eks_cluster.default.id] + command = "aws" + } +} \ No newline at end of file diff --git a/eks/eks_iam.tf b/eks/eks_iam.tf new file mode 100644 index 0000000..f5fe81b --- /dev/null +++ b/eks/eks_iam.tf @@ -0,0 +1,89 @@ +############ creatiang the iam policy ########################## + +module "allow_eks_access_iam_policy" { + source = "terraform-aws-modules/iam/aws//modules/iam-policy" + version = "5.3.1" + + name = "allow-eks-access" + create_policy = true + + policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Action = [ + "eks:DescribeCluster", + ] + Effect = "Allow" + Resource = "*" + }, + ] + }) +} + +############################# Iam role ###################### + +module "eks_admins_iam_role" { + source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role" + version = "5.3.1" + + role_name = "eks-admin" + create_role = true + role_requires_mfa = false + + custom_role_policy_arns = [module.allow_eks_access_iam_policy.arn] + + trusted_role_arns = [ + "arn:aws:iam::${module.vpc.vpc_owner_id}:root" + ] +} + +################# iam user ############## + +module "user1_iam_user" { + source = "terraform-aws-modules/iam/aws//modules/iam-user" + version = "5.3.1" + + name = "user1" + create_iam_access_key = false + create_iam_user_login_profile = false + + force_destroy = true +} + +############# to allow assumption of eks adim iam role ####################### + +module "allow_assume_eks_admins_iam_policy" { + source = "terraform-aws-modules/iam/aws//modules/iam-policy" + version = "5.3.1" + + name = "allow-assume-eks-admin-iam-role" + create_policy = true + + policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Action = [ + "sts:AssumeRole", + ] + Effect = "Allow" + Resource = module.eks_admins_iam_role.iam_role_arn + }, + ] + }) +} + + +###################### creating an IAM groud and adding user1 to the group ################## + +module "eks_admins_iam_group" { + source = "terraform-aws-modules/iam/aws//modules/iam-group-with-policies" + version = "5.3.1" + + name = "eks-admin" + attach_iam_self_management_policy = false + create_group = true + group_users = [module.user1_iam_user.iam_user_name] + custom_group_policy_arns = [module.allow_assume_eks_admins_iam_policy.arn] +} \ No newline at end of file diff --git a/eks/provider.tf b/eks/provider.tf new file mode 100644 index 0000000..97d4dc3 --- /dev/null +++ b/eks/provider.tf @@ -0,0 +1,18 @@ +provider "aws" { + region = "us-east-1" +} + +terraform { + required_providers { + kubectl = { + source = "gavinbunney/kubectl" + version = ">= 1.14.0" + } + helm = { + source = "hashicorp/helm" + version = ">= 2.6.0" + } + } + + required_version = "~> 1.0" +} \ No newline at end of file diff --git a/eks/vpc.tf b/eks/vpc.tf new file mode 100644 index 0000000..5613fd8 --- /dev/null +++ b/eks/vpc.tf @@ -0,0 +1,30 @@ +module "vpc" { + source = "terraform-aws-modules/vpc/aws" + version = "3.14.3" + + name = "main" + cidr = "10.0.0.0/16" + + azs = ["us-east-1a", "us-east-1b"] + private_subnets = ["10.0.0.0/19", "10.0.32.0/19"] + public_subnets = ["10.0.64.0/19", "10.0.96.0/19"] + + public_subnet_tags = { + "kubernates.io/role/elb" = "1" + } + + private_subnet_tags = { + "kubernates.io/role/internal-elb" = "1" + } + + enable_nat_gateway = true + single_nat_gateway = true + one_nat_gateway_per_az = false + + enable_dns_hostnames = true + enable_dns_support = true + + tags = { + environment = "dev" + } +} \ No newline at end of file