@@ -43,15 +43,17 @@ resource "aws_security_group_rule" "db" {
4343 source_security_group_id = aws_security_group. this . id
4444}
4545
46+ data "aws_iam_role" "this" {
47+ name = " bcda-${ local . env } -cclf-import-function"
48+ }
4649# ---------------------------------------------------------------------------
4750# Managed policies
4851# ---------------------------------------------------------------------------
49-
5052data "aws_iam_policy_document" "assume_bucket_role" {
5153 statement {
5254 sid = " AssumeBucketRole"
5355 actions = [" sts:AssumeRole" ]
54- resources = [module . platform . ssm . eft-nextgen . iam_bucket_role_arn . value ]
56+ resources = [data . aws_iam_role . this . arn ]
5557 }
5658}
5759
@@ -157,14 +159,8 @@ resource "aws_iam_role" "this" {
157159}
158160
159161resource "aws_iam_role_policy_attachment" "this" {
160- # TODO: Complexity below is for eventual targeting of `test` and `prod` environments
161- for_each = { for k , v in {
162- assume_bucket_role = try (aws_iam_policy. assume_bucket_role . arn , " " )
163- default_function = try (aws_iam_policy. default_function . arn , " " )
164- } : k => v if length (v) > 0 }
165-
166162 role = aws_iam_role. this . name
167- policy_arn = each . value
163+ policy_arn = aws_iam_policy . default_function . arn
168164}
169165
170166module "bucket" {
@@ -176,62 +172,8 @@ module "bucket" {
176172 ssm_parameter = " /${ local . app } /${ local . env } /${ local . service } /nonsensitive/bucket_name"
177173}
178174
179- resource "aws_lambda_function" "this" {
180- s3_key = " function-3540b70393e3dc30f375eee2e8635a65c6f21036.zip" # fixme create zip
181- s3_bucket = module. bucket . id
182- package_type = " Zip"
183- handler = " bootstrap"
184-
185- function_name = local. name_prefix
186- description = " Ingests the most recent eft file from BFD"
187- kms_key_arn = local. kms_key_arn_primary
188- memory_size = 128
189- reserved_concurrent_executions = 1
190- role = aws_iam_role. this . arn
191- runtime = " provided.al2023"
192- skip_destroy = false
193- timeout = 900
194- architectures = [
195- " x86_64" ,
196- ]
197-
198- tags = {
199- code = " https://github.com/CMSgov/bcda-app/tree/main/bcda/lambda/cclf"
200- }
201-
202- lifecycle {
203- ignore_changes = [
204- s3_object_version ,
205- s3_key ,
206- ]
207- }
208-
209- environment {
210- variables = {
211- APP_NAME = local.name_prefix
212- DB_HOST = " postgres://${ data . aws_rds_cluster . this . endpoint } :${ data . aws_rds_cluster . this . port } /bcda"
213- ENV = local.env
214- }
215- }
216-
217- ephemeral_storage {
218- size = 512
219- }
220-
221- logging_config {
222- log_format = " Text"
223- log_group = " /aws/lambda/bcda-${ local . env } -${ local . service } "
224- }
225-
226- tracing_config {
227- mode = " Active"
228- }
229-
230- vpc_config {
231- ipv6_allowed_for_dual_stack = false
232- security_group_ids = [aws_security_group . this . id ]
233- subnet_ids = local. private_subnets
234- }
175+ data "aws_lambda_function" "this" {
176+ function_name = " bcda-${ local . env } -cclf-import"
235177}
236178
237179resource "aws_security_group" "this" {
@@ -258,7 +200,7 @@ resource "aws_security_group" "this" {
258200}
259201
260202data "aws_sqs_queue" "this" {
261- name = " ${ local . name_prefix } -cclf-import"
203+ name = " ${ local . app } - ${ local . env } -cclf-import"
262204}
263205
264206resource "aws_sns_topic" "eft_nextgen_topic" {
@@ -274,8 +216,8 @@ resource "aws_sns_topic_subscription" "this" {
274216}
275217
276218resource "aws_lambda_event_source_mapping" "this" {
277- event_source_arn = aws_sqs_queue. this . arn
278- function_name = aws_lambda_function. this . function_name
219+ event_source_arn = data . aws_sqs_queue . this . arn
220+ function_name = data . aws_lambda_function . this . function_name
279221 batch_size = 1
280222 enabled = true
281223}
0 commit comments