cowork
This commit is contained in:
@ -1,8 +1,30 @@
|
||||
resource "aws_network_interface" "eni" {
|
||||
subnet_id = var.public_ip_associate ? var.public_subnet : var.private_subnet
|
||||
# private_ips = ["172.16.10.100"]
|
||||
security_groups = var.sg_list
|
||||
tags = {
|
||||
Name = "primary_network_interface"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_instance" "ubuntu" {
|
||||
ami = "ami-0ab04b3ccbadfae1f"
|
||||
instance_type = "t2.micro"
|
||||
ami = var.ami_name
|
||||
# "ami-0ab04b3ccbadfae1f"
|
||||
instance_type = var.instance_type
|
||||
# "t2.micro"
|
||||
|
||||
tags = {
|
||||
Name = "tf-ubuntu"
|
||||
Name = "${var.tag_name}"
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
network_interface_id = aws_network_interface.eni.id
|
||||
device_index = 0
|
||||
# delete_on_termination = true
|
||||
|
||||
# security_groups = var.sg_list
|
||||
|
||||
}
|
||||
|
||||
key_name = var.key_name
|
||||
}
|
||||
|
13
modules/ec2/outputs.tf
Normal file
13
modules/ec2/outputs.tf
Normal file
@ -0,0 +1,13 @@
|
||||
output "ec2_id" {
|
||||
value = aws_instance.ubuntu.id
|
||||
|
||||
}
|
||||
|
||||
output "public_ip_associate" {
|
||||
value = aws_instance.ubuntu.associate_public_ip_address
|
||||
|
||||
}
|
||||
|
||||
output "sg_id" {
|
||||
value = aws_network_interface.eni.security_groups
|
||||
}
|
36
modules/ec2/vailables.tf
Normal file
36
modules/ec2/vailables.tf
Normal file
@ -0,0 +1,36 @@
|
||||
variable "ami_name" {
|
||||
description = "ami name"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "instance_type" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "tag_name" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "public_ip_associate" {
|
||||
type = bool
|
||||
}
|
||||
variable "key_name" {
|
||||
type = string
|
||||
}
|
||||
# variable "subnet_id" {
|
||||
# type = string
|
||||
# }
|
||||
|
||||
variable "public_subnet" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "private_subnet" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "sg_list" {
|
||||
description = "sg list"
|
||||
type = list(string)
|
||||
|
||||
}
|
4
modules/eip/main.tf
Normal file
4
modules/eip/main.tf
Normal file
@ -0,0 +1,4 @@
|
||||
resource "aws_eip" "lb" {
|
||||
instance = aws_instance.web.id
|
||||
vpc = true
|
||||
}
|
0
modules/eip/outputs.tf
Normal file
0
modules/eip/outputs.tf
Normal file
0
modules/eip/variables.tf
Normal file
0
modules/eip/variables.tf
Normal file
24
modules/nat-gateway/main.tf
Normal file
24
modules/nat-gateway/main.tf
Normal file
@ -0,0 +1,24 @@
|
||||
resource "aws_eip" "nat-eip" {
|
||||
vpc = true
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_nat_gateway" "example" {
|
||||
allocation_id = aws_eip.nat-eip.id
|
||||
subnet_id = var.subnet_id
|
||||
|
||||
tags = {
|
||||
Name = "gw NAT"
|
||||
}
|
||||
|
||||
# To ensure proper ordering, it is recommended to add an explicit dependency
|
||||
# on the Internet Gateway for the VPC.
|
||||
# depends_on = [aws_internet_gateway.example]
|
||||
}
|
||||
# resource "aws_nat_gateway" "example" {
|
||||
# connectivity_type = "private"
|
||||
# subnet_id = aws_subnet.example.id
|
||||
# }
|
4
modules/nat-gateway/outputs.tf
Normal file
4
modules/nat-gateway/outputs.tf
Normal file
@ -0,0 +1,4 @@
|
||||
output "nat_id" {
|
||||
value = aws_nat_gateway.example.id
|
||||
|
||||
}
|
5
modules/nat-gateway/variables.tf
Normal file
5
modules/nat-gateway/variables.tf
Normal file
@ -0,0 +1,5 @@
|
||||
variable "subnet_id" {
|
||||
description = "subnet id"
|
||||
type = string
|
||||
|
||||
}
|
@ -1,7 +1,16 @@
|
||||
resource "aws_route" "route-add" {
|
||||
route_table_id = var.route_public_id
|
||||
resource "aws_route" "route-igw-add" {
|
||||
count = format("%.1s", var.gw_type) == "i" ? 1 : 0
|
||||
route_table_id = var.route_id
|
||||
destination_cidr_block = "0.0.0.0/0"
|
||||
gateway_id = var.igw_id
|
||||
depends_on = [var.route_public_id]
|
||||
depends_on = [var.route_id]
|
||||
# depends_on = [aws_route_table.testing]
|
||||
}
|
||||
resource "aws_route" "route-nat-add" {
|
||||
count = format("%.1s", var.gw_type) == "i" ? 0 : 1
|
||||
route_table_id = var.route_id
|
||||
destination_cidr_block = "0.0.0.0/0"
|
||||
nat_gateway_id = var.nat_id
|
||||
depends_on = [var.route_id]
|
||||
# depends_on = [aws_route_table.testing]
|
||||
}
|
@ -1,9 +1,19 @@
|
||||
variable "route_public_id" {
|
||||
variable "route_id" {
|
||||
description = "value"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "gw_type" {
|
||||
description = "gateway type. nat or igw"
|
||||
type = string
|
||||
}
|
||||
variable "igw_id" {
|
||||
description = "value"
|
||||
type = string
|
||||
default = "null"
|
||||
}
|
||||
variable "nat_id" {
|
||||
description = "value"
|
||||
type = string
|
||||
default = "null"
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
//public
|
||||
resource "aws_route_table" "public-table" {
|
||||
resource "aws_route_table" "rt-tbl" {
|
||||
vpc_id = var.vpc_id
|
||||
tags = {
|
||||
Name = "${var.tag_name}-route-public"
|
||||
|
@ -1,5 +1,5 @@
|
||||
output "route_public_id" {
|
||||
output "route_id" {
|
||||
description = "get route_public_id"
|
||||
value = aws_route_table.public-table.id
|
||||
value = aws_route_table.rt-tbl.id
|
||||
|
||||
}
|
@ -9,8 +9,8 @@ resource "aws_subnet" "subnets" {
|
||||
map_public_ip_on_launch = var.public_ip_on ? true : false
|
||||
|
||||
tags = {
|
||||
Name = var.vpc_name
|
||||
Name = "${var.public_ip_on ? "22shop-eks-public" : "22shop-eks-private"}"
|
||||
"kubernetes.io/role/elb" = "${var.k8s_ingress ? 1 : 0}"
|
||||
# Name = module.vpc_hq.vpcHq.id
|
||||
"kubernetes.io/role/internal-elb" = "${var.k8s_ingress ? 0 : 1}"
|
||||
}
|
||||
}
|
@ -31,6 +31,7 @@ variable "subnet-az-list" {
|
||||
# }
|
||||
}
|
||||
|
||||
|
||||
variable "public_ip_on" {
|
||||
type = bool
|
||||
}
|
||||
|
Reference in New Issue
Block a user