forked from jmhale/terraform-aws-wireguard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wireguard-iam.tf
49 lines (42 loc) · 1.43 KB
/
wireguard-iam.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
data "aws_iam_policy_document" "ec2_assume_role" {
statement {
actions = [
"sts:AssumeRole",
]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "wireguard_policy_doc" {
statement {
actions = [
"ec2:AssociateAddress",
]
resources = ["*"]
}
}
resource "aws_iam_policy" "wireguard_policy" {
name = "tf-wireguard-${var.env}"
description = "Terraform Managed. Allows Wireguard instance to attach EIP."
policy = data.aws_iam_policy_document.wireguard_policy_doc.json
count = (var.use_eip ? 1 : 0) # only used for EIP mode
}
resource "aws_iam_role" "wireguard_role" {
name = "tf-wireguard-${var.env}"
description = "Terraform Managed. Role to allow Wireguard instance to attach EIP."
path = "/"
assume_role_policy = data.aws_iam_policy_document.ec2_assume_role.json
count = (var.use_eip ? 1 : 0) # only used for EIP mode
}
resource "aws_iam_role_policy_attachment" "wireguard_roleattach" {
role = aws_iam_role.wireguard_role[0].name
policy_arn = aws_iam_policy.wireguard_policy[0].arn
count = (var.use_eip ? 1 : 0) # only used for EIP mode
}
resource "aws_iam_instance_profile" "wireguard_profile" {
name = "tf-wireguard-${var.env}"
role = aws_iam_role.wireguard_role[0].name
count = (var.use_eip ? 1 : 0) # only used for EIP mode
}