-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fixed error when a boolean field set to false #4004
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
if obj["fields"] != nil { | ||
// isEmptyValue() does not work for a boolean as it shows | ||
// false when it is 'empty'. Filter boolValue here based on | ||
// the rule api does not take more than 1 'value' | ||
fields := obj["fields"].(map[string]interface{}) | ||
for _, elements := range fields { | ||
values := elements.(map[string]interface{}) | ||
if len(values) > 1 { | ||
for val := range values { | ||
if val == "boolValue" { | ||
delete(values, "boolValue") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return obj, nil |
64 changes: 64 additions & 0 deletions
64
templates/terraform/examples/data_catalog_entry_tag_false.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
resource "google_data_catalog_entry" "entry" { | ||
entry_group = google_data_catalog_entry_group.entry_group.id | ||
entry_id = "<%= ctx[:vars]['entry_id'] %>" | ||
|
||
user_specified_type = "my_custom_type" | ||
user_specified_system = "SomethingExternal" | ||
} | ||
|
||
resource "google_data_catalog_entry_group" "entry_group" { | ||
entry_group_id = "<%= ctx[:vars]['entry_group_id'] %>" | ||
} | ||
|
||
resource "google_data_catalog_tag_template" "tag_template" { | ||
tag_template_id = "<%= ctx[:vars]['tag_template_id'] %>" | ||
region = "us-central1" | ||
display_name = "Demo Tag Template" | ||
|
||
fields { | ||
field_id = "source" | ||
display_name = "test boolean value" | ||
type { | ||
primitive_type = "BOOL" | ||
} | ||
is_required = true | ||
} | ||
|
||
fields { | ||
field_id = "num_rows" | ||
display_name = "Number of rows in the data asset" | ||
type { | ||
primitive_type = "DOUBLE" | ||
} | ||
} | ||
|
||
fields { | ||
field_id = "pii_type" | ||
display_name = "PII type" | ||
type { | ||
enum_type { | ||
allowed_values { | ||
display_name = "EMAIL" | ||
} | ||
allowed_values { | ||
display_name = "SOCIAL SECURITY NUMBER" | ||
} | ||
allowed_values { | ||
display_name = "NONE" | ||
} | ||
} | ||
} | ||
} | ||
|
||
force_delete = "<%= ctx[:vars]['force_delete'] %>" | ||
} | ||
|
||
resource "google_data_catalog_tag" "<%= ctx[:primary_resource_id] %>" { | ||
parent = google_data_catalog_entry.entry.id | ||
template = google_data_catalog_tag_template.tag_template.id | ||
|
||
fields { | ||
field_name = "source" | ||
bool_value = false | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to remove user-set boolValues, and even ones that are set to True? Even though we are enacting the API's rules, we should either validate during plan or let the user's bad configuration return an error, not change their values underneath the hood.
I think this encoder solves the problem of sending too many boolValue's, but checking if the user has set the field using
d.GetOkExists()
would do better here to make sure we are carrying out the user's intent. We can check if the value is set, and if not, delete it. How does that sound?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually backtracking on this: we can't use
d.GetOkExists()
becausefields
is a set and cannot be indexed. Don't really know any other way of tell the difference between user set/unset. Do you @ndmckinley ?We stick with this original approach and only remove if the bool_value is false? Seems slightly better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing sticks out to me. Maybe we should pause this for a day or two and think on it, let it percolate, bring it up in the next Monday meeting if we haven't thought of anything clever by then. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the API only except 1 value for
fields
? If so we can use One-of validation to make sure the user isn't setting multiple values. Then we are free to delete the extra boolean values in this encoderThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the API only take 1 value for each fields. But there is no way to distinguish between
empty
andfalse
for bool, along with othervalue
types.