diff --git a/nsxt/resource_nsxt_policy_distributed_flood_protection_profile_binding.go b/nsxt/resource_nsxt_policy_distributed_flood_protection_profile_binding.go index 0eaee9972..04fd1a3b8 100644 --- a/nsxt/resource_nsxt_policy_distributed_flood_protection_profile_binding.go +++ b/nsxt/resource_nsxt_policy_distributed_flood_protection_profile_binding.go @@ -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" @@ -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) } diff --git a/nsxt/resource_nsxt_policy_distributed_flood_protection_profile_binding_test.go b/nsxt/resource_nsxt_policy_distributed_flood_protection_profile_binding_test.go index de70dc807..9ec987acf 100644 --- a/nsxt/resource_nsxt_policy_distributed_flood_protection_profile_binding_test.go +++ b/nsxt/resource_nsxt_policy_distributed_flood_protection_profile_binding_test.go @@ -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 { diff --git a/nsxt/resource_nsxt_policy_gateway_flood_protection_profile_binding.go b/nsxt/resource_nsxt_policy_gateway_flood_protection_profile_binding.go index fd00c4377..c898fb998 100644 --- a/nsxt/resource_nsxt_policy_gateway_flood_protection_profile_binding.go +++ b/nsxt/resource_nsxt_policy_gateway_flood_protection_profile_binding.go @@ -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) @@ -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 @@ -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) } @@ -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) }