Skip to content

Commit

Permalink
Merge pull request #482 from vmware/preserve_lb_rules
Browse files Browse the repository at this point in the history
Alternative fix for preserving LB VS rules
  • Loading branch information
annakhm authored Oct 9, 2020
2 parents 7c3927f + 65f82ca commit 6d50c85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
12 changes: 0 additions & 12 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,18 +533,6 @@ func configurePolicyConnectorData(d *schema.ResourceData, clients *nsxtClients)
return nil
}

type enablePartialPatchHeaderProcessor struct {
}

func newEnablePartialPatchHeaderProcessor() *enablePartialPatchHeaderProcessor {
return &enablePartialPatchHeaderProcessor{}
}

func (processor enablePartialPatchHeaderProcessor) Process(req *http.Request) error {
req.Header.Set("nsx-enable-partial-patch", "true")
return nil
}

type remoteBasicAuthHeaderProcessor struct {
}

Expand Down
15 changes: 11 additions & 4 deletions nsxt/resource_nsxt_policy_lb_virtual_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,6 @@ func resourceNsxtPolicyLBVirtualServerRead(d *schema.ResourceData, m interface{}

func resourceNsxtPolicyLBVirtualServerUpdate(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)
// NOTE: Partial patch is required to respect rules that might have
// been added manually
connector.AddRequestProcessor(newEnablePartialPatchHeaderProcessor())
client := infra.NewDefaultLbVirtualServersClient(connector)
if client == nil {
return policyResourceNotSupportedError()
Expand Down Expand Up @@ -567,6 +564,16 @@ func resourceNsxtPolicyLBVirtualServerUpdate(d *schema.ResourceData, m interface

policyLBVirtualServerVersionDepenantSet(d, &obj)

// The user might have defined the rules outside terraform, lets keep these
existingObj, err := client.Get(id)
if err != nil {
return handleUpdateError("LBVirtualServer", id, err)
}

if len(existingObj.Rules) > 0 {
obj.Rules = existingObj.Rules
}

if maxNewConnectionRate > 0 {
obj.MaxNewConnectionRate = &maxNewConnectionRate
}
Expand All @@ -576,7 +583,7 @@ func resourceNsxtPolicyLBVirtualServerUpdate(d *schema.ResourceData, m interface
}

// Update the resource using PATCH
err := client.Patch(id, obj)
err = client.Patch(id, obj)
if err != nil {
return handleUpdateError("LBVirtualServer", id, err)
}
Expand Down

0 comments on commit 6d50c85

Please sign in to comment.