Terraform v0.12.28 and template parser

Hello.
I have a problem with Terraform v0.12.28, using new version via Octopus.Action.Terraform.CustomTerraformExecutable variable.
When I use new syntax, like:

resource "azurerm_app_service_plan" "Intermediate" {
  name                = "ReplyWebAutomationPlan"
  location            = "West Europe"
  resource_group_name = "ReplyAutomationGroup"
  kind                = "app"
  sku {
    	tier = "Standard"
        size = "S1"
	  }
}

resource "azurerm_app_service" "IntermediateWeb" {
  name                = "webreplyintermediate"
  location            = "West Europe"
  resource_group_name = "ReplyAutomationGroup"
  app_service_plan_id = azurerm_app_service_plan.Intermediate.id
  https_only = true
  client_affinity_enabled = false
}

I get error from built-in Terraform parser.
If I use it like:

app_service_plan_id = "${azurerm_app_service_plan.Intermediate.id}"

it works, but I get warning from Terraform:

Warning: Interpolation-only expressions are deprecated 
on template.tf line 58, in resource "azurerm_app_service" "IntermediateWeb": 
58:   app_service_plan_id = "${azurerm_app_service_plan.Intermediate.id}" 
Terraform 0.11 and earlier required all non-constant expressions to be 
provided via interpolation syntax, but this pattern is now deprecated. To 
silence this warning, remove the "${ sequence from the start and the }" 
sequence from the end of this expression, leaving just the inner expression. 
Template interpolation syntax is still used to construct strings from 
expressions when the template includes multiple interpolation sequences or a 
mixture of literal strings and interpolations. This deprecation applies only 
to templates that consist entirely of a single interpolation sequence. 

Is it possible to fix a parser issue (or turn it off) and use new syntax?
Thanks in advance!

Hey Pavel,

Thanks for reaching out.

Within your Terraform steps, do you have this option checked?

Assuming ${azurerm_app_service_plan.Intermediate.id} is an octopus variable, terraform should never see the placeholder, only the value.

Please let me know if that helps or if we need to dig in further.

Thanks,
Jeremy

Hi Jeremy.
Thanks for quick response.
azurerm_app_service_plan.Intermediate.id isn’t an Octopus variable, it’s explicit resource dependency to another resource (resource "azurerm_app_service_plan" "Intermediate").
I’m just curious, how to pass throught template parser with
app_service_plan_id = azurerm_app_service_plan.Intermediate.id
instead of
app_service_plan_id = "${azurerm_app_service_plan.Intermediate.id}"
P.S. I’m using standelone Octopus server and don’t have “Replace variables in default Terraform files” option.

Hi Pavel,

Would you be able to privately message a copy of your TF files for me to pass along? It appears like I may need to speak to the engineers about this one.

Are you able to use a TF .11 compatible file for now?

Would you also be able send me a copy of your deployment process JSON? To get this go to the Project, then the process section, then click the 3 dots to the right of add step and click download JSON.

Could we also possibly get a copy of the package? If the file is too big for the private message you can upload the file to our support files. (please include your organization name in our private message).
To do this do the following:

  1. Log in to octopus.com
  2. Click your profile in the upper right
  3. Click your organization
  4. Go to the support tab

Please let me know if you have any questions.

Thanks,
Jeremy

Hi Jeremy.
For now, I’m using free server license and don’t have opportunity to use support. It’s why I’m writing on forum.
But template to reproduce is pretty simple.
This is Terraform 0.12 format:

terraform {
  backend "azurerm" {
    resource_group_name   = "ReplyAppSecondStageGroup"
    storage_account_name  = "replyappstages"
    container_name        = "terraform-state"
    key                   = "terraform.tfstate"
  }
}

data "azurerm_client_config" "current" {}

provider "azurerm" {
features {}
}

resource "azurerm_app_service_plan" "Intermediate" {
  name                = "ReplyWebAutomationPlan"
  location            = "West Europe"
  resource_group_name = "ReplyAutomationGroup"
  kind                = "app"

  sku {
 	tier = "Standard"
    size = "S1"
	  }
}

resource "azurerm_app_service" "IntermediateWeb" {
  name                = "webreplyintermediate"
  location            = "West Europe"
  resource_group_name = "ReplyAutomationGroup"
  app_service_plan_id = azurerm_app_service_plan.Intermediate.id
  https_only = true
  client_affinity_enabled = false

  site_config {
  default_documents         = [
              "Default.htm",
              "Default.html",
              "Default.asp",
              "index.htm",
              "index.html",
              "iisstart.htm",
              "default.aspx",
              "index.php",
              "hostingstart.html",
            ]
    dotnet_framework_version = "v4.0"
	always_on = true
	http2_enabled = true
	scm_type                  = "None"
    use_32_bit_worker_process = false
	websockets_enabled        = true
	  }
}

But you won’t be able to add this code, coz this line:
app_service_plan_id = azurerm_app_service_plan.Intermediate.id
Parser won’t accept it.
You can use app_service_plan_id = “${azurerm_app_service_plan.Intermediate.id}” instead, but since we use terraform 0.12 exe, you will get this warning:

Warning: Interpolation-only expressions are deprecated

  on test.tf line 34, in resource "azurerm_app_service" "IntermediateWeb":
  34:   app_service_plan_id = "${azurerm_app_service_plan.Intermediate.id}"

Terraform 0.11 and earlier required all non-constant expressions to be
provided via interpolation syntax, but this pattern is now deprecated. To
silence this warning, remove the "${ sequence from the start and the }"
sequence from the end of this expression, leaving just the inner expression.

Template interpolation syntax is still used to construct strings from
expressions when the template includes multiple interpolation sequences or a
mixture of literal strings and interpolations. This deprecation applies only
to templates that consist entirely of a single interpolation sequence.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

Hi Pavel,

Thank you for the details. Even if you are on a free license you can email us at support@octopus.com, you just cant upload files to octopus.com.

Would you be able to either private message me your deployment process JSON or email it to support? The engineers need to take a look at it.

Thanks,
Jeremy

Hi @Pavel_Timoschenkov,

The issue here is that the inline template parsing feature only supports Terraform 0.11 syntax. If you add Terraform 0.12 style templates, the built in parser will fail.

The workaround is to reformat the code as Terraform 0.11 syntax (as you have done), but this has the downside of the warnings produced by Terraform 0.12. You can also bundle the Terraform templates into a package, in which case Octopus will not attempt the validate the files, meaning you can use Terraform 0.12 syntax.

Regards
Matt

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.