I am really new to terraform so please forgive anything I say incorrectly. I come from a normal programming background (C/C++/C#/python etc)
In order to avoid duplication, I want to use a module output value to set a variable value in variables.tf using string interpolation. When I do this and then do 'terraform validate' I get an Error: Variables not allowed.
String interpolation worked fine when I used the output value in a different .tf file to set a resource parameter.
resource "google_storage_bucket_iam_binding" "b-viewer" {
bucket = google_storage_bucket.b.name
role = "roles/storage.objectViewer"
members = ["abc${module.my_module.project_number}xyz"]
}
How can I achieve this?
What I have tried:
My terraform structure is:
root/variables.tf
root/module/<module name=""> # this is the module source
The module is called "my_module" and has an output e.g.
output "project_number" {
value = google_project.project.number
}
In root/variables.tf I have:
variable "my_variable" {
type = string
default = "abc${module.my_module.project_number}xyz"
{
but this does not work, it throws and error because I have used the ${module.....} in the default value setting.
I also tried creating a local in variables.tf
locals {
my_project = module.my_module.project_number
}
and then tried using that in the variable:
default = "abc${local.my_project}xyz"
but that did not work either.
I have tried to find answers to this, of course, but have failed and may be completely missing a point, so I apologise in advance if I am being stupid :/