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

Unchanged NestedSets are not returned by DiffFieldReader. #8891

Merged
merged 3 commits into from
Oct 3, 2016

Conversation

gotascii
Copy link
Contributor

@gotascii gotascii commented Sep 17, 2016

Given a schema such as:

schema := map[string]*Schema{
  "list_of_sets_1": &Schema{
    Type: TypeList,
    Elem: &Resource{
      Schema: map[string]*Schema{
        "nested_set": &Schema{
          Type: TypeSet,
          Elem: &Resource{
            Schema: map[string]*Schema{
              "val": &Schema{
                Type: TypeInt,
              },
            },
          },
          Set: func(a interface{}) int {
            m := a.(map[string]interface{})
            return m["val"].(int)
          },
        },
      },
    },
  },
  "list_of_sets_2": &Schema{
    Type: TypeList,
    Elem: &Resource{
      Schema: map[string]*Schema{
        "nested_set": &Schema{
          Type: TypeSet,
          Elem: &Resource{
            Schema: map[string]*Schema{
              "val": &Schema{
                Type: TypeInt,
              },
            },
          },
          Set: func(a interface{}) int {
            m := a.(map[string]interface{})
            return m["val"].(int)
          },
        },
      },
    },
  },
}

And a configuration such as:

resource "provider_name_resource_name" "test" {
  list_of_sets_1 {
    nested_set {
      val = 1
    }
  }
  list_of_sets_2 {
    nested_set {
      val = 1
    }
  }
}

Updating the val of the nested_set inlist_of_sets_1 from 1 to 2:

resource "provider_name_resource_name" "test" {
  list_of_sets_1 {
    nested_set {
      val = 2
    }
  }
  list_of_sets_2 {
    nested_set {
      val = 1
    }
  }
}

Results in resourceData.Get("list_of_sets_2") returning an empty *schema.Set.

This PR provides a unit test along with a fix. The fix is to check if the state has a value for the field after determining that the value does not exist in the diff. This matches the behavior of the primitive and other field types.

I ran all of the other core tests and they continue to pass, so I think the fix is not inadvertently breaking anything. Would love feedback on how to get this PR to a state where it is mergable! Thanks!

@phinze
Copy link
Contributor

phinze commented Oct 3, 2016

This looks great - thanks @gotascii!

@ghost
Copy link

ghost commented Apr 21, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants