Skip to content

Applies of nsxt_policy_predefined_security_policy are inconsistent and non-idempotent #631

Open
@neil-wwt

Description

@neil-wwt

Terraform CLI and Terraform Provider Version

Terraform v0.15.5
on windows_amd64
+ provider registry.terraform.io/vmware/nsxt v3.1.1

Affected Resource(s)

nsxt_policy_predefined_security_policy

Terraform Configuration Files

terraform {
  required_providers {
    nsxt = {
      source = "vmware/nsxt"
      version = "3.1.1"
    }
  }
}

provider "nsxt" {
# Your creds here
}

data "nsxt_policy_security_policy" "default_app_policy" {
  is_default = true
  category   = "Application"
}

resource "nsxt_policy_predefined_security_policy" "default_app_policy" {
  path = data.nsxt_policy_security_policy.default_app_policy.path
  default_rule {
    action = "DROP"
  }
}

Expected Behavior

  1. Run apply the first time. Change default rule to DROP (or whatever is specified) and do something (or don't) with other existing rules in that policy. (Not sure what the expected behavior is in regards to other rules)
  2. Run apply again and nothing else changes

Actual Behavior

  1. On the first apply, the default rule is modified. TF reports "1 to add"

  2. On the second apply, the other rules in the default policy are removed. TF reports "1 changed"

  3. On the second apply, the default rule is created. TF reports "1 to add"

Steps to Reproduce

  1. Have NSX-T default policy with at least one manually created rule. In this example, called Test
  2. terraform apply
    • On the first apply, the default rule is created. TF reports "1 to add"
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # nsxt_policy_predefined_security_policy.default_app_policy will be created
  + resource "nsxt_policy_predefined_security_policy" "default_app_policy" {
      + description = (known after apply)
      + id          = (known after apply)
      + path        = "/infra/domains/default/security-policies/default-layer3-section"
      + revision    = (known after apply)

      + default_rule {
          + action          = "DROP"
          + description     = (known after apply)
          + logged          = false
          + nsx_id          = (known after apply)
          + path            = (known after apply)
          + revision        = (known after apply)
          + scope           = (known after apply)
          + sequence_number = (known after apply)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

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

  Enter a value: yes

nsxt_policy_predefined_security_policy.default_app_policy: Creating...
nsxt_policy_predefined_security_policy.default_app_policy: Creation complete after 1s [id=default-layer3-section]
  1. Check NSX-T console. You will see the Test rule is still in place.

  2. terraform apply

    • After making no changes in code or console.
    • On the second apply, the other rules in the default policy are removed. TF reports "1 changed"
nsxt_policy_predefined_security_policy.default_app_policy: Refreshing state... [id=default-layer3-section]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # nsxt_policy_predefined_security_policy.default_app_policy will be updated in-place
  ~ resource "nsxt_policy_predefined_security_policy" "default_app_policy" {
        id       = "default-layer3-section"
        # (2 unchanged attributes hidden)


      - rule {
          - action                = "ALLOW" -> null
          - destination_groups    = [] -> null
          - destinations_excluded = false -> null
          - direction             = "IN_OUT" -> null
          - disabled              = false -> null
          - display_name          = "Test" -> null
          - ip_version            = "IPV4_IPV6" -> null
          - logged                = false -> null
          - nsx_id                = "Test" -> null
          - profiles              = [] -> null
          - revision              = 0 -> null
          - rule_id               = 0 -> null
          - scope                 = [] -> null
          - sequence_number       = 499999 -> null
          - services              = [] -> null
          - source_groups         = [] -> null
          - sources_excluded      = false -> null
        }
        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

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

  Enter a value: yes

nsxt_policy_predefined_security_policy.default_app_policy: Modifying... [id=default-layer3-section]
nsxt_policy_predefined_security_policy.default_app_policy: Modifications complete after 1s [id=default-layer3-section]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
  1. Check NSX-T console. You will see the Test rule has been removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions