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

Alternative fix for preserving LB VS rules #482

Merged
merged 1 commit into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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