-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws-ec2.tf
56 lines (48 loc) · 1.78 KB
/
aws-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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
data "aws_ami" "this" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["al2023-ami-2023*"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
}
resource "aws_instance" "app_a_instance" {
ami = data.aws_ami.this.id
instance_type = "t3.micro"
vpc_security_group_ids = [data.aws_security_group.default.id]
subnet_id = aws_subnet.public_subnets[0].id
associate_public_ip_address = true
iam_instance_profile = aws_iam_instance_profile.app_a_instance_profile.name
tags = {
Name = "${var.app_a_prefix}-instance"
}
user_data = templatefile("${path.module}/script/userdata.tftpl", {
vault_addr = var.vault_addr,
vault_namespace = var.vault_namespace
secret_path = "${vault_mount.pki.path}/issue/${vault_pki_secret_backend_role.role.name}"
common_name = "demo.${var.common_name}"
role_name = aws_iam_role.app_a_role.name
})
}
resource "aws_instance" "app_b_instance" {
ami = data.aws_ami.this.id
instance_type = "t3.micro"
vpc_security_group_ids = [data.aws_security_group.default.id]
subnet_id = aws_subnet.public_subnets[0].id
associate_public_ip_address = true
iam_instance_profile = aws_iam_instance_profile.app_b_instance_profile.name
tags = {
Name = "${var.app_b_prefix}-instance"
}
user_data = templatefile("${path.module}/script/userdata.tftpl", {
vault_addr = var.vault_addr,
vault_namespace = var.vault_namespace,
secret_path = "${vault_mount.pki.path}/issue/${vault_pki_secret_backend_role.role.name}"
common_name = "demo.${var.common_name}"
role_name = aws_iam_role.app_a_role.name
})
}