erc 모듈화, vpc public dns 설정 등

This commit is contained in:
2022-12-26 14:34:38 +09:00
parent a0d22896a0
commit 535d721a50
14 changed files with 123 additions and 115 deletions

35
modules/ecr/main.tf Normal file
View File

@ -0,0 +1,35 @@
//ecr make
resource "aws_ecr_repository" "ecr" {
for_each = toset(var.names_list)
name = each.value
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}
# resource "aws_ecr_repository" "bar" {
# name = "demo-frontend"
# image_tag_mutability = "MUTABLE"
# image_scanning_configuration {
# scan_on_push = true
# }
# }
# resource "null_resource" "null_for_ecr_get_login_password" {
# provisioner "local-exec" {
# command = <<EOF
# aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${aws_ecr_repository.foo.repository_url}
# EOF
# }
# }
# output "ecr_registry_id" {
# value = aws_ecr_repository.foo.registry_id
# }
# output "ecr_repository_url" {
# value = aws_ecr_repository.foo.repository_url
# }
# --region ${AWS_REGION}

9
modules/ecr/valiables.tf Normal file
View File

@ -0,0 +1,9 @@
variable "names_list" {
description = "name list"
type = list(string)
}
# default = [
# "web",
# "nginx",
# "mariadb",
# ]

7
modules/igw/main.tf Normal file
View File

@ -0,0 +1,7 @@
resource "aws_internet_gateway" "gw" {
vpc_id = var.vpc_id
tags = {
Name = "main-igw"
}
}

4
modules/igw/valiables.tf Normal file
View File

@ -0,0 +1,4 @@
variable "vpc_id" {
description = "set vpc id"
type = string
}

View File

@ -0,0 +1,15 @@
resource "aws_subnet" "subnets" {
vpc_id = var.vpc_id
# module.vpc_hq.vpc_hq_id
for_each = var.subnet-az-list
availability_zone = each.value.name
cidr_block = each.value.cidr
map_public_ip_on_launch = true
tags = {
Name = "${var.vpc_id}-${each.value.name}"
# Name = module.vpc_hq.vpcHq.id
}
}

View File

View File

@ -0,0 +1,29 @@
variable "vpc_id" {
description = "set vpc id"
type = string
}
// reference | https://github.com/davidcsi/terraform/blob/master/healthchecks/main.tf
variable "subnet-az-list" {
description = "Subnet available zone & cidr"
type = map(map(string))
# default = {
# "zone-a" = {
# name = "ap-northeast-2a"
# cidr = "10.3.1.0/24"
# }
# "zone-b" = {
# name = "ap-northeast-2b"
# cidr = "10.3.2.0/24"
# }
# "zone-c" = {
# name = "ap-northeast-2c"
# cidr = "10.3.3.0/24"
# }
# "zone-d" = {
# name = "ap-northeast-2d"
# cidr = "10.3.4.0/24"
# }
# }
}

View File

@ -1,8 +1,13 @@
resource "aws_vpc" "vpcHq" {
resource "aws_vpc" "vpc-hq" {
# cidr_block = "10.3.0.0/16"
cidr_block = var.cidr_block
// instance_tenancy = "default"
# 인스턴스에 public DNS가 표시되도록 하는 속성
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = "test"
}

View File

@ -1,5 +1,5 @@
//modules-vpc-output
output "vpc_hq_id" {
description = "The name of vpc hq id"
value = aws_vpc.vpcHq.id
value = aws_vpc.vpc-hq.id
}

View File

@ -3,27 +3,3 @@ variable "cidr_block" {
type = string
}
// reference | https://github.com/davidcsi/terraform/blob/master/healthchecks/main.tf
variable "subnet-az-list" {
description = "Subnet available zone & cidr"
type = map(map(string))
default = {
"zone-a" = {
name = "ap-northeast-2a"
cidr = "10.3.1.0/24"
}
"zone-b" = {
name = "ap-northeast-2b"
cidr = "10.3.2.0/24"
}
"zone-c" = {
name = "ap-northeast-2c"
cidr = "10.3.3.0/24"
}
"zone-d" = {
name = "ap-northeast-2d"
cidr = "10.3.4.0/24"
}
}
}