sg, eks, iam 모듈추가

This commit is contained in:
2022-12-28 22:15:11 +09:00
parent 878bae5c65
commit 0b1946ecb3
25 changed files with 342 additions and 41 deletions

16
modules/eks/main.tf Normal file
View File

@ -0,0 +1,16 @@
resource "aws_eks_cluster" "demo" {
name = var.cluster-name
role_arn = aws_iam_role.demo-cluster.arn
enabled_cluster_log_types = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
vpc_config {
security_group_ids = [aws_security_group.demo-cluster.id]
subnet_ids = [
aws_subnet.VPC_HQ_public_1a.id,
aws_subnet.VPC_HQ_public_1c.id
]
endpoint_private_access = true
endpoint_public_access = true
}
}

0
modules/eks/outputs.tf Normal file
View File

0
modules/eks/valiables.tf Normal file
View File

View File

@ -0,0 +1,5 @@
resource "aws_iam_policy_attachment" "test-attach" {
name = "${var.iam_name}-att"
roles = ["${var.role_name}"]
policy_arn = "${var.arn}"
}

View File

View File

@ -0,0 +1,14 @@
variable "iam_name" {
description = "value"
type = string
}
variable "role_name" {
description = "value"
type = string
}
variable "arn" {
description = "value"
type = string
}

View File

@ -0,0 +1,14 @@
{
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : {
"Service" : [
"eks.amazonaws.com"
]
},
"Action" : "sts:AssumeRole"
}
]
}

23
modules/iam/main.tf Normal file
View File

@ -0,0 +1,23 @@
resource "aws_iam_role" "iam-role" {
name = var.iam_name
assume_role_policy = var.policy
tags = {
tag-key = var.tag_name
}
}
# {
# "Version" : "2012-10-17",
# "Statement" : [
# {
# "Effect" : "Allow",
# "Principal" : {
# "Service" : [
# "eks.amazonaws.com"
# ]
# },
# "Action" : "sts:AssumeRole"
# }
# ]
# }

4
modules/iam/outputs.tf Normal file
View File

@ -0,0 +1,4 @@
output "iam_name" {
value = aws_iam_role.iam-role.name
}

14
modules/iam/variables.tf Normal file
View File

@ -0,0 +1,14 @@
variable "iam_name" {
description = "value"
type = string
}
variable "policy" {
description = "value"
type = string
}
variable "tag_name" {
description = "value"
type = string
}

View File

@ -1,9 +1,8 @@
variable "vpc_id" {
description = "set vpc id"
type = string
}
variable "tag_name" {
description = "value"
type = string
}
variable "vpc_id" {
description = "set vpc id"
type = string
}

View File

@ -0,0 +1,11 @@
resource "aws_security_group_rule" "sg-rule-add" {
description = "Security groups rule add"
type = var.type
from_port = var.set_ports.http
to_port = var.set_ports.http
protocol = var.set_ports.protocol_tcp #tcp
cidr_blocks = var.cidr_blocks
security_group_id = var.sg_id
}

View File

@ -0,0 +1,10 @@
//sg-output
output "vpc_hq_id" {
description = "The name of vpc hq id"
value = aws_vpc.vpc-hq.id
}
output "vpc_name" {
value = var.tag_name
}

View File

@ -0,0 +1,8 @@
variable "type" {
description = "security rule type"
type = string
}
variable "from_port" {
description = "from port"
type = number
}

5
modules/sg/main.tf Normal file
View File

@ -0,0 +1,5 @@
resource "aws_security_group" "sg" {
description = "Security groups"
name = var.sg_name
}

5
modules/sg/outputs.tf Normal file
View File

@ -0,0 +1,5 @@
//sg-output
output "sg_id" {
description = "sg id outputs"
value = aws_security_group.sg.id
}

4
modules/sg/variables.tf Normal file
View File

@ -0,0 +1,4 @@
variable "sg_name" {
description = "security group name"
type = string
}

View File

@ -0,0 +1,24 @@
resource "aws_iam_role" "eks-cluster" {
name = "iam role eks-cluster"
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
assume_role_policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : {
"Service" : [
"eks.amazonaws.com"
]
},
"Action" : "sts:AssumeRole"
}
]
})
tags = {
tag-key = "eks-cluster-rule"
}
}

View File

@ -0,0 +1,10 @@
terraform {
backend "remote"{
hostname = "app.terraform.io"
organization = "22shop"
workspaces {
name = "tf-cloud-backend"
}
}
}