-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiam.tf
More file actions
57 lines (48 loc) · 1.45 KB
/
iam.tf
File metadata and controls
57 lines (48 loc) · 1.45 KB
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
57
resource "aws_iam_role" "ssm_instance_role" {
name = "${var.project_name}-SSMInstanceRole"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
},
]
})
tags = {
Name = "${var.project_name}-SSMInstanceRole"
}
}
resource "aws_iam_role_policy_attachment" "ssm_instance_role_policy_attachment" {
role = aws_iam_role.ssm_instance_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}
# Additional policy for CloudWatch Logs (useful for debugging)
resource "aws_iam_role_policy_attachment" "ssm_instance_cloudwatch_policy" {
role = aws_iam_role.ssm_instance_role.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
}
resource "aws_iam_instance_profile" "ssm_instance_profile" {
name = "${var.project_name}-SSMInstanceProfile"
role = aws_iam_role.ssm_instance_role.name
tags = {
Name = "${var.project_name}-SSMInstanceProfile"
}
}
# GitHub Actions OIDC Provider (shared across environments)
resource "aws_iam_openid_connect_provider" "github" {
url = "https://token.actions.githubusercontent.com"
client_id_list = [
"sts.amazonaws.com"
]
thumbprint_list = [
# Official GitHub OIDC thumbprint
"6938fd4d98bab03faadb97b34396831e3780aea1"
]
tags = {
Name = "GitHub Actions OIDC Provider"
}
}