|
| 1 | +resource "aws_glue_catalog_database" "athena_glue_catalog_database" { |
| 2 | + count = local.stack_enabled == 1 && local.is_primary_environment ? 1 : 0 |
| 3 | + |
| 4 | + name = "${local.resource_prefix}-glue-db" |
| 5 | +} |
| 6 | + |
| 7 | +resource "aws_athena_workgroup" "athena_workgroup" { |
| 8 | + count = local.stack_enabled == 1 && local.is_primary_environment ? 1 : 0 |
| 9 | + |
| 10 | + name = "${local.resource_prefix}-workgroup" |
| 11 | + configuration { |
| 12 | + result_configuration { |
| 13 | + output_location = "s3://${module.athena_output_bucket[0].s3_bucket_id}/results/" |
| 14 | + encryption_configuration { |
| 15 | + encryption_option = "SSE_KMS" |
| 16 | + kms_key_arn = data.aws_kms_key.athena_kms_key[0].arn |
| 17 | + } |
| 18 | + } |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +# Athena Federated Query (DynamoDB Connector) |
| 23 | +# Use this approach if you require real-time querying of DynamoDB tables via Athena. |
| 24 | + |
| 25 | +resource "aws_serverlessapplicationrepository_cloudformation_stack" "dynamodb_connector" { |
| 26 | + count = local.stack_enabled == 1 && local.is_primary_environment ? 1 : 0 |
| 27 | + |
| 28 | + name = "${local.resource_prefix}-dynamodb-connector" |
| 29 | + application_id = var.athena_dynamodb_connector_app_id |
| 30 | + |
| 31 | + capabilities = [ |
| 32 | + "CAPABILITY_IAM", |
| 33 | + "CAPABILITY_RESOURCE_POLICY", |
| 34 | + ] |
| 35 | + |
| 36 | + parameters = { |
| 37 | + AthenaCatalogName = "${local.resource_prefix}-dynamodb-connector" |
| 38 | + SpillBucket = module.athena_spill_bucket[0].s3_bucket_id |
| 39 | + LambdaRole = aws_iam_role.athena_dynamodb_role[0].arn |
| 40 | + } |
| 41 | + |
| 42 | + depends_on = [ |
| 43 | + module.athena_spill_bucket, |
| 44 | + aws_iam_role.athena_dynamodb_role, |
| 45 | + aws_iam_role_policy.athena_dynamodb_policy |
| 46 | + ] |
| 47 | +} |
| 48 | + |
| 49 | +resource "aws_athena_data_catalog" "athena_data_catalog_dynamodb" { |
| 50 | + count = local.stack_enabled == 1 && local.is_primary_environment ? 1 : 0 |
| 51 | + |
| 52 | + name = "${local.resource_prefix}-dynamodb-connector" |
| 53 | + description = "Athena DynamoDB data catalog" |
| 54 | + type = "LAMBDA" |
| 55 | + |
| 56 | + parameters = { |
| 57 | + "function" = data.aws_lambda_function.dynamodb_lambda_connector[0].arn |
| 58 | + } |
| 59 | + |
| 60 | + depends_on = [ |
| 61 | + aws_serverlessapplicationrepository_cloudformation_stack.dynamodb_connector |
| 62 | + ] |
| 63 | +} |
| 64 | + |
| 65 | +# Athena Federated Query (RDS Connector) |
| 66 | +# Use this approach if you require real-time querying of RDS databases via Athena. |
| 67 | + |
| 68 | +resource "aws_serverlessapplicationrepository_cloudformation_stack" "rds_connector" { |
| 69 | + count = local.stack_enabled == 1 && local.is_primary_environment ? 1 : 0 |
| 70 | + |
| 71 | + name = "${local.resource_prefix}-rds-connector" |
| 72 | + application_id = var.athena_postgres_connector_app_id |
| 73 | + |
| 74 | + capabilities = [ |
| 75 | + "CAPABILITY_IAM", |
| 76 | + "CAPABILITY_AUTO_EXPAND", |
| 77 | + "CAPABILITY_RESOURCE_POLICY", |
| 78 | + ] |
| 79 | + |
| 80 | + parameters = { |
| 81 | + SpillBucket = module.athena_spill_bucket[0].s3_bucket_id |
| 82 | + DefaultConnectionString = "postgres://jdbc:postgresql://${local.rds_secret.host}:${local.rds_secret.port}/${local.rds_secret.dbname}" |
| 83 | + SecretNamePrefix = "/${var.project}/${var.environment}/target-rds" |
| 84 | + LambdaFunctionName = "${local.resource_prefix}-rds-connector" |
| 85 | + SecurityGroupIds = aws_security_group.rds_connector_sg[0].id |
| 86 | + SubnetIds = join(",", data.aws_subnets.private_subnets.ids) |
| 87 | + } |
| 88 | + |
| 89 | + depends_on = [ |
| 90 | + module.athena_spill_bucket |
| 91 | + ] |
| 92 | +} |
| 93 | + |
| 94 | +resource "aws_athena_data_catalog" "athena_data_catalog_rds" { |
| 95 | + count = local.stack_enabled == 1 && local.is_primary_environment ? 1 : 0 |
| 96 | + |
| 97 | + name = "${local.resource_prefix}-rds-connector" |
| 98 | + description = "Athena RDS data catalog" |
| 99 | + type = "LAMBDA" |
| 100 | + |
| 101 | + parameters = { |
| 102 | + "function" = data.aws_lambda_function.rds_lambda_connector[0].arn |
| 103 | + } |
| 104 | + |
| 105 | + depends_on = [ |
| 106 | + aws_serverlessapplicationrepository_cloudformation_stack.rds_connector |
| 107 | + ] |
| 108 | +} |
0 commit comments