Skip to content

Terraform does not detect change in resource in case nested list value is known after apply #1491

@annakhm

Description

@annakhm

SDK version

v2.37.0

Relevant provider source code

func resourceNsxtTest() *schema.Resource {
	return &schema.Resource{
		Create: resourceNsxtDummyCreate,
		Read:   resourceNsxtDummy,
		Update: resourceNsxtDummy,
		Delete: resourceNsxtDummy,
		Schema: map[string]*schema.Schema{
			"test_computed": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"test_string": {
				Type:     schema.TypeString,
				Optional: true,
			},
			"test_list": {
				Type:     schema.TypeList,
				Optional: true,
				Elem: &schema.Schema{
					Type: schema.TypeString,
				},
			},
			"test_struct_list": {
				Type:        schema.TypeList,
				Optional:    true,
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"test_string": {
							Type:     schema.TypeString,
							Optional: true,
						},
						"test_list": {
							Type:     schema.TypeList,
							Optional: true,
							Elem: &schema.Schema{
								Type: schema.TypeString,
							},
						},
					},
				},
			},
		},
	}
}

Terraform Configuration Files

starting config

resource "nsxt_test" "test" {
  test_string = "some string"
  test_struct_list {
    test_string = "some nested string"
  }
}

update config

resource "nsxt_test" "parent" {
  test_string = "parent"
}

resource "nsxt_test" "test" {
  test_string = "some string"
  test_struct_list {
    test_list = [nsxt_test.parent.test_computed]
    test_string = "some nested string"
  }
}

Debug Output

https://gist.github.com/annakhm/1d20ea8d36124c5e0b95a9389331884d

Expected Behavior

plan should detect 1 new resource (nsxt_test.parent) and change in 1 resource (nsxt_test.test)

Actual Behavior

plan only detects 1 new resource (nsxt_test.parent)

Steps to Reproduce

  1. compile terraform provider nsxt from branch https://github.com/vmware/terraform-provider-nsxt/tree/sdk-bug-demo
  2. configure one resource
resource "nsxt_test" "test" {
  test_string = "some string"
  test_struct_list {
    test_string = "some nested string"
  }
}
  1. terraform apply - resource gets created
  2. change config to
resource "nsxt_test" "parent" {
  test_string = "parent"
}

resource "nsxt_test" "test" {
  test_string = "some string"
  test_struct_list {
    test_list = [nsxt_test.parent.test_computed]
    test_string = "some nested string"
  }
}
  1. terraform plan

Notes

  1. The issue does not happen with terraform plugin framework. I've coded a similar resource and it works as expected (code available upon request). This leads me to believe the issue is in the SDK and not terraform core.
  2. The issue only happens with schema where list attribute is defined under nested block. It works as expected for top-level list attribute, and also for nested string attribute.
  3. I've created a simple demo resource for the issue based on an actual use case for the issue (more complex resource) in nsxt provider

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions