Aws_secretsmanager saying ResourceNotFoundException

I create Aws secrets in secret manager then pass secret-name name to aws_secretsmanager in a packer file as :

locals {
  rt_auth_token = aws_secretsmanager("${var.sm_rt_auth_token_name}", null)
}

But I am getting

failed: ResourceNotFoundException: Secrets\nManager can’t find the specified secret…

When I use aws CLI to check this

aws secretsmanager get-secret-value --secret-id <secret-name> --region ca-central-1 

i get secret is there something else going wrong with packer get secret or do I have to something else ?

Is your packer build running in that correct region?

Hello, Yes and I was using aws-vault for credentials and packer was not picking the aws-region variable I set as var

This get solve by adding aws-region as env variable though wondering why -var packer isnt picking the variable up.

N.B I have region defined as variable in packer file

When I run this :
awsv packer build -var sm_rt_auth_token_name=rt-token-NE2sQX -var aws_region=us-east-1 -var builder_instance_type=t2.micro eks-node.pkr.hcl

I get this error :
Error: Error in function call

on eks-node.pkr.hcl line 42:
(source code not available)

with var.sm_rt_auth_token_name as “rt-token-NE2sQX”.

Call to function “aws_secretsmanager” failed: MissingRegion: could not find
region configuration.

As an artifact of the way the AWS plugin is built, I don’t think the region information gets shared between the AWS builder and this secretsmanager function.

Since you’re in HCL, I’d recommend using the secrets manager data source instead: Secrets Manager - Data Source | Packer by HashiCorp, which allows you to define the authentication inside the data source so that it doesn’t get lost.