https://infracost.io logo
#contributors
Title
# contributors
s

stocky-magazine-90066

02/06/2023, 1:38 PM
Hi, can I just clarify something with ReferenceAttributes? I've added the following reference attribute for the lambda function resource
Copy code
func getLambdaFunctionRegistryItem() *schema.RegistryItem {
	return &schema.RegistryItem{
		Name:                "aws_lambda_function",
		Notes:               []string{"Provisioned concurrency is not yet supported."},
		ReferenceAttributes: []string{"function_name"},
		CoreRFunc:           NewLambdaFunction,
	}
}
I then added this to a new resource for provisioned concurrency
Copy code
func getLambdaProvisionedConcurrencyConfigRegistryItem() *schema.RegistryItem {
	return &schema.RegistryItem{
		Name:                "aws_lambda_provisioned_concurrency_config",
		RFunc:               NewLambdaProvisionedConcurrencyConfig,
		ReferenceAttributes: []string{"aws_lambda_function.function_name"},
	}
}
Am I missing something ? Because I'm unable to access this from within the new provisioned concurrency resource. It's empty!! Any help would be appreciated, I looked at the example here Example terraform below.
Copy code
# Add example resources for LambdaProvisionedConcurrencyConfig below
resource "aws_lambda_provisioned_concurrency_config" "lambda_provisioned_concurrency_config" {
  function_name                     = aws_lambda_function.lambda.function_name
  provisioned_concurrent_executions = 50
  qualifier                         = aws_lambda_function.lambda.version
}

resource "aws_lambda_function" "lambda" {
  function_name = "lambda_function_name"
  role          = "arn:aws:lambda:us-east-1:account-id:resource-id"
  handler       = "exports.test"
  filename      = "function.zip"
  runtime       = "nodejs12.x"
  architectures = ["arm64"]
  memory_size   = 512
}
l

little-author-61621

02/06/2023, 1:52 PM
@stocky-magazine-90066 which resource are you adding the new cost to? The
aws_lambda_function
or the
aws_lambda_provisioned_concurrency_config
?
s

stocky-magazine-90066

02/06/2023, 2:06 PM
Hi @little-author-61621 I was looking to add
aws_lambda_provisioned_concurrency_config
as a new resource, but the resource needs some information from
aws_lambda_function
which I thought I could do via the reference attributes.
Or maybe I'm actually thinking about this in the wrong way.
With some of the examples I looked at on the pricing page, provisioned concurrency is a separate charge. A common use case looks to be that provisioned concurrency isn't enabled 24 x 7 . So I was going to look at implementing this as a separate resource & provide the concurrency usage separate values. But maybe I was getting to far ahead & I wanted to include somethings from the lambda function. The only thing I actually need at the moment when I'm thinking out loud is the Architecture for the function, as there's a cost difference for ARM v x86. Which as an initial thought could be a usage parameter.
l

little-author-61621

02/06/2023, 2:13 PM
yeah, looking at it now it seems like it makes sense to treat it as a separate resource. I think what you might want is this on the
aws_lambda_provisioned_concurrency_config
resource:
Copy code
ReferenceAttributes: []string{"function_name"}
And then this on the
aws_lambda_function
resource so it knows to use
function_name
as an identifer:
Copy code
CustomRefIDFunc: func(d *schema.ResourceData) []string {
  name := d.Get("function_name").String()
  if name != "" {
    return []string{name}
  }

  return nil
}
s

stocky-magazine-90066

02/06/2023, 2:16 PM
Thanks @little-author-61621 I think initially I was possibly over complicating it. I think I've a clearer path forward for an initial stab.
l

little-author-61621

02/06/2023, 2:17 PM
👍 great! lmk if I can help more
4 Views