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

helper/schema: Make nested Set(s) in List(s) work #7393

Merged
merged 4 commits into from
Jun 29, 2016

Conversation

radeksimko
Copy link
Member

Related to #7253 & #7254
Supersedes/fixes #7268


Issue explained below in (hopefully) simple ASCII art.

resource schema

.
├── TypeInt
└── TypeList
    └── TypeSet
    └── TypeString
    └── TypeInt
    └── TypeBool

resource CRUD

resourceXyzCreate() {
  d.Get("TypeInt") # OK
  d.Get("TypeList") # OK
}
resourceXyzRead() {
  d.Get("TypeInt") # OK
  d.Get("TypeList") # OK
}
resourceXyzUpdate() {
  d.Get("TypeInt") # OK
  d.Get("TypeList") # returns *Set(TypeSet=NIL, TypeString, TypeInt, TypeBool)
}

The nested TypeSet inside TypeList was set to nil and any data further nested in that Set were ignored inside Update function of a resource unless that TypeSet field was actually contained in the diff.


Summary (couple of whys)

  • Previously there was a common exported ReadList function shared between all field readers (Diff, Map, Config), this was replaced with unexported implementations per each reader
    • it turns out each reader requires different approach, especially DiffFieldReader
    • this is a first step towards getting rid of the magical nestedConfigFieldReader
    • reader-specific function can call readPrimitive and doesn't have to perform the data-type detection anymore - theoretically should save us some CPU cycles and prevent the infinite loops (one of the reasons why nestedConfigFieldReader was there)
  • readSet implementation of the Diff reader was only reading the diff and worked fine for creation/deletion of whole sets, but not so well for cases where only part of the set was being updated (contained in the diff).
    • readSet now fills in the gaps by getting the missing data from previous reader

Tests, yey

About 84% LOC of this PR are just tests covering the broken (now fixed) functionality - all contained in a separate commit.


Another PR will follow to fix the original CloudFront bug with data types.

Although DiffFieldReader was the one mostly responsible for a buggy behaviour
more tests were added throughout the debugging process most of which
would fail without the bugfix.

 - ResourceData
 - MultiLevelFieldReader
 - MapFieldReader
 - DiffFieldReader
@radeksimko radeksimko force-pushed the b-schema-set-in-list branch from 8f9715e to 37d57f4 Compare June 28, 2016 16:41
// This should never happen, because by the time the data
// gets to the FieldReaders, all the defaults should be set by
// Schema.
panic("missing field in list: " + strings.Join(addrPadded, "."))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for panic here - as soon as I saw the "This should never happen" in the old shared impl i was like 💭 "we should panic then!" 😀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's more or less inherited from the original generic ReadList function, but it's still valid here too. 😄

@phinze
Copy link
Contributor

phinze commented Jun 29, 2016

Okay! This looks great @radeksimko, especially the extensive testing work.

Merge at will. 👍 🚀

@radeksimko radeksimko merged commit 26f294c into hashicorp:master Jun 29, 2016
@radeksimko radeksimko deleted the b-schema-set-in-list branch June 29, 2016 17:59
@catsby
Copy link
Contributor

catsby commented Jun 30, 2016

Hello –

We've found some regressions in our tests and suspect this PR. I'm going to issue a revert (#7436), but first, here are some examples:

--- FAIL: TestAccAWSSecurityGroup_Change (25.93s)
    testing.go:255: Step 1 error: Error applying: 1 error(s) occurred:

        * aws_security_group.web: Error authorizing security group ingress rules: InvalidParameterValue: Invalid value '' for IP protocol. No protocol value given.
--- FAIL: TestAccFastlyServiceV1_gzips_basic (15.47s)
    testing.go:255: Step 1 error: Error applying: 1 error(s) occurred:

        * fastly_service_v1.foo: 400 - Bad Request
        Message: Name can't be blank

From https://travis-ci.org/hashicorp/terraform/builds/141247532 and https://travis-ci.org/hashicorp/terraform/builds/141254784, respectively.

@ghost
Copy link

ghost commented Apr 24, 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 24, 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