테라폼 환경 수정
This commit is contained in:
25
prod-hq-eks/.terraform.lock.hcl
generated
Normal file
25
prod-hq-eks/.terraform.lock.hcl
generated
Normal file
@ -0,0 +1,25 @@
|
||||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/hashicorp/aws" {
|
||||
version = "3.76.0"
|
||||
constraints = "~> 3.0"
|
||||
hashes = [
|
||||
"h1:OzcRXMb2MU7LOheOcCX4rMVffltsLIX3ENs84UzB2Kw=",
|
||||
"zh:144ac5d606a9236564a9e2cfe4fde5f25c56c42d97108b5ef9f4ba68c367c17a",
|
||||
"zh:1e8f594d094bd83e759aeed1f6b9d83d67bace36bcd0d5ddc48316e9c219d9f8",
|
||||
"zh:1eb473010b250c083a7370e0ae43f9961f3c83678a4f5782981387d04f5f7491",
|
||||
"zh:258ff4c1d204876dea485fac0856721cccf15b94361e7d56ea433fc6fbfc7dc6",
|
||||
"zh:3cf323d1ebc797486c8b995b0e8d1093ec75e832308fe9dd52dccb8507af2b00",
|
||||
"zh:5108ba908617ed6e89ac15defafbf9bc57b3ff098d0efdd10294bae1a5532daf",
|
||||
"zh:54bd6fe57680b845bbf3f4f0cc9a20057973defcd7786390f1967bdbf7b58e1f",
|
||||
"zh:5f1d06843997229616dc56cecae450e4165ecadb2b2f8206eb074babc09e8dbc",
|
||||
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
|
||||
"zh:a6a222eb9ac72ad4efd0f039cac3ffda35d0152e47e573da1aa6da272edb9413",
|
||||
"zh:ad96cddae3ab78fa85095b7d82e09ed6b25ef099c58d18c1c14c75d5f5f1219c",
|
||||
"zh:bf18dd6bd6a8eba83f9d55adeeeb14abeb2b63b4a05ac26fc15d1820d34ff9d2",
|
||||
"zh:cace02539792163c90362998fae484f3b32869d0d148484c809d7c9e8086ac50",
|
||||
"zh:d527fe5b1fa912a06134fa6be35a044d05ae69973b5ce5c1804466a167b4d3bc",
|
||||
"zh:fad111579454ec38c3d51ad2422bf43b108f51f17d4db64e81f178b5fbfb2675",
|
||||
]
|
||||
}
|
239
prod-hq-eks/main.tf
Normal file
239
prod-hq-eks/main.tf
Normal file
@ -0,0 +1,239 @@
|
||||
// prod - main
|
||||
provider "aws" {
|
||||
region = "ap-northeast-2"
|
||||
|
||||
#2.x버전의 AWS공급자 허용
|
||||
version = "~> 3.0"
|
||||
|
||||
}
|
||||
|
||||
locals {
|
||||
vpc_id = data.terraform_remote_state.hq_vpc_id.outputs.vpc_id
|
||||
public_subnet = data.terraform_remote_state.hq_vpc_id.outputs.subnet
|
||||
common_tags = {
|
||||
project = "22shop"
|
||||
owner = "icurfer"
|
||||
|
||||
}
|
||||
tcp_port = {
|
||||
any_port = 0
|
||||
http_port = 80
|
||||
https_port = 443
|
||||
ssh_port = 22
|
||||
dns_port = 53
|
||||
django_port = 8000
|
||||
mysql_port = 3306
|
||||
}
|
||||
udp_port = {
|
||||
dns_port = 53
|
||||
}
|
||||
any_protocol = "-1"
|
||||
tcp_protocol = "tcp"
|
||||
icmp_protocol = "icmp"
|
||||
all_ips = ["0.0.0.0/0"]
|
||||
|
||||
node_group_scaling_config = {
|
||||
desired_size = 2
|
||||
max_size = 4
|
||||
min_size = 1
|
||||
}
|
||||
}
|
||||
|
||||
// GET 계정정보
|
||||
data "aws_caller_identity" "this" {}
|
||||
|
||||
// eks를 위한 iam역할 생성 데이터 조회
|
||||
data "aws_iam_policy_document" "eks-assume-role-policy" {
|
||||
statement {
|
||||
actions = ["sts:AssumeRole"]
|
||||
|
||||
principals {
|
||||
type = "Service"
|
||||
identifiers = ["eks.amazonaws.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
data "aws_iam_policy_document" "eks_node_group_role" {
|
||||
statement {
|
||||
actions = ["sts:AssumeRole"]
|
||||
|
||||
principals {
|
||||
type = "Service"
|
||||
identifiers = ["ec2.amazonaws.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 테라폼클라우드
|
||||
data "terraform_remote_state" "hq_vpc_id" {
|
||||
backend = "remote"
|
||||
|
||||
config = {
|
||||
organization = "22shop"
|
||||
|
||||
workspaces = {
|
||||
name = "tf-22shop-network"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// eks 클러스터 역할 생성
|
||||
module "eks_cluster_iam" {
|
||||
source = "../modules/iam"
|
||||
iam_name = "eks-cluster-test"
|
||||
policy = data.aws_iam_policy_document.eks-assume-role-policy.json
|
||||
tag_name = local.common_tags.project
|
||||
}
|
||||
|
||||
// eks 클러스터 역할 정책 추가
|
||||
module "eks_cluster_iam_att" {
|
||||
source = "../modules/iam-policy-attach"
|
||||
iam_name = "eks-cluster-att"
|
||||
role_name = module.eks_cluster_iam.iam_name
|
||||
arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
|
||||
|
||||
depends_on = [
|
||||
module.eks_cluster_iam
|
||||
]
|
||||
}
|
||||
module "eks_cluster_iam_att2" {
|
||||
source = "../modules/iam-policy-attach"
|
||||
iam_name = "eks-cluster-att"
|
||||
role_name = module.eks_cluster_iam.iam_name
|
||||
arn = "arn:aws:iam::aws:policy/AmazonEKSVPCResourceController"
|
||||
|
||||
depends_on = [
|
||||
module.eks_cluster_iam
|
||||
]
|
||||
}
|
||||
|
||||
// eks 노드그룹 역할 생성 및 추가
|
||||
module "eks_nodegroup_iam" {
|
||||
source = "../modules/iam"
|
||||
iam_name = "eks-nodegroup-test"
|
||||
policy = data.aws_iam_policy_document.eks_node_group_role.json
|
||||
tag_name = local.common_tags.project
|
||||
}
|
||||
module "eks_nodegroup_iam_att_1" {
|
||||
source = "../modules/iam-policy-attach"
|
||||
iam_name = "eks-nodegroup-att"
|
||||
role_name = module.eks_nodegroup_iam.iam_name
|
||||
arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
|
||||
|
||||
depends_on = [
|
||||
module.eks_nodegroup_iam
|
||||
]
|
||||
}
|
||||
module "eks_nodegroup_iam_att_2" {
|
||||
source = "../modules/iam-policy-attach"
|
||||
iam_name = "eks-nodegroup-att"
|
||||
role_name = module.eks_nodegroup_iam.iam_name
|
||||
arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
|
||||
|
||||
depends_on = [
|
||||
module.eks_nodegroup_iam
|
||||
]
|
||||
}
|
||||
module "eks_nodegroup_iam_att_3" {
|
||||
source = "../modules/iam-policy-attach"
|
||||
iam_name = "eks-nodegroup-att"
|
||||
role_name = module.eks_nodegroup_iam.iam_name
|
||||
arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
|
||||
|
||||
depends_on = [
|
||||
module.eks_nodegroup_iam
|
||||
]
|
||||
}
|
||||
|
||||
// 보안그룹 생성
|
||||
module "eks_sg" {
|
||||
source = "../modules/sg"
|
||||
sg_name = "${local.common_tags.project}-sg"
|
||||
# vpc_id = module.vpc_hq.vpc_hq_id
|
||||
vpc_id = local.vpc_id
|
||||
|
||||
}
|
||||
|
||||
module "eks_sg_ingress_http" {
|
||||
for_each = local.tcp_port
|
||||
source = "../modules/sg-rule-add"
|
||||
type = "ingress"
|
||||
from_port = each.value
|
||||
to_port = each.value
|
||||
protocol = local.tcp_protocol
|
||||
cidr_blocks = local.all_ips
|
||||
security_group_id = module.eks_sg.sg_id
|
||||
|
||||
tag_name = each.key
|
||||
}
|
||||
|
||||
module "eks_sg_egress_all" {
|
||||
source = "../modules/sg-rule-add"
|
||||
type = "egress"
|
||||
from_port = local.any_protocol
|
||||
to_port = local.any_protocol
|
||||
protocol = local.any_protocol
|
||||
cidr_blocks = local.all_ips
|
||||
security_group_id = module.eks_sg.sg_id
|
||||
|
||||
tag_name = "egress-all"
|
||||
}
|
||||
|
||||
module "eks_cluster" {
|
||||
source = "../modules/eks-cluster"
|
||||
name = local.common_tags.project
|
||||
iam_role_arn = module.eks_cluster_iam.iam_arn
|
||||
sg_list = [module.eks_sg.sg_id]
|
||||
# subnet_list = [module.subnet_public.subnet.zone-a.id, module.subnet_public.subnet.zone-c.id] #변경해야될수있음.
|
||||
subnet_list = [local.public_subnet.zone-a.id, local.public_subnet.zone-c.id]
|
||||
|
||||
depends_on = [
|
||||
module.eks_cluster_iam,
|
||||
module.eks_sg,
|
||||
]
|
||||
|
||||
client_id = data.aws_caller_identity.this.id
|
||||
|
||||
}
|
||||
|
||||
module "eks_node_group" {
|
||||
source = "../modules/eks-node-group"
|
||||
node_group_name = "${local.common_tags.project}-ng"
|
||||
cluster_name = module.eks_cluster.cluster_name
|
||||
# iam_role_arn = module.eks_nodegroup_iam.iam_arn
|
||||
iam_role_arn = "arn:aws:iam::448559955338:role/eks-nodegroup-test"
|
||||
# subnet_list = [module.subnet_public.subnet.zone-a.id, module.subnet_public.subnet.zone-c.id] #변경해야될수있음.
|
||||
subnet_list = [local.public_subnet.zone-a.id, local.public_subnet.zone-c.id]
|
||||
|
||||
desired_size = local.node_group_scaling_config.desired_size
|
||||
max_size = local.node_group_scaling_config.max_size
|
||||
min_size = local.node_group_scaling_config.min_size
|
||||
|
||||
depends_on = [
|
||||
module.eks_nodegroup_iam,
|
||||
module.eks_cluster,
|
||||
]
|
||||
}
|
||||
# EKS테스트 할때 활성
|
||||
# module "ecr" {
|
||||
# source = "../modules/ecr"
|
||||
|
||||
# names_list = ["web", "nginx", "mariadb"]
|
||||
# }
|
||||
|
||||
/*
|
||||
terraform_remote_state reference method
|
||||
terraform cloud
|
||||
*/
|
||||
# data "terraform_remote_state" "foo" {
|
||||
# backend = "remote"
|
||||
|
||||
# config = {
|
||||
# organization = "company"
|
||||
|
||||
# workspaces = {
|
||||
# name = "workspace"
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
13
prod-hq-eks/outputs.tf
Normal file
13
prod-hq-eks/outputs.tf
Normal file
@ -0,0 +1,13 @@
|
||||
//main-outputs
|
||||
output "aws_id" {
|
||||
description = "The AWS Account ID."
|
||||
value = data.aws_caller_identity.this.account_id
|
||||
}
|
||||
# output "cluster_oidc" {
|
||||
# description = "eks_cluster_identity"
|
||||
# value = module.eks_cluster.cluster_oidc
|
||||
# }
|
||||
# output "subnet" {
|
||||
# description = "The name of vpc hq id"
|
||||
# value = module.subnet_public.subnet
|
||||
# }
|
10
prod-hq-eks/terraform.tf
Normal file
10
prod-hq-eks/terraform.tf
Normal file
@ -0,0 +1,10 @@
|
||||
terraform {
|
||||
backend "remote"{
|
||||
hostname = "app.terraform.io"
|
||||
organization = "22shop"
|
||||
|
||||
workspaces {
|
||||
name = "tf-cloud-backend"
|
||||
}
|
||||
}
|
||||
}
|
45
prod-hq-eks/valiables.tf
Normal file
45
prod-hq-eks/valiables.tf
Normal file
@ -0,0 +1,45 @@
|
||||
# variable "cidr_block" {
|
||||
# type = string
|
||||
# default = "10.3.0.0/16"
|
||||
|
||||
# }
|
||||
|
||||
variable "prod_name" {
|
||||
description = "value"
|
||||
type = string
|
||||
default = "22shop"
|
||||
}
|
||||
|
||||
# variable "igw_id" {
|
||||
# description = "value"
|
||||
# type = string
|
||||
# }
|
||||
|
||||
variable "subnet-az-public" {
|
||||
description = "Subnet available zone & cidr"
|
||||
type = map(map(string))
|
||||
default = {
|
||||
"zone-a" = {
|
||||
name = "ap-northeast-2a"
|
||||
cidr = "10.3.1.0/24"
|
||||
}
|
||||
"zone-c" = {
|
||||
name = "ap-northeast-2c"
|
||||
cidr = "10.3.3.0/24"
|
||||
}
|
||||
}
|
||||
}
|
||||
variable "subnet-az-private" {
|
||||
description = "Subnet available zone & cidr"
|
||||
type = map(map(string))
|
||||
default = {
|
||||
"zone-b" = {
|
||||
name = "ap-northeast-2b"
|
||||
cidr = "10.3.2.0/24"
|
||||
}
|
||||
"zone-d" = {
|
||||
name = "ap-northeast-2d"
|
||||
cidr = "10.3.4.0/24"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user