NEW: ec2 module

This commit is contained in:
xpk 2022-09-05 18:32:37 +08:00
parent 4181b5488f
commit 1ed9590757
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
3 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,31 @@
resource "aws_instance" "ec2-instance" {
ami = var.ami-id
instance_type = var.instance-type
associate_public_ip_address = var.asso-public-ip
// availability_zone = var.az
iam_instance_profile = var.instance-profile
key_name = var.key-name
root_block_device {
encrypted = var.ebs-encrypted
volume_size = var.root-volume-size
volume_type = var.root-volume-type
}
ebs_optimized = true
subnet_id = var.subnet-id
vpc_security_group_ids = var.security-groups
tags = merge(var.additional_tags, var.default-tags,
{ Name = var.instance-name }
)
volume_tags = merge(var.additional_tags, var.default-tags,
{ Name = var.instance-name }
)
}
resource "aws_eip" "ec2-eip" {
count = var.asso-eip ? 1 : 0
instance = aws_instance.ec2-instance.id
vpc = true
tags = merge(var.default-tags,
{ Name = var.instance-name }
)
}

View File

@ -0,0 +1,6 @@
output ec2-id-ip {
value = {
instance-id = aws_instance.ec2-instance.id
private-ip = aws_instance.ec2-instance.private_ip
}
}

View File

@ -0,0 +1,25 @@
variable instance-type {}
variable ami-id {}
variable asso-public-ip {}
// variable az {}
variable instance-profile {
type = string
default = ""
}
variable key-name {}
variable ebs-encrypted {}
variable root-volume-size {}
variable root-volume-type {
type = string
default = "gp3"
}
variable subnet-id {}
variable security-groups {
type = list
}
variable instance-name {}
variable additional_tags {}
variable asso-eip {
type = bool
}
variable default-tags {}