I want to dynamically set a variable object depending on another variable object_name. So for example, if object_name = object1, the value assigned to variable object should be content of object1
Although many of these names use dot-separated paths that resemble attribute notation for elements of object values, they are not implemented as real objects. This means you must use them exactly as written
If you want to look up a value dynamically based on another variable, the typical answer would be to construct a map whose keys are values that other variable might have.
For example, if you have a variable var.object_name as you described then you can construct a map in a local value whose keys are the different values that variable might take, like this:
With the above definition, local.object will refer to whichever of the objects in local.objects the var.object_name value refers to, or return an error if the given name isn’t one of the expected values.
The Terraform language uses static global definitions rather than dynamic ones, so this isn’t a language where you can dynamically manipulate the global scope as you might be accustomed to from more dynamic languages like Python or JavaScript. If you want to look up values dynamically like this then you can do so by constructing the appropriate data structure to do so, which in this case was a mapping since the dynamic key is a string.