-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathec2.tf
39 lines (38 loc) · 1.17 KB
/
ec2.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
data "aws_ami" "linux_ami" {
filter {
name = "name"
values = ["amzn2-ami-amd-hvm-2.0.20230727.0-x86_64-gp2"]
#values = ["Windows_Server-2019-English-Full-Base-2023*"] // for linux "amzn2-ami-amd-hvm-2.0.20230727.0-x86_64-gp2"
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
most_recent = true
owners = ["amazon"]
}
resource "aws_instance" "app-server" {
instance_type = "t3.medium"
ami = data.aws_ami.linux_ami.id
vpc_security_group_ids = [aws_security_group.instance-sg.id]
subnet_id = aws_subnet.public.id
associate_public_ip_address = true
iam_instance_profile = aws_iam_instance_profile.ec2_profile.name
metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
http_put_response_hop_limit = 1
instance_metadata_tags = "enabled"
}
user_data = templatefile("user_data/user_data.tpl",
{
Parameter_Name = aws_ssm_parameter.cloudwatch_linux_config.name
})
tags = {
Name = "${var.name}-server-1"
}
depends_on = [
aws_kms_key_policy.encrypt_app,
aws_kms_alias.key
]
}