Skip to content

avi_httppolicyset resource shows perpetual drift on every plan due to computed attributes #680

@Arderos

Description

@Arderos

Describe the bug

The avi_httppolicyset resource shows changes on every terraform plan even when no configuration changes have been made. The resource is constantly trying to replace the http_request_policy block.

Reproduction steps

  1. Create an avi_httppolicyset resource with http_request_policy rules
  2. Run terraform apply - succeeds
  3. Run terraform plan again with no changes
  4. Observe perpetual drift

Expected behavior

Expected Behavior

Running terraform plan with no configuration changes should show "No changes. Your infrastructure matches the configuration."

Actual Behavior

Every terraform plan shows the http_request_policy block being removed and re-added with identical values. The diff shows computed attributes like hdr_index, all_headers, log, pool_group_ref, status_code being returned by the API but not properly handled as computed-only by the provider.

Additional context

Terraform Configuration

resource "avi_httppolicyset" "monitoring_http_policy" {
  name               = "astr-monitoring-http-policy"
  is_internal_policy = false

  http_request_policy {
    rules {
      name   = "add-x-forwarded-proto"
      index  = 1
      enable = true
      hdr_action {
        action = "HTTP_ADD_HDR"
        hdr {
          name = "X-Forwarded-Proto"
          value {
            val = "https"
          }
        }
      }
    }
    rules {
      name   = "route-vmalert"
      index  = 2
      enable = true
      match {
        path {
          match_criteria = "BEGINS_WITH"
          match_str      = ["/vmalert"]
          match_case     = "INSENSITIVE"
        }
      }
      switching_action {
        action   = "HTTP_SWITCHING_SELECT_POOL"
        pool_ref = avi_pool.vmalert.id
      }
    }
  }
}

Plan Output (truncated)

# avi_httppolicyset.monitoring_http_policy will be updated in-place
~ resource "avi_httppolicyset" "monitoring_http_policy" {
    id   = "https://..."
    name = "astr-monitoring-http-policy"

  - http_request_policy {
      - rules {
          - enable      = "true" -> null
          - index       = "1" -> null
          - name        = "add-x-forwarded-proto" -> null

          - hdr_action {
              - action    = "HTTP_ADD_HDR" -> null
              - hdr_index = "4" -> null          # <-- computed by API
              ...
            }
        }
    }
  + http_request_policy {
      + rules {
          + enable      = "true"
          + index       = "1"
          + name        = "add-x-forwarded-proto"

          + hdr_action {
              + action    = "HTTP_ADD_HDR"
              + hdr_index = (known after apply)  # <-- not in config
              ...
            }
        }
    }
}

Root Cause Analysis

The AVI API returns additional computed attributes (hdr_index, all_headers, log, pool_group_ref, status_code, etc.) that are not specified in the Terraform configuration. The provider schema does not properly mark these as Computed: true only, causing Terraform to see a difference between state and config on every plan.

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions