tankovich
tankovich

Reputation: 11

Terraform variable without interpolation

This seems like a simple question and maybe I'm misreading the documentation somewhere. I am trying to set a variable with a string value, in my case it is a SAS token for an Azure blob, which I then want to pass in to a template deployment. The issue that I am running into is that the string gets interpolated causing the token to be invalid. I am unable to figure out how I can pass a variable and not have it be interpolated.

scripts_blob_sas_token = "${var.scripts_blob_sas_token}"

This is the string:

?sv=2015-04-05&sr=c&sig=O%2FurgY2Eu%2FZN3Ax1GSN58cNpc2DRMahLdB7lPqVifNc%3D&st=2017-06-13T17%3A17%3A45Z&se=2027-06-13T17%3A17%3A45Z&sp=r

When I reference the ${var.scripts_blob_sas_token} variable it get interpolated to this:

?sv=2015-04-05\\u0026sr=c\\u0026sig=O%2FurgY2Eu%2FZN3Ax1GSN58cNpc2DRMahLdB7lPqVifNc%3D\\u0026st=2017-06-13T17%3A17%3A45Z

Is there a way to call a variable in Terraform and escape interpolation of the string?

Any ideas/suggestions would be appreciated.

Upvotes: 1

Views: 1740

Answers (1)

strongjz
strongjz

Reputation: 4491

You can put the variable into a file and read it into a string.

file(path) - Reads the contents of a file into the string. Variables in this file are not interpolated. The contents of the file are read as-is. The path is interpreted relative to the working directory. Path variables can be used to reference paths relative to other base locations. For example, when using file() from inside a module, you generally want to make the path relative to the module base, like this: file("${path.module}/file").

https://www.terraform.io/docs/configuration/interpolation.html#file-path-

Upvotes: 0

Related Questions