-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute.tf
53 lines (41 loc) · 1.2 KB
/
compute.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"]
}
resource "aws_key_pair" "key-pair-1" {
key_name = "key-pair-1"
public_key = file(var.PUBLIC_KEY_PATH)
tags = {
Name = "${var.PROJECT_NAME}_key-pair"
Terraform = "true"
Environment = "dev"
}
}
resource "aws_instance" "instance1" {
depends_on = [aws_efs_mount_target.efs-mt-1]
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.ec2-sg.id]
associate_public_ip_address = true
subnet_id = aws_subnet.cidr1.id
key_name = aws_key_pair.key-pair-1.id
user_data = base64encode(templatefile("user-data-instance1.tpl",
{ aws_efs_id = aws_efs_file_system.efs1.id }))
connection {
user = var.EC2_USER
private_key = file[var.PRIVATE_KEY_PATH]
}
tags = {
Name = "${var.PROJECT_NAME}_instance1"
Terraform = "true"
Environment = "dev"
}
}