diff --git a/create_dynamodb/main.tf b/create_dynamodb/main.tf new file mode 100644 index 0000000..f6711e4 --- /dev/null +++ b/create_dynamodb/main.tf @@ -0,0 +1,17 @@ +provider "aws" { + region = var.region +} + +resource "aws_dynamodb_table" "table" { + name = var.name + billing_mode = var.billing_mode + read_capacity = var.read_capacity + write_capacity = var.write_capacity + hash_key = "LockID" + + attribute { + name = "LockID" + type = "S" + } + tags = var.tags +} diff --git a/create_dynamodb/output.tf b/create_dynamodb/output.tf new file mode 100644 index 0000000..b62273c --- /dev/null +++ b/create_dynamodb/output.tf @@ -0,0 +1,9 @@ +output "table_name" { + description = "The name of the DynamoDB table" + value = aws_dynamodb_table.table.name +} + +output "table_arn" { + description = "The ARN of the DynamoDB table" + value = aws_dynamodb_table.table.arn +} diff --git a/create_dynamodb/vars.tf b/create_dynamodb/vars.tf new file mode 100644 index 0000000..21bdbbc --- /dev/null +++ b/create_dynamodb/vars.tf @@ -0,0 +1,32 @@ +variable "region" { + type = string + description = "region of dynamodb table" + default = "" +} +variable "name" { + type = string + description = "name of dynamodb table" + default = "" +} +variable "billing_mode" { + description = "Controls how you are charged for read and write throughput and how you manage capacity" + type = string + default = "PROVISIONED" +} + +variable "read_capacity" { + description = "The number of read units for this table" + type = number + default = 5 +} + +variable "write_capacity" { + description = "The number of write units for this table" + type = number + default = 5 +} +variable "tags" { + description = "A mapping of tags to assign to the table" + type = map(string) + default = {} +} \ No newline at end of file diff --git a/create_s3/main.tf b/create_s3/main.tf new file mode 100644 index 0000000..43db72b --- /dev/null +++ b/create_s3/main.tf @@ -0,0 +1,13 @@ +provider "aws" { + region = var.region +} +resource "aws_s3_bucket" "this" { + bucket_prefix = var.bucket_prefix + tags = var.tags +} +resource "aws_s3_bucket_versioning" "this" { + bucket = aws_s3_bucket.this.id + versioning_configuration { + status = "Enabled" + } +} \ No newline at end of file diff --git a/create_s3/output.tf b/create_s3/output.tf new file mode 100644 index 0000000..2049fc3 --- /dev/null +++ b/create_s3/output.tf @@ -0,0 +1,12 @@ +output "bucket_region" { + description = "The region of the bucket" + value = aws_s3_bucket.this.region +} +output "bucket_name" { + description = "The name of the bucket" + value = aws_s3_bucket.this.bucket_prefix +} +output "bucket_arn" { + description = "The ARN of the bucket" + value = aws_s3_bucket.this.arn +} diff --git a/create_s3/vars.tf b/create_s3/vars.tf new file mode 100644 index 0000000..7ff93e8 --- /dev/null +++ b/create_s3/vars.tf @@ -0,0 +1,16 @@ +variable "region" { + description = "Region to create s3_bucket" + type = string + default = "" +} + +variable "bucket_prefix" { + description = "Prefix of the bucket name to create" + type = string + default = "" +} +variable "tags" { + description = "A mapping of tags to assign to the bucket" + type = map(string) + default = {} +} \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..3d071f0 --- /dev/null +++ b/main.tf @@ -0,0 +1,19 @@ +provider "aws" { + region = "ap-south-1" +} +module "s3_bucket" { + source = "./create_s3" + bucket_prefix = "assign4a-581" + tags = { + Environment = "test" + Owner = "QA team" + } +} +module "dynamodb" { + source = "./create_dynamodb" + name = "assign4b-581" + tags = { + Name = "assign4b" + Environment = "QA" + } +} \ No newline at end of file diff --git a/modules/create_ec2/ec2.tf b/modules/create_ec2/ec2.tf deleted file mode 100644 index 4b1541a..0000000 --- a/modules/create_ec2/ec2.tf +++ /dev/null @@ -1,9 +0,0 @@ -resource "aws_instance" "my-instance" { - ami = var.instance_ami - instance_type = var.instance_type - key_name = var.instance_key - - tags = { - Name = var.instance_name - } -} diff --git a/modules/create_ec2/outputs.tf b/modules/create_ec2/outputs.tf deleted file mode 100644 index 7148642..0000000 --- a/modules/create_ec2/outputs.tf +++ /dev/null @@ -1,7 +0,0 @@ -output "instance_id" { - value = aws_instance.my-instance.id -} - -output "instance_publicip" { - value = aws_instance.my-instance.public_ip -} diff --git a/modules/create_ec2/vars.tf b/modules/create_ec2/vars.tf deleted file mode 100644 index dc55b87..0000000 --- a/modules/create_ec2/vars.tf +++ /dev/null @@ -1,19 +0,0 @@ -variable "instance_type" { - description = "The Instance type to be used for the instance" - type = string -} - -variable "instance_ami" { - description = "The AMI to be used for the instance" - type = string -} - -variable "instance_key" { - description = "The Key to be used for the instance" - type = string -} - -variable "instance_name" { - description = "The name of the instance to create" - type = string -} \ No newline at end of file diff --git a/modules/create_k8s/keys/README.md b/modules/create_k8s/keys/README.md deleted file mode 100644 index 8b13789..0000000 --- a/modules/create_k8s/keys/README.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/modules/create_k8s/main.tf b/modules/create_k8s/main.tf deleted file mode 100644 index 8774c7c..0000000 --- a/modules/create_k8s/main.tf +++ /dev/null @@ -1,165 +0,0 @@ -resource "aws_security_group" "k8s-sg" { - vpc_id = var.vpc-id - - ingress { - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - } - - ingress { - from_port = 6443 - to_port = 6443 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - } - - ingress { - from_port = 2379 - to_port = 2380 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - } - - ingress { - from_port = 10250 - to_port = 10250 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - } - - ingress { - from_port = 10257 - to_port = 10257 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - } - - ingress { - from_port = 10259 - to_port = 10259 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - } - - ingress { - from_port = 30000 - to_port = 32767 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - } - - egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - } - - tags = { - Name = "K8S-SG" - } -} - -resource "tls_private_key" "generic-ssh-key" { - algorithm = "RSA" - rsa_bits = 4096 - - provisioner "local-exec" { - interpreter = ["bash", "-c"] - command = < ./${path.module}/keys/${var.key-name}.pem - chmod 400 ./${path.module}/keys/${var.key-name}.pem - EOF - } -} - -resource "aws_key_pair" "generated_key" { - key_name = var.key-name - public_key = tls_private_key.generic-ssh-key.public_key_openssh -} - -resource "aws_instance" "k8s-master" { - vpc_security_group_ids = [aws_security_group.k8s-sg.id] - ami = var.ami - instance_type = var.k8s-master-size - key_name = var.key-name - tags = { - Name = "K8S-Master" - } - - connection { - type = "ssh" - user = "ubuntu" - host = self.public_ip - private_key = tls_private_key.generic-ssh-key.private_key_openssh - } - - provisioner "file" { - source = "./${path.module}/scripts" - destination = "/home/ubuntu/" - } - - provisioner "remote-exec" { - inline = [ - "sudo sh /home/ubuntu/scripts/k8s-components-install.sh", - "sudo kubeadm init", - "sh /home/ubuntu/scripts/k8s-kubeconfig-cni.sh", - "rm -rf /home/ubuntu/scripts" - ] - } - - provisioner "local-exec" { - interpreter = ["bash", "-c"] - command = <> ./${path.module}/scripts/k8s-kubeadm-join.sh - EOF - } -} - -resource "aws_instance" "k8s-worker" { - depends_on = [ - aws_instance.k8s-master - ] - vpc_security_group_ids = [aws_security_group.k8s-sg.id] - - ami = var.ami - instance_type = var.k8s-worker-size - count = var.k8s-worker-count - key_name = var.key-name - tags = { - Name = "K8S-Worker ${count.index + 1}" - } - - connection { - type = "ssh" - user = "ubuntu" - host = self.public_ip - private_key = tls_private_key.generic-ssh-key.private_key_openssh - } - - provisioner "file" { - source = "./${path.module}/scripts" - destination = "/home/ubuntu/" - } - - provisioner "remote-exec" { - inline = [ - "sudo sh /home/ubuntu/scripts/k8s-components-install.sh", - "sudo sh /home/ubuntu/scripts/k8s-kubeadm-join.sh", - "rm -rf /home/ubuntu/scripts" - ] - } - -} \ No newline at end of file diff --git a/modules/create_k8s/scripts/k8s-components-install.sh b/modules/create_k8s/scripts/k8s-components-install.sh deleted file mode 100644 index 7cadb24..0000000 --- a/modules/create_k8s/scripts/k8s-components-install.sh +++ /dev/null @@ -1,26 +0,0 @@ -#/bin/bash - - # First diasbale swap - sudo swapoff -a 1>/dev/null - # And then to disable swap on startup in /etc/fstab - sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab 1>/dev/null - - apt-get install -y apt-transport-https 1>/dev/null - curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add > /dev/null 2>&1 - echo 'deb http://apt.kubernetes.io/ kubernetes-xenial main' > /etc/apt/sources.list.d/kubernetes.list - - apt-get update > /dev/null 2>&1 - - curl -fsSL https://get.docker.com -o get-docker.sh - sh get-docker.sh > /dev/null 2>&1 - - echo "{ \n \"exec-opts\": [\"native.cgroupdriver=systemd\"]\n}" > /etc/docker/daemon.json - systemctl daemon-reload 1>/dev/null - systemctl restart docker 1>/dev/null - - apt-get install -y kubelet=1.23.8-00 1>/dev/null - apt-get install -y kubeadm=1.23.8-00 1>/dev/null - apt-get install -y kubectl=1.23.8-00 1>/dev/null - apt-get install -y kubernetes-cni 1>/dev/null - -exit diff --git a/modules/create_k8s/scripts/k8s-kubeconfig-cni.sh b/modules/create_k8s/scripts/k8s-kubeconfig-cni.sh deleted file mode 100644 index cbed512..0000000 --- a/modules/create_k8s/scripts/k8s-kubeconfig-cni.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -mkdir -p $HOME/.kube -sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config -sudo chown $(id -u):$(id -g) $HOME/.kube/config - -sudo sysctl net.bridge.bridge-nf-call-iptables=1 -kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml \ No newline at end of file diff --git a/modules/create_k8s/vars.tf b/modules/create_k8s/vars.tf deleted file mode 100644 index eda686b..0000000 --- a/modules/create_k8s/vars.tf +++ /dev/null @@ -1,24 +0,0 @@ -variable "key-name" { - description = "Enter The Key Pair Name to be created on AWS" -} - -variable "k8s-master-size" { - description = "Enter The Key Instance type to be used for K8S Master" -} - -variable "k8s-worker-size" { - description = "Enter The Key Instance type to be used for K8S Worker Nodes" -} - -variable "k8s-worker-count" { - description = "Enter The K8S Worker Nodes to be created" -} - -variable "ami" { - description = "Enter The Ubuntu AMI to be used for EC2 Instances" -} - -variable "vpc-id" { - description = "Enter the VPC-ID under which the security group has to be created" -} - diff --git a/modules/create_vpc/outputs.tf b/modules/create_vpc/outputs.tf deleted file mode 100644 index c436333..0000000 --- a/modules/create_vpc/outputs.tf +++ /dev/null @@ -1,18 +0,0 @@ -output "vpc_id" { - value = aws_vpc.vpc.id -} - -output "subnet_ids" { - value = aws_subnet.subnet.id -} - -output "igw_id" { - value = aws_internet_gateway.igw.id -} - -output "public_crt_id" { - value = aws_route_table.public_crt.id -} - - - diff --git a/modules/create_vpc/vars.tf b/modules/create_vpc/vars.tf deleted file mode 100644 index b3a2736..0000000 --- a/modules/create_vpc/vars.tf +++ /dev/null @@ -1,36 +0,0 @@ -variable "vpc_cidr" { - description = "The address space that is used by the VPC" - type = string -} - -variable "vpc_name" { - description = "The name of the VPC to create" - type = string -} - -variable "subnet_name" { - description = "The name of the Subnet to create" - type = string -} - -variable "subnet_cidr" { - description = "The CIDR block for the subnet" - type = string -} - -variable "subnet_zone" { - description = "The AZ's in which to deploy the subnet" - type = string -} - -variable "igw_name" { - description = "The name of the IGW to create" - type = string -} - -variable "public_crt_name" { - description = "The name of the Public Route Table to create" - type = string -} - - diff --git a/modules/create_vpc/vpc.tf b/modules/create_vpc/vpc.tf deleted file mode 100644 index 78b7f66..0000000 --- a/modules/create_vpc/vpc.tf +++ /dev/null @@ -1,44 +0,0 @@ -resource "aws_vpc" "vpc" { - cidr_block = var.vpc_cidr - enable_dns_hostnames = true - enable_dns_support = true - tags = { - Name = var.vpc_name - } -} - -resource "aws_subnet" "subnet" { - vpc_id = aws_vpc.vpc.id - cidr_block = var.subnet_cidr - map_public_ip_on_launch = true - availability_zone = var.subnet_zone - tags = { - Name = var.subnet_name - } -} - -resource "aws_internet_gateway" "igw" { - vpc_id = aws_vpc.vpc.id - tags = { - "Name" = var.igw_name - } -} - -resource "aws_route_table" "public_crt" { - vpc_id = aws_vpc.vpc.id - route { - cidr_block = "0.0.0.0/0" - gateway_id = aws_internet_gateway.igw.id - } - tags = { - Name = var.public_crt_name - } -} - -resource "aws_route_table_association" "rt_association" { - subnet_id = aws_subnet.subnet.id - route_table_id = aws_route_table.public_crt.id -} - - -