Skip to content

Commit a11023c

Browse files
committed
add active tracing option
1 parent 515f11f commit a11023c

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed

main.tf

+20
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ resource "aws_iam_role_policy_attachment" "default" {
6565
policy_arn = join("", aws_iam_policy.default.*.arn)
6666
}
6767

68+
data "aws_iam_policy" "tracing" {
69+
count = var.enabled && var.attach_tracing_policy ? 1 : 0
70+
arn = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
71+
}
72+
73+
resource "aws_iam_policy" "tracing" {
74+
count = var.enabled && var.attach_tracing_policy ? 1 : 0
75+
76+
path = "/"
77+
policy = data.aws_iam_policy.tracing[0].policy
78+
tags = var.tags
79+
}
80+
81+
resource "aws_iam_role_policy_attachment" "tracing" {
82+
count = var.enabled && var.attach_tracing_policy ? 1 : 0
83+
84+
role = join("", aws_iam_role.default.*.name)
85+
policy_arn = aws_iam_policy.tracing[0].arn
86+
}
87+
6888
# Module : Lambda layers
6989
# Description : Terraform module to create Lambda layers resource on AWS.
7090
resource "aws_lambda_layer_version" "default" {

variables.tf

+34-22
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ variable "environment" {
1919
}
2020

2121
variable "label_order" {
22-
type = list
22+
type = list(any)
2323
default = []
2424
description = "Label order, e.g. `name`,`application`."
2525
}
2626

2727
variable "attributes" {
28-
type = list
28+
type = list(any)
2929
default = []
3030
description = "Additional attributes (e.g. `1`)."
3131
}
@@ -37,7 +37,7 @@ variable "delimiter" {
3737
}
3838

3939
variable "tags" {
40-
type = map
40+
type = map(any)
4141
default = {}
4242
description = "Additional tags (e.g. map(`BusinessUnit`,`XYZ`)."
4343
}
@@ -128,115 +128,127 @@ variable "kms_key_arn" {
128128
}
129129

130130
variable "layer_filenames" {
131-
type = list
131+
type = list(any)
132132
default = []
133133
description = "The path to the function's deployment package within the local filesystem. If defined, The s3_-prefixed options cannot be used."
134134
}
135135

136136
variable "s3_buckets" {
137-
type = list
137+
type = list(any)
138138
default = []
139139
description = "The S3 bucket location containing the function's deployment package. Conflicts with filename. This bucket must reside in the same AWS region where you are creating the Lambda function."
140140
}
141141

142142
variable "s3_keies" {
143-
type = list
143+
type = list(any)
144144
default = []
145145
description = "The S3 key of an object containing the function's deployment package. Conflicts with filename."
146146
}
147147

148148
variable "s3_object_versions" {
149-
type = list
149+
type = list(any)
150150
default = []
151151
description = "The object version containing the function's deployment package. Conflicts with filename."
152152
}
153153

154154
variable "names" {
155-
type = list
155+
type = list(any)
156156
default = []
157157
description = "A unique name for your Lambda Layer."
158158
}
159159

160160
variable "compatible_runtimes" {
161-
type = list
161+
type = list(any)
162162
default = []
163163
description = "A list of Runtimes this layer is compatible with. Up to 5 runtimes can be specified."
164164
}
165165

166166
variable "descriptions" {
167-
type = list
167+
type = list(any)
168168
default = []
169169
description = "Description of what your Lambda Layer does."
170170
}
171171

172172
variable "license_infos" {
173-
type = list
173+
type = list(any)
174174
default = []
175175
description = "License info for your Lambda Layer. See License Info."
176176
}
177177

178178
variable "statement_ids" {
179-
type = list
179+
type = list(any)
180180
default = []
181181
description = "A unique statement identifier. By default generated by Terraform. "
182182
}
183183

184184
variable "event_source_tokens" {
185-
type = list
185+
type = list(any)
186186
default = []
187187
description = "The Event Source Token to validate. Used with Alexa Skills."
188188
}
189189

190190
variable "iam_actions" {
191-
type = list
191+
type = list(any)
192192
default = ["logs:CreateLogStream", "logs:CreateLogGroup", "logs:PutLogEvents"]
193193
description = "The actions for Iam Role Policy."
194194
}
195195

196196
variable "actions" {
197-
type = list
197+
type = list(any)
198198
default = []
199199
description = "The AWS Lambda action you want to allow in this statement. (e.g. lambda:InvokeFunction)."
200200
}
201201

202202
variable "principals" {
203-
type = list
203+
type = list(any)
204204
default = []
205205
description = "The principal who is getting this permission. e.g. s3.amazonaws.com, an AWS account ID, or any valid AWS service principal such as events.amazonaws.com or sns.amazonaws.com."
206206
}
207207

208208
variable "source_arns" {
209-
type = list
209+
type = list(any)
210210
default = []
211211
description = "When granting Amazon S3 or CloudWatch Events permission to invoke your function, you should specify this field with the Amazon Resource Name (ARN) for the S3 Bucket or CloudWatch Events Rule as its value. This ensures that only events generated from the specified bucket or rule can invoke the function."
212212
}
213213

214214
variable "qualifiers" {
215-
type = list
215+
type = list(any)
216216
default = []
217217
description = "Query parameter to specify function version or alias name. The permission will then apply to the specific qualified ARN. e.g. arn:aws:lambda:aws-region:acct-id:function:function-name:2"
218218
}
219219

220220
variable "source_accounts" {
221-
type = list
221+
type = list(any)
222222
default = []
223223
description = "This parameter is used for S3 and SES. The AWS account ID (without a hyphen) of the source owner."
224224
}
225225

226226
variable "subnet_ids" {
227-
type = list
227+
type = list(any)
228228
default = []
229229
description = "Subnet ids for vpc config."
230230
}
231231

232232
variable "security_group_ids" {
233-
type = list
233+
type = list(any)
234234
default = []
235235
description = "Security group ids for vpc config."
236236
}
237237

238238
variable "variables" {
239-
type = map
239+
type = map(any)
240240
default = {}
241241
description = "A map that defines environment variables for the Lambda function."
242+
}
243+
244+
variable "tracing_mode" {
245+
type = string
246+
default = null
247+
description = "Whether to to sample and trace a subset of incoming requests with AWS X-Ray. Valid values are PassThrough and Active."
248+
}
249+
250+
variable "attach_tracing_policy" {
251+
type = bool
252+
default = false
253+
description = "Controls whether X-Ray tracing policy should be added to IAM role for Lambda Function"
242254
}

0 commit comments

Comments
 (0)