NEW: ec2 module
This commit is contained in:
parent
4181b5488f
commit
1ed9590757
31
modules/compute/ec2/main.tf
Normal file
31
modules/compute/ec2/main.tf
Normal 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 }
|
||||
)
|
||||
}
|
6
modules/compute/ec2/outputs.tf
Normal file
6
modules/compute/ec2/outputs.tf
Normal 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
|
||||
}
|
||||
}
|
25
modules/compute/ec2/variable.tf
Normal file
25
modules/compute/ec2/variable.tf
Normal 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 {}
|
Loading…
Reference in New Issue
Block a user