简体   繁体   中英

How do you reference a dynamic terraform output in application code?

I'm creating a dynamodb table using terraform and the name attribute of the table looks something like this...

name = "${var.service}-${var.environment}-Item-table"

Depending on the environment the name could be items-service-dev-Item-table or items-service-prod-Item-table . In my application code (JS) I obviously need to know the name of the table in order to interact with it but the dynamic nature makes it trickier.

I've considered going down the route of environment variables that are referenced by both the terraform and application code, but it seems messy. What's the best practice approach for handling something like this?

Is terraform also deploying your application code? Usually you would have Terraform inject that value as an environment variable in the application it deploys.

If that's not possible, store the value in AWS Parameter Store .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM