Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation of ignore_body_changes #583

Open
nyanhp opened this issue Aug 19, 2024 · 5 comments
Open

Deprecation of ignore_body_changes #583

nyanhp opened this issue Aug 19, 2024 · 5 comments

Comments

@nyanhp
Copy link

nyanhp commented Aug 19, 2024

Hi!

According to the documentation

- `ignore_body_changes` (List of String, Deprecated)
ignore_body_changes is deprecated, but what are we supposed to use instead? lifecycle can be used for some, but not all attributes.

image

@ms-henglu
Copy link
Member

Hi @nyanhp ,

Thank you for taking time to report this issue!

Please first switch to use the dynamic attribute in body then use the lifecycle.ignore_changes to suppress the diff.

lifecycle can be used for some, but not all attributes.

Would you please share more details about the scenario? Thanks!

@gareda
Copy link

gareda commented Aug 29, 2024

Hello, I can add a situation in the lifecycle parameter does not work. If I try to implement a virtual network with subnets where the lifecycle of the subnets I want to ignore, I get the following error:

resource "azapi_resource" "vnet" {
  type      = "Microsoft.Network/virtualNetworks@2024-01-01"
  name      = "test"
  parent_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test"
  location  = "Spain Central"

  body = {
    properties = {
      addressSpace = {
        addressPrefixes = ["10.0.0.0/16"]
      }
      dhcpOptions = {
        dnsServers = ["8.8.8.8", "1.1.1.1"]
      }

      subnets = [
        {
          name = "subnet1"
          properties = {
            addressPrefixes = ["10.0.1.0/24"]
          }
        },
        {
          name = "subnet2"
          properties = {
            addressPrefixes = ["10.0.2.0/24"]
          }
        }
      ]
    }
  }

  lifecycle {
    ignore_changes = [body.properties.subnets]
  }
}
Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Invalid configuration
│ 
│   with azapi_resource.virtual_network,
│   on main.tf line 1, in resource "azapi_resource" "virtual_network":
│    1: resource "azapi_resource" "virtual_network" {
│ 
│ embedded schema validation failed: the argument "body" is invalid:
│ `properties.subnets.0.properties.provisioningState` is not expected here, it's read only
│ `properties.subnets.0.properties.ipamPoolPrefixAllocations` is not expected here. Do you mean `properties.subnets.0.properties.ipAllocations`? 
│ `properties.subnets.0.etag` is not expected here, it's read only
│ `properties.subnets.1.etag` is not expected here, it's read only
│ `properties.subnets.1.properties.provisioningState` is not expected here, it's read only
│ `properties.subnets.1.properties.serviceEndpoints.0.provisioningState` is not expected here, it's read only
│ `properties.subnets.1.properties.ipamPoolPrefixAllocations` is not expected here. Do you mean `properties.subnets.1.properties.ipAllocations`? 
│  You can try to update `azapi` provider to the latest version or disable the validation using the feature flag `schema_validation_enabled = false` within the resource block

@ms-henglu
Copy link
Member

Hi @gareda ,

Thanks for the details! Behind the scene, the ignore_changes will add everything from the remote state which includes some read-only fields. It's easy to bypass that, please disable the validation using the feature flag schema_validation_enabled = false within the resource block.

@gareda
Copy link

gareda commented Aug 30, 2024

@ms-henglu I understand that I can do a bypass by disabling schema validation, but shouldn't the correct ones be that it is not necessary?

Another example where ignore_body_changes is more interesting than lifecycle is that the former can be dynamic, you can set conditionals using a : x ? y or other systems like for, lifecycle does not allow this at the moment, the values have to be static.

@jchancellor-ms
Copy link

Concur with @gareda on the last statement. As we publish modules that are reusable, the ability to dynamically define fields that are ignored is a nice workaround to the lack of support for dynamic configurations in a lifecycle block. Is there any appetite to have support for both types?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants