route53 add

This commit is contained in:
2023-01-11 20:21:43 +09:00
parent c96cac92b9
commit e9c35f55b5
11 changed files with 143 additions and 227 deletions

10
prod-hq-dns/.terraform.lock.hcl generated Normal file
View File

@ -0,0 +1,10 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "4.49.0"
constraints = "~> 4.0"
hashes = [
"h1:HxPUxrHpAJey832OwVk3J2T7lHpRzMavqjXDzaFyM6I=",
]
}

View File

@ -1,15 +1,16 @@
// prod - main
// prod - dev
provider "aws" {
region = "ap-northeast-2"
#2.x버전의 AWS공급자 허용
version = "~> 3.0"
region = "ap-northeast-2"
profile = "22shop"
shared_credentials_file = "C:/Users/aa/.aws/credentials"
#4.x버전의 AWS공급자 허용
version = "~> 4.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
vpc_id = data.terraform_remote_state.hq_vpc_id.outputs.vpc_id
common_tags = {
project = "22shop"
owner = "icurfer"
@ -42,192 +43,35 @@ locals {
// 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"]
}
}
locals {
dns_name = "ddochi.ml"
}
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 = "icurfer"
organization = "22shop"
workspaces = {
name = "tf-22shop-network"
name = "hq-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
module "rote53" {
source = "../modules/route53"
name = local.dns_name
}
// 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"
resource "aws_route53_record" "www" {
zone_id = module.rote53.zone_id
name = "hq.ddochi.ml"
type = "A"
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,
]
}
module "ng_sg_ingress_http" {
# for_each = local.tcp_port
source = "../modules/sg-rule-add"
type = "ingress"
from_port = "2049"
to_port = "2049"
protocol = local.tcp_protocol
cidr_blocks = local.all_ips
security_group_id = module.eks_node_group.ng_sg
tag_name = "ng_sg_sub"
depends_on = [
module.eks_node_group
]
}
alias {
name = "k8s-22shopekscluster-42f56c4a0b-158144463.ap-northeast-2.elb.amazonaws.com"
zone_id = "ZWKZPGTI48KDX"
evaluate_target_health = true
}
}

View File

@ -1,13 +1,8 @@
//main-outputs
output "aws_id" {
description = "The AWS Account ID."
value = data.aws_caller_identity.this.account_id
}
output "ng_sg" {
description = "Identifier of the remote access EC2 Security Group."
value = module.eks_node_group.ng_sg
}
# 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

View File

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