Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tinhtq committed Nov 18, 2024
2 parents 9cb2d1d + 614c0ad commit 845ea21
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ node_modules
wordpress.xml
*.tfvars
test.txt
python.zip
python.zip
backend.tf
.DS_Store
1 change: 0 additions & 1 deletion ec2/ec2-with-docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ data "aws_vpc" "default" {
default = true
}
resource "aws_security_group" "instance" {
name = "security-group-ec2-docker"
ingress {
from_port = 0
to_port = 0
Expand Down
2 changes: 1 addition & 1 deletion ec2/ec2-with-docker/provider.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
provider "aws" {
region = "us-east-1"
region = "ap-south-2"
}
8 changes: 2 additions & 6 deletions ec2/sample/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ resource "aws_key_pair" "example" {
public_key = file(var.ssh_file)
}


data "aws_vpc" "default" {
default = true
id = var.vpc_id
}
resource "aws_security_group" "instance" {
name = "security-group-test"
Expand All @@ -15,15 +14,13 @@ resource "aws_security_group" "instance" {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 6443
to_port = 6443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}


ingress {
from_port = 22
to_port = 22
Expand All @@ -47,7 +44,6 @@ resource "aws_security_group" "instance" {
vpc_id = data.aws_vpc.default.id
}


module "ec2" {
for_each = merge([for obj in var.instances : { for i in range(obj.quantity) : "${obj.ami_filter}-${i + 1}" => obj }]...)
source = "./modules"
Expand All @@ -57,9 +53,9 @@ module "ec2" {
instance_type = var.instance_type
vpc_security_group_ids = [aws_security_group.instance.id]
ebs = 30
subnet_id = var.subnet_id
}


output "instance_ip_public" {
value = module.ec2
}
1 change: 1 addition & 0 deletions ec2/sample/modules/ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ resource "aws_instance" "example" {
volume_size = var.ebs
volume_type = "gp2"
}
subnet_id = var.subnet_id
}

data "aws_ami" "amazon" {
Expand Down
3 changes: 3 additions & 0 deletions ec2/sample/modules/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ variable "ami_filter" {
variable "ebs" {

}
variable "subnet_id" {

}
7 changes: 7 additions & 0 deletions ec2/sample/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ variable "instance_type" {
# variable "ami_owner" {
# default = "amazon"
# }

variable "vpc_id" {

}
variable "subnet_id" {

}
File renamed without changes.
22 changes: 22 additions & 0 deletions eks/terraform/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"

principals {
type = "Service"
identifiers = ["eks.amazonaws.com"]
}

actions = ["sts:AssumeRole"]
}
}

resource "aws_iam_role" "eks" {
name_prefix = "eks-role"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}

resource "aws_iam_role_policy_attachment" "example-AmazonEKSClusterPolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
role = aws_iam_role.eks.name
}
19 changes: 2 additions & 17 deletions eks/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@


resource "aws_eks_cluster" "cluster" {
name = "eks_cluster"
role_arn = aws_iam_role.eks_cluster.arn
name = "eks-cluster"
role_arn = aws_iam_role.eks.arn
version = "1.31"
vpc_config {
subnet_ids = [data.aws_subnet.zone_a.id, data.aws_subnet.zone_b.id]
}
}


resource "aws_autoscaling_policy" "bat" {
name = "eks_dynamic_scaling"
policy_type = "TargetTrackingScaling"
target_tracking_configuration {
predefined_metric_specification {
predefined_metric_type = "ASGAverageCPUUtilization"

}
target_value = 60
}
autoscaling_group_name = module.eks_self_managed_node_group.name
}

0 comments on commit 845ea21

Please sign in to comment.