-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdata.tf
More file actions
136 lines (116 loc) · 3.22 KB
/
Copy pathdata.tf
File metadata and controls
136 lines (116 loc) · 3.22 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
# VPC lookup by name (when vpc_name is provided)
data "aws_vpc" "selected" {
count = var.vpc_name != null ? 1 : 0
filter {
name = "tag:Name"
values = [var.vpc_name]
}
}
# Individual subnet lookup by name (when subnet_names are provided)
data "aws_subnet" "selected" {
for_each = toset(var.subnet_names)
filter {
name = "tag:Name"
values = [each.value]
}
filter {
name = "vpc-id"
values = [local.vpc_id]
}
}
# Most recent Amazon Linux 2023 AMI
data "aws_ami" "amazon_linux_2023" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["al2023-ami-2023*"]
}
filter {
name = "architecture"
values = [var.architecture]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
# A trunk-ignore rule is added here because the "owners" argument for this data resource is optional
# (as per the Terraform provider docs) and is intentionally omitted, since the consumer of this
# module can specify an arbitrary AMI ID as input. Therefore, the security of the AMI is a concern
# for the consumer. According to the AWS docs, if this value is not specified, the results include
# all images for which the caller has launch permissions.
#
# AWS docs: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html.
#
# This rule was introduced in the following PR:
# https://github.com/masterpointio/terraform-aws-ssm-agent/pull/43.
#
# trivy:ignore:AVD-AWS-0344
data "aws_ami" "instance" {
count = length(var.ami) > 0 ? 1 : 0
most_recent = true
filter {
name = "image-id"
values = [var.ami]
}
}
# IAM policy document for EC2 instances to assume the SSM Agent role
data "aws_iam_policy_document" "default" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
# https://docs.aws.amazon.com/systems-manager/latest/userguide/getting-started-create-iam-instance-profile.html#create-iam-instance-profile-ssn-logging
data "aws_iam_policy_document" "session_logging" {
count = var.session_logging_enabled ? 1 : 0
statement {
sid = "SSMAgentSessionAllowS3Logging"
effect = "Allow"
actions = [
"s3:PutObject"
]
resources = ["${local.session_logging_bucket_arn}/*"]
}
statement {
sid = "SSMAgentSessionAllowCloudWatchLogging"
effect = "Allow"
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = ["${local.session_logging_log_group_arn}:*"]
}
statement {
sid = "SSMAgentSessionAllowCloudWatchDescribe"
effect = "Allow"
actions = [
"logs:DescribeLogGroups",
"logs:DescribeLogStreams"
]
resources = [local.session_logging_log_group_arn]
}
statement {
sid = "SSMAgentSessionAllowGetEncryptionConfig"
effect = "Allow"
actions = [
"s3:GetEncryptionConfiguration"
]
resources = [local.session_logging_bucket_arn]
}
statement {
sid = "SSMAgentSessionAllowKMSDataKey"
effect = "Allow"
actions = [
"kms:GenerateDataKey"
]
resources = [local.session_logging_kms_key_arn]
}
}