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

Support revision in flood protection binding #1184

Merged
merged 1 commit into from
Apr 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ package nsxt
import (
"fmt"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/terraform-provider-nsxt/api/infra/domains/groups"
utl "github.com/vmware/terraform-provider-nsxt/api/utl"
Expand Down Expand Up @@ -77,31 +75,8 @@ func resourceNsxtPolicyDistributedFloodProtectionProfileBindingPatch(d *schema.R
domain := getDomainFromResourcePath(groupPath)

if !isCreate {
// Regular API doesn't support UPDATE operation, response example below:
// Cannot create an object with path=[/infra/domains/default/groups/testgroup/firewall-flood-protection-profile-binding-maps/994019f3-aba0-4592-96ff-f00326e13976] as it already exists. (code 500127)
// Instead of using H-API to increase complexity, we choose to delete and then create the resource for UPDATE.
err := bindingClient.Delete(domain, groupID, id)
if err != nil {
return err
}
stateConf := &resource.StateChangeConf{
Pending: []string{"exist"},
Target: []string{"deleted"},
Refresh: func() (interface{}, string, error) {
state, err := bindingClient.Get(domain, groupID, id)
if isNotFoundError(err) {
return state, "deleted", nil
}
return state, "exist", nil
},
Timeout: 30 * time.Second,
PollInterval: 200 * time.Millisecond,
Delay: 200 * time.Millisecond,
}
_, err = stateConf.WaitForState()
if err != nil {
return fmt.Errorf("failed to update GatewayFloodProtectionProfileBinding %s: %v", id, err)
}
revision := int64(d.Get("revision").(int))
obj.Revision = &revision
}
return bindingClient.Patch(domain, groupID, id, obj)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func testAccResourceNsxtPolicyDistributedFloodProtectionProfileBindingBasic(t *t
name := getAccTestResourceName()
updatedName := fmt.Sprintf("%s-updated", name)

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: preCheck,
Providers: testAccProviders,
CheckDestroy: func(state *terraform.State) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func extractGatewayIDLocaleServiceID(parentPath string) (string, string, string,
return tier0ID, tier1ID, localeServiceID, nil
}

func resourceNsxtPolicyGatewayFloodProtectionProfileBindingPatch(d *schema.ResourceData, m interface{}, parentPath string, id string) error {
func resourceNsxtPolicyGatewayFloodProtectionProfileBindingPatch(d *schema.ResourceData, m interface{}, parentPath string, id string, isCreate bool) error {
connector := getPolicyConnector(m)

displayName := d.Get("display_name").(string)
Expand All @@ -86,6 +86,11 @@ func resourceNsxtPolicyGatewayFloodProtectionProfileBindingPatch(d *schema.Resou
ProfilePath: &profilePath,
}

if !isCreate {
revision := int64(d.Get("revision").(int))
obj.Revision = &revision
}

tier0ID, tier1ID, localeServiceID, err := extractGatewayIDLocaleServiceID(parentPath)
if err != nil {
return err
Expand Down Expand Up @@ -169,7 +174,7 @@ func resourceNsxtPolicyGatewayFloodProtectionProfileBindingCreate(d *schema.Reso
return fmt.Errorf("Resource with id %s already exists", id)
}

err = resourceNsxtPolicyGatewayFloodProtectionProfileBindingPatch(d, m, parentPath, id)
err = resourceNsxtPolicyGatewayFloodProtectionProfileBindingPatch(d, m, parentPath, id, true)
if err != nil {
return handleCreateError("GatewayFloodProtectionProfile", id, err)
}
Expand Down Expand Up @@ -220,7 +225,7 @@ func resourceNsxtPolicyGatewayFloodProtectionProfileBindingUpdate(d *schema.Reso

parentPath := d.Get("parent_path").(string)

err := resourceNsxtPolicyGatewayFloodProtectionProfileBindingPatch(d, m, parentPath, id)
err := resourceNsxtPolicyGatewayFloodProtectionProfileBindingPatch(d, m, parentPath, id, false)
if err != nil {
return handleUpdateError("GatewayFloodProtectionProfileBinding", id, err)
}
Expand Down
Loading