mirror of
https://github.com/Sea-Haven-Industries/file-share.git
synced 2026-09-30 06:33:17 +00:00
45 lines
1.2 KiB
Terraform
45 lines
1.2 KiB
Terraform
|
|
resource "aws_instance" "this" {
|
||
|
|
count = local.create_instance ? 1 : 0
|
||
|
|
|
||
|
|
ami = var.ami_id
|
||
|
|
instance_type = "t4g.small"
|
||
|
|
subnet_id = aws_subnet.file_share.id
|
||
|
|
vpc_security_group_ids = [aws_security_group.file_share.id]
|
||
|
|
iam_instance_profile = aws_iam_instance_profile.this.name
|
||
|
|
associate_public_ip_address = false
|
||
|
|
user_data = local.user_data
|
||
|
|
user_data_replace_on_change = false
|
||
|
|
|
||
|
|
root_block_device {
|
||
|
|
volume_size = 20
|
||
|
|
volume_type = "gp3"
|
||
|
|
encrypted = true
|
||
|
|
}
|
||
|
|
|
||
|
|
metadata_options {
|
||
|
|
http_endpoint = "enabled"
|
||
|
|
http_tokens = "required"
|
||
|
|
}
|
||
|
|
|
||
|
|
tags = {
|
||
|
|
Name = "file-share"
|
||
|
|
"file-share-backup" = "true"
|
||
|
|
}
|
||
|
|
|
||
|
|
lifecycle {
|
||
|
|
postcondition {
|
||
|
|
condition = self.public_ip == null || self.public_ip == ""
|
||
|
|
error_message = "file-share must not have a public IP."
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
resource "aws_volume_attachment" "data" {
|
||
|
|
count = local.create_instance ? 1 : 0
|
||
|
|
|
||
|
|
device_name = "/dev/xvdf"
|
||
|
|
volume_id = var.data_volume_id
|
||
|
|
instance_id = aws_instance.this[0].id
|
||
|
|
stop_instance_before_detaching = true
|
||
|
|
}
|