Incorrect usage of trim function leads to malformed resource names in monitoring resources terraform
In the Terraform module, the trim function is being used to remove specific suffixes from strings. However, the current usage can lead to the unintended removal of characters, causing malformed resource names in Azure resources.
Description: In the Monitoring Resources main.tf Terraform module, the trim function is being used to remove specific suffixes from strings. However, the current usage can lead to the unintended removal of characters, causing malformed resource names in Azure resources.
Details: The specific instance observed is in the trimming of the -rg suffix from resource group names. The current code uses:
central_group_prefix = trim(data.terraform_remote_state.central_resources.outputs.central_resource_group_name, "-rg")
The intention is to remove the -rg suffix, but due to the behavior of trim, it also removes any individual -, r, and g characters from the ends of the string, leading to unexpected results.
For instance, a name like "osdu-pl2-crpl2-583g-rg" is trimmed to "osdu-pl2-crpl2-583" instead of the expected "osdu-pl2-crpl2-583g".
Expected Behavior: The -rg suffix should be removed without affecting other characters in the string.
Actual Behavior: Characters within the -rg suffix are being removed individually if they are at the ends of the string, leading to unexpected results.
Steps to Reproduce:
Use a resource group name like "osdu-pl2-crpl2-583g-rg". Apply the Terraform module. Observe that resources dependent on the central_group_prefix variable have the g character missing. Suggested Fix: Replace the trim function with the trimsuffix function, which will only remove the exact -rg suffix:
central_group_prefix = trimsuffix(data.terraform_remote_state.central_resources.outputs.central_resource_group_name, "-rg")
This change should be applied wherever the trim function is used in a similar context.