terraform-provider-azapi icon indicating copy to clipboard operation
terraform-provider-azapi copied to clipboard

How to ignore_body_changes for nested properties

Open jkroepke opened this issue 2 years ago • 11 comments

I want to setup an vm gallery, however I would like to ignore properties inside a list:

  ~ resource "azapi_resource" "gallery_application_version_linux" {
      ~ body                      = jsonencode(
          ~ {
              ~ properties = {
                  ~ publishingProfile = {
                      ~ targetRegions      = [
                          ~ {
                              ~ name                 = "West Europe" -> "westeurope"
                                # (2 unchanged attributes hidden)
                            },
                        ]
                        # (8 unchanged attributes hidden)
                    }
                    # (1 unchanged attribute hidden)
                }
            }
        )
        id                        = "/subscriptions/***/resourceGroups/rg-dev-opsstack-westeurope-001/providers/Microsoft.Compute/galleries/DEV_GAL_OPSSTACK_WESTEUROPE_001/applications/opsstack-agent-linux/versions/1.1.0"
        ignore_body_changes       = [
            "properties.publishingProfile.source.media_link",
            "properties.publishingProfile.targetRegions.*.name",
        ]
        name                      = "1.1.0"
        # (9 unchanged attributes hidden)
    }

I tired properties.publishingProfile.targetRegions.*.name, however it seems like it has not affect.

jkroepke avatar Sep 20 '23 12:09 jkroepke

I quickly read the the code and the provider does not seem to support the override of specific item in list.

gianrubio avatar Oct 04 '23 13:10 gianrubio

Hi @jkroepke ,

Thank you for taking time to report this issue and apologize for late response.

Thanks @gianrubio for answering the question, and yes, the provider doesn't support the override of specific item in the list.

More details: https://github.com/Azure/terraform-provider-azapi/issues/315#issuecomment-1716943998

ms-henglu avatar Oct 11 '23 06:10 ms-henglu

Also would like ability to ignore specific item + property in a list. We are deploying Azure Container Apps via AzApi. Terraform creates the container app resource for us with the latest image tag. Once the app is created, we use Azure DevOps to apply image updates to the container app.

Ideally, we can use "ignore_body_changes" to ignore "properties.template.containers[0].image"

image

jsheetzmt avatar Dec 04 '23 17:12 jsheetzmt

My from point of view, this can be archived by using json path at the ignore property.

jkroepke avatar Dec 04 '23 18:12 jkroepke

Adding the following snippet to the azapi_resource doesn't work as intented. Just like @jsheetzmt pointed out.

ignore_body_changes = ["properties.template.containers[0].image"]

mvanhil avatar Dec 08 '23 08:12 mvanhil

I was doing something wrong. It works as expected for me @jsheetzmt

mvanhil avatar Dec 08 '23 09:12 mvanhil

I was doing something wrong. It works as expected for me

Could you please provide some example of working config? @mvanhil It seems it should not work: https://github.com/Azure/terraform-provider-azapi/issues/315

For me it does not work either, have tried following:

ignore_body_changes = ["properties.template.containers[0].image"] ignore_body_changes = ["properties.template.containers[\"job_name\"].image"] ignore_body_changes = ["properties.template.containers"]

koldyba avatar Jan 10 '24 17:01 koldyba

I am also trying to achieve same thing. For me it did not work with ignore_body_changes = ["properties.template.containers"]

Getting the error as below.

Error: ignoring specific item in list is not supported

@mvanhil : Can u please share configuration if it is working for you.

deen-nitj avatar Jan 11 '24 12:01 deen-nitj

In the meanwhile I migrated all the azapi stuff to the modified TF resources. I was missing the workload profile feature, but since that has been added, I migrated everything over. A lot easier now. :-)

mvanhil avatar Jan 11 '24 12:01 mvanhil

@mvanhil: Thanks for your quick response.

deen-nitj avatar Jan 11 '24 13:01 deen-nitj