Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Terraform uses the expression "Interpolation"

So, mathematically speaking, interpolation is a method of constructing new data points within the range of a discrete set of known data points.

Now, Terraform has been using this terminology to reference values, like variables.

I can't seem to find any minimal coincidence using this math term in TF. Where is the match?

like image 505
pedro Avatar asked Dec 08 '20 17:12

pedro


3 Answers

The other answers explain why Terraform uses the term interpolation, so I'll just answer the bit

Where is the match?

As you say, in mathematics, interpolation means making a new data point in between existing data points. Crudely, this could be something like

1  2  3  _  5  6
         ^
   please find an appropriate value for here

In software, string interpolation is the process of putting something into a gap in a string. For example

"For the problem above, _ is the simplest value" <- 4

So the coincidence comes about if you frame interpolation as "filling a gap". It's certainly not the exact same thing, but that's how they're similar.

like image 145
lxop Avatar answered Oct 06 '22 17:10

lxop


Different industries can use the same term in different ways. The usage of the term interpolation in software development is very common. The fact that mathematics uses the term in different ways does not really matter in the same way that they word "punch" means one thing in the boxing world and another in the metal working world.

String interpolation

like image 31
John Hanley Avatar answered Oct 06 '22 15:10

John Hanley


It's used in the same meaning as elsewhere in programming. Typically mentioned in a phrase "String interpolation". To quote Wikipedia:

In computer programming, string interpolation [...] is the process of evaluating a string literal containing one or more placeholders,

The reason Terraform mentions that is that whenever you define a value in Terraform, you can use quotes "" and within the quotes have one or more expressions, e.g. "ami-${var.image_id}". These expressions are evaluated and interpolated into the String.

like image 2
Grzegorz Oledzki Avatar answered Oct 06 '22 16:10

Grzegorz Oledzki