Terraform, Ignore specific app setting azurerm

4.1k views Asked by At

I'm using Terraform and right now I'm in a situation where all my appsettings for my apps is being populated as the infrastructure might change. This way it's all automatic.

However, I've got a problem with my linux consumption plan Functions app that has an appsetting that needs to be set during deployment. WEBSITE_RUN_FROM_PACKAGE is the value that is set to a URL during deployment.

My problem is that terraform will remove this value or set it to whatever I set it to.

How can I get this value to stay as is during terraform deployment?

Either getting the value from azure or ignoring the value in terraform?

I found this but it does not seem to work for the appsettings section.

https://www.terraform.io/docs/configuration/resources.html#ignore_changes

My test:

resource "azurerm_function_app" "shipping-broker-msw-func" {
  name                       = "shipping-broker-msw-func"
  ...

  app_settings = {
    ...
    "WEBSITE_RUN_FROM_PACKAGE"        = "URL_Form_CD"
  }

   lifecycle {
    ignore_changes = [
      app_settings["WEBSITE_RUN_FROM_PACKAGE"],
    ]
  }
}
1

There are 1 answers

2
JJ F On BEST ANSWER

From Terraform documentation: https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes

enter image description here

So it seems the reason is that, when you first create the app service, you need to include the key (with a dummy value possibly) in order to be able to specify later on that you wanna ignore it.

If you did not include the key at the very beginning, you can still add it later on. So just add in your configuration that key with a dummy value, and then the ignore_changes seems to work. In my case it worked.