Hey!
I am trying to set Kafka event source for Lambda function using the Lambda module.
My code is in the end of the question. I need to pass source_access_configuration
with both the subnet id and the security groups, which I am reading from another stack using DataTerraformRemoteState
.
So I can’t just use map
or loop over the values. I tried using iterator but it produced very weird TF syntax which failed on apply:
"source_access_configuration": [
{
"type": "SASL_SCRAM_512_AUTH",
"uri": "${aws_secretsmanager_secret.secret.arn}"
},
{
"type": "SERVER_ROOT_CA_CERTIFICATE",
"uri": "<>"
},
"${[ for key, val in toset([data.terraform_remote_state.production-remote-state.outputs.vpc-default-security-group-id]): {type = \"VPC_SECURITY_GROUP\", uri = val}]}",
"${[ for key, val in toset(data.terraform_remote_state.production-remote-state.outputs.vpc-private-subnet-ids): {type = \"VPC_SUBNET\", uri = val}]}"
]
How can I do that? I need to combine 2 dynamic lists + static values…
const vpcSecurityGroupIterator = TerraformIterator.fromList(vpcSecurityGroupIds);
const vpcSubnetsIterator = TerraformIterator.fromList(vpcSubnetIds);
const lambdaFunction = new Lambda(scope, `lambda-${functionName}`, {
imageUri: `<>`,
createPackage: false,
packageType: 'Image',
functionName: `${serviceName}_${functionName}`,
attachPolicyJson: true,
policyJson: policy.json,
timeout: 60,
environmentVariables: {
},
vpcSecurityGroupIds,
vpcSubnetIds,
createAsyncEventConfig: true,
attachNetworkPolicy: true,
publish: true,
eventSourceMapping: {
kafka: {
topics: ['<>'],
starting_position: 'LATEST',
self_managed_event_source: [
{
endpoints: { KAFKA_BOOTSTRAP_SERVERS: '<> },
},
],
self_managed_kafka_event_source_config: [
{
consumer_group_id: serviceName,
},
],
source_access_configuration: [
{
type: 'SASL_SCRAM_512_AUTH',
uri: secretArn,
},
{
type: 'SERVER_ROOT_CA_CERTIFICATE',
uri: '<>',
},
vpcSecurityGroupIterator.dynamic({
type: 'VPC_SECURITY_GROUP',
uri: vpcSecurityGroupIterator.value,
}),
vpcSubnetsIterator.dynamic({
type: 'VPC_SUBNET',
uri: vpcSubnetsIterator.value,
}),
],
},