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

View File

@ -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
View 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
View 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)
}