Hi,
I have more of a best practise question related to data sources. We are heavily using data sources like below in our TF modules instead of passing the value through variables.
e.g.,
data "aws_partition" "current" {}
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_iam_session_context" "current" {}
Sometimes i have to use the output value of these data source in multiple places in the same sub module.
My concern is that does it make a call to the data source AWS API for every occurrence that i use in the code? Is there a caching mechanism?
e.g., getting current partition data.aws_partition.current.partition
used multiple places in the module
Will it reduce the number of calls if i store the data source output in local variable and use the local variable across the module.
e.g.,
locals
{
aws_current_partition = data.aws_partition.current.partition
}
and then use this everywhere in the code
local.aws_current_partition
Please advise the best way to reduce the number of calls to improve the performance of PLAN and APPLY.
Overall does Hashicorp has any DONTS document on Terraform which you can share. We will would like to improve the performance of our code by avoid making unnecessary calls
Thanks in Advance!