Skip to content

Commit

Permalink
Merge pull request #1238 from vmware/omit-empty
Browse files Browse the repository at this point in the history
Add OmitIfEmpty option in metadata library
  • Loading branch information
annakhm authored Jun 26, 2024
2 parents 7f51f71 + 9115874 commit af29c99
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nsxt/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Metadata struct {
// skip handling of this attribute - it will be done manually
Skip bool
ReflectType reflect.Type
OmitIfEmpty bool
TestData Testdata
}

Expand Down Expand Up @@ -268,7 +269,7 @@ func SchemaToStruct(elem reflect.Value, d *schema.ResourceData, metadata map[str
continue
}
if item.Metadata.IntroducedInVersion != "" && util.NsxVersionLower(item.Metadata.IntroducedInVersion) {
logger.Printf("[TRACE] %s skip key %s as NSX does not have support", ctx, key)
logger.Printf("[TRACE] %s skip key %s as NSX version is lower than %v", ctx, key, item.Metadata.IntroducedInVersion)
continue
}
if !elem.FieldByName(item.Metadata.SdkFieldName).IsValid() {
Expand Down Expand Up @@ -307,6 +308,10 @@ func SchemaToStruct(elem reflect.Value, d *schema.ResourceData, metadata map[str
} else {
value = d.Get(key).(string)
}
if item.Metadata.OmitIfEmpty && value == "" {
logger.Printf("[TRACE] %s skip key %s since its empty and OmitIfEmpty is true", ctx, key)
continue
}
logger.Printf("[TRACE] %s assigning string %v to %s", ctx, value, key)
elem.FieldByName(item.Metadata.SdkFieldName).Set(reflect.ValueOf(&value))
}
Expand Down

0 comments on commit af29c99

Please sign in to comment.