This commit is contained in:
2023-01-11 01:31:56 +09:00
parent f0402956e2
commit c96cac92b9
42 changed files with 746 additions and 265 deletions

24
icurfer-hq-network/.terraform.lock.hcl generated Normal file
View File

@ -0,0 +1,24 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "2.70.4"
constraints = "~> 2.0"
hashes = [
"h1:0ALZ1dGL41uYi6Ooc0mT52FAcYMEvozpFNx8AQKvatY=",
"zh:45f528103c5580623b15e7ac3986b72baa5d33cabc66c902594d666c7607a8f2",
"zh:538793ad294171370cc0c280c98cb5c8eb77669d0917c2ab727090016ec2626e",
"zh:631d5aea6ec7b13d8973f13fc70dc36ecc5e5614793c5141ccd254773bc4ec36",
"zh:7861c5e12c322717ff9684ac658be590d12906a9549204b6337f3f8d55bf0640",
"zh:8adfe014d0a0552a9a6b358cc0d7e3d0c660bc15aa5524e771525b0e5d14b20f",
"zh:9d81089842c0990d410bffc5702dec719145951c3f5cbc85c3bf8968985d50cc",
"zh:a4b0922e0fddccbb84958d4909896e8009c57885a41cc2e1c37dcdc56e2da796",
"zh:a6dcd0292e807d8d5b8a922d2e0cc3c6949461e18603cb48005c967329abe574",
"zh:ae07e0dae4e700c1f6623bd0b66ab4153d0b498ffd5f6681117101d2020815bc",
"zh:bd07ba17501b8b57d4455329770f4f520e709d12f8b0c364821f39d1b2df1a89",
"zh:ddbf1a0b63ac84462da002b44b249f86180804670f1070109785d00a19f88e16",
"zh:e2291e9efbd0100c555d3bae8f2b2af4d416f80105c250747cb5fd8f0b17062f",
"zh:e5d8e0ad489547118fd76f300d1cb6dd516997cf919dc0bbaedaacb5c91e697a",
"zh:eae90e616cec391546bf4ecf294e8a3ae56ce7c90ac0e1d45ebf2907957b9f16",
]
}

142
icurfer-hq-network/main.tf Normal file
View File

@ -0,0 +1,142 @@
// prod - main
provider "aws" {
region = "ap-northeast-2"
#2.x버전의 AWS공급자 허용
version = "~> 2.0"
}
locals {
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
}
eks_ingress_type = {
public = "kubernetes.io/role/elb"
private = "kubernetes.io/role/internal-elb=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"]
}
}
}
# module "vpc_hq" {
module "vpc_hq" {
source = "../modules/vpc"
# source = "github.com/Seong-dong/team_prj/tree/main/modules/vpc"
tag_name = "${local.common_tags.project}-vpc"
cidr_block = "10.3.0.0/16"
}
module "vpc_igw" {
source = "../modules/igw"
vpc_id = module.vpc_hq.vpc_hq_id
tag_name = "${local.common_tags.project}-vpc_igw"
depends_on = [
module.vpc_hq
]
}
module "subnet_public" {
source = "../modules/vpc-subnet"
vpc_id = module.vpc_hq.vpc_hq_id
subnet-az-list = var.subnet-az-public
public_ip_on = true
# vpc_name = "${local.common_tags.project}-public"
#alb-ingress 생성을 위해 지정
k8s_ingress = true
vpc_name = local.eks_ingress_type.public
}
// public route
module "route_public" {
source = "../modules/route-table"
tag_name = "${local.common_tags.project}-route_table"
vpc_id = module.vpc_hq.vpc_hq_id
}
module "route_add" {
source = "../modules/route-add"
route_public_id = module.route_public.route_public_id
igw_id = module.vpc_igw.igw_id
}
module "route_association" {
source = "../modules/route-association"
route_table_id = module.route_public.route_public_id
association_count = 2
subnet_ids = [module.subnet_public.subnet.zone-a.id, module.subnet_public.subnet.zone-c.id]
}
# // private subnet
# module "subnet_private" {
# source = "../modules/vpc-subnet"
# vpc_id = module.vpc_hq.vpc_hq_id
# subnet-az-list = var.subnet-az-private
# public_ip_on = false
# k8s_ingress = false
# #alb-ingress 생성을 위해 지정
# vpc_name = local.eks_ingress_type.public
# }
# module "route_private" {
# source = "../modules/route-table"
# tag_name = "${local.common_tags.project}-private_route_table"
# vpc_id = module.vpc_hq.vpc_hq_id
# }

View File

@ -0,0 +1,16 @@
//main-outputs
output "aws_id" {
description = "The AWS Account ID."
value = data.aws_caller_identity.this.account_id
}
output "subnet" {
description = "The name of vpc hq id"
value = module.subnet_public.subnet
}
output "vpc_id" {
description = "vpc_id"
value = module.vpc_hq.vpc_hq_id
}

View File

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

View 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"
}
}
}