From 04d62b0b77cab363d83e519670979bfc83a2c3aa Mon Sep 17 00:00:00 2001 From: Rohit Myali Date: Mon, 15 May 2023 02:26:54 -0700 Subject: [PATCH 1/2] Updated Id of the resource and made it backward compatible Signed-off-by: Rohit Myali --- ...rixadc_vpnvserver_appflowpolicy_binding.go | 33 ++++++++++++++----- ...c_vpnvserver_appflowpolicy_binding_test.go | 12 ++++--- .../vpnvserver_appflowpolicy_binding.md | 6 ++-- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/citrixadc/resource_citrixadc_vpnvserver_appflowpolicy_binding.go b/citrixadc/resource_citrixadc_vpnvserver_appflowpolicy_binding.go index 6c007507e..fdc5fb9c4 100644 --- a/citrixadc/resource_citrixadc_vpnvserver_appflowpolicy_binding.go +++ b/citrixadc/resource_citrixadc_vpnvserver_appflowpolicy_binding.go @@ -35,8 +35,8 @@ func resourceCitrixAdcVpnvserver_appflowpolicy_binding() *schema.Resource { }, "bindpoint": &schema.Schema{ Type: schema.TypeString, - Optional: true, - Computed: true, + Required: true, + Computed: false, ForceNew: true, }, "gotopriorityexpression": &schema.Schema{ @@ -72,7 +72,8 @@ func createVpnvserver_appflowpolicy_bindingFunc(d *schema.ResourceData, meta int client := meta.(*NetScalerNitroClient).client name := d.Get("name") policy := d.Get("policy") - bindingId := fmt.Sprintf("%s,%s", name, policy) + bindpoint := d.Get("bindpoint") + bindingId := fmt.Sprintf("%s,%s,%s", name, policy, bindpoint) vpnvserver_appflowpolicy_binding := vpn.Vpnvserverappflowpolicybinding{ Bindpoint: d.Get("bindpoint").(string), Gotopriorityexpression: d.Get("gotopriorityexpression").(string), @@ -102,10 +103,25 @@ func readVpnvserver_appflowpolicy_bindingFunc(d *schema.ResourceData, meta inter log.Printf("[DEBUG] citrixadc-provider: In readVpnvserver_appflowpolicy_bindingFunc") client := meta.(*NetScalerNitroClient).client bindingId := d.Id() - idSlice := strings.SplitN(bindingId, ",", 2) + + // To make the resource backward compatible, in the prev state file user will have ID with 2 values, but we have updated Id. So here we are changing the code to make it backward compatible + // here we are checking for id, if it has 2 elements then we are appending the 3rd attribute to the old Id. + oldIdSlice := strings.Split(bindingId, ",") + + if len(oldIdSlice) == 2 { + if _, ok := d.GetOk("bindpoint") ; ok { + bindingId = bindingId + "," + d.Get("bindpoint").(string) + } else { + return fmt.Errorf("bindpoint should be given, as it is the part of Id. The id of the vpnvserver_appflowpolicy_binding is the concatenation of the `name`, `policy` and `bindpoint` attributes separated by a comma") + } + d.SetId(bindingId) + } + + idSlice := strings.SplitN(bindingId, ",", 3) name := idSlice[0] policy := idSlice[1] + bindpoint := idSlice[2] log.Printf("[DEBUG] citrixadc-provider: Reading vpnvserver_appflowpolicy_binding state %s", bindingId) @@ -133,7 +149,7 @@ func readVpnvserver_appflowpolicy_bindingFunc(d *schema.ResourceData, meta inter // Iterate through results to find the one with the right id foundIndex := -1 for i, v := range dataArr { - if v["policy"].(string) == policy { + if v["policy"].(string) == policy && v["bindpoint"].(string) == bindpoint { foundIndex = i break } @@ -167,22 +183,21 @@ func deleteVpnvserver_appflowpolicy_bindingFunc(d *schema.ResourceData, meta int client := meta.(*NetScalerNitroClient).client bindingId := d.Id() - idSlice := strings.SplitN(bindingId, ",", 2) + idSlice := strings.SplitN(bindingId, ",", 3) name := idSlice[0] policy := idSlice[1] + bindpoint := idSlice[2] args := make([]string, 0) args = append(args, fmt.Sprintf("policy:%s", policy)) + args = append(args, fmt.Sprintf("bindpoint:%s", bindpoint)) if val, ok := d.GetOk("secondary"); ok { args = append(args, fmt.Sprintf("secondary:%s", url.QueryEscape(val.(string)))) } if val, ok := d.GetOk("groupextraction"); ok { args = append(args, fmt.Sprintf("groupextraction:%s", url.QueryEscape(val.(string)))) } - if val, ok := d.GetOk("bindpoint"); ok { - args = append(args, fmt.Sprintf("bindpoint:%s", url.QueryEscape(val.(string)))) - } err := client.DeleteResourceWithArgs(service.Vpnvserver_appflowpolicy_binding.Type(), name, args) if err != nil { diff --git a/citrixadc/resource_citrixadc_vpnvserver_appflowpolicy_binding_test.go b/citrixadc/resource_citrixadc_vpnvserver_appflowpolicy_binding_test.go index e6f60097f..d94594959 100644 --- a/citrixadc/resource_citrixadc_vpnvserver_appflowpolicy_binding_test.go +++ b/citrixadc/resource_citrixadc_vpnvserver_appflowpolicy_binding_test.go @@ -74,7 +74,7 @@ func TestAccVpnvserver_appflowpolicy_binding_basic(t *testing.T) { resource.TestStep{ Config: testAccVpnvserver_appflowpolicy_binding_basic_step2, Check: resource.ComposeTestCheckFunc( - testAccCheckVpnvserver_appflowpolicy_bindingNotExist("citrixadc_vpnvserver_appflowpolicy_binding.tf_bind", "tf_vpnvserver,tf_appflowpolicy"), + testAccCheckVpnvserver_appflowpolicy_bindingNotExist("citrixadc_vpnvserver_appflowpolicy_binding.tf_bind", "tf_vpnvserver,tf_appflowpolicy,ICA_REQUEST"), ), }, }, @@ -104,10 +104,11 @@ func testAccCheckVpnvserver_appflowpolicy_bindingExist(n string, id *string) res bindingId := rs.Primary.ID - idSlice := strings.SplitN(bindingId, ",", 2) + idSlice := strings.SplitN(bindingId, ",", 3) name := idSlice[0] policy := idSlice[1] + bindpoint := idSlice[2] findParams := service.FindParams{ ResourceType: "vpnvserver_appflowpolicy_binding", @@ -124,7 +125,7 @@ func testAccCheckVpnvserver_appflowpolicy_bindingExist(n string, id *string) res // Iterate through results to find the one with the matching secondIdComponent found := false for _, v := range dataArr { - if v["policy"].(string) == policy { + if v["policy"].(string) == policy && v["bindpoint"].(string) == bindpoint { found = true break } @@ -145,10 +146,11 @@ func testAccCheckVpnvserver_appflowpolicy_bindingNotExist(n string, id string) r if !strings.Contains(id, ",") { return fmt.Errorf("Invalid id string %v. The id string must contain a comma.", id) } - idSlice := strings.SplitN(id, ",", 2) + idSlice := strings.SplitN(id, ",", 3) name := idSlice[0] policy := idSlice[1] + bindpoint := idSlice[2] findParams := service.FindParams{ ResourceType: "vpnvserver_appflowpolicy_binding", @@ -165,7 +167,7 @@ func testAccCheckVpnvserver_appflowpolicy_bindingNotExist(n string, id string) r // Iterate through results to hopefully not find the one with the matching secondIdComponent found := false for _, v := range dataArr { - if v["policy"].(string) == policy { + if v["policy"].(string) == policy && v["bindpoint"].(string) == bindpoint { found = true break } diff --git a/docs/resources/vpnvserver_appflowpolicy_binding.md b/docs/resources/vpnvserver_appflowpolicy_binding.md index ac0d70058..4d894bc9c 100644 --- a/docs/resources/vpnvserver_appflowpolicy_binding.md +++ b/docs/resources/vpnvserver_appflowpolicy_binding.md @@ -30,7 +30,7 @@ resource "citrixadc_vpnvserver_appflowpolicy_binding" "tf_bind" { * `name` - (Required) Name of the virtual server. * `policy` - (Required) The name of the policy, if any, bound to the VPN virtual server. -* `bindpoint` - (Optional) Bindpoint to which the policy is bound. +* `bindpoint` - (Required) Bindpoint to which the policy is bound. * `gotopriorityexpression` - (Optional) Next priority expression. * `groupextraction` - (Optional) Binds the authentication policy to a tertiary chain which will be used only for group extraction. The user will not authenticate against this server, and this will only be called if primary and/or secondary authentication has succeeded. * `priority` - (Optional) Integer specifying the policy's priority. The lower the number, the higher the priority. Policies are evaluated in the order of their priority numbers. Maximum value for default syntax policies is 2147483647 and for classic policies is 64000. @@ -41,7 +41,7 @@ resource "citrixadc_vpnvserver_appflowpolicy_binding" "tf_bind" { In addition to the arguments, the following attributes are available: -* `id` - The id of the vpnvserver_appflowpolicy_binding. t is the concatenation of the `name` and `policy` attributes separated by a comma. +* `id` - The id of the vpnvserver_appflowpolicy_binding. It is the concatenation of the `name`, `policy` and `bindpoint` attributes separated by a comma. ## Import @@ -49,5 +49,5 @@ In addition to the arguments, the following attributes are available: A vpnvserver_appflowpolicy_binding can be imported using its id, e.g. ```shell -terraform import citrixadc_vpnvserver_appflowpolicy_binding.tf_bind tf_vpnvserver,tf_appflowpolicy +terraform import citrixadc_vpnvserver_appflowpolicy_binding.tf_bind tf_vpnvserver,tf_appflowpolicy,ICA_REQUEST ``` From e1f30c78cfe5df3be04df4dd984a8d7c24aed07b Mon Sep 17 00:00:00 2001 From: Rohit Myali Date: Mon, 15 May 2023 02:29:18 -0700 Subject: [PATCH 2/2] Updated changelog for vpnvserver_appflowpolicy_binding resource Signed-off-by: Rohit Myali --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b95fd5da..6e1f9e7f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.35.0 (May 15, 2023) + +BUG FIXES + +* **citrixadc_vpnvserver_appflowpolicy_binding**: Updated Id of the resource and Updated read operation to make it backward compatible. + ## 1.34.0 (May 05, 2023) FEATURES