Skip to content

Commit

Permalink
Merge pull request #1044 from citrix/711_vpnvserver_appflowpolicy_bin…
Browse files Browse the repository at this point in the history
…ding

**BUG FIXES** vpnvserver appflowpolicy binding: Updated Id of the resource and Updated read operation to make it backward compatible.
  • Loading branch information
sumanth-lingappa authored May 26, 2023
2 parents 97182ce + bc1d0f4 commit 193a59e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BUG FIXES

* **citrixadc_ntpsync**: Updated create operation to call appropriate API call.
* **citrixadc_appfwprofile**: Updated the read function to not to set values for some attributes that are not recieved from the NetScaler.
* **citrixadc_vpnvserver_appflowpolicy_binding**: Updated Id of the resource and Updated read operation to make it backward compatible.

ENHANCEMENTS

Expand Down
33 changes: 24 additions & 9 deletions citrixadc/resource_citrixadc_vpnvserver_appflowpolicy_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down Expand Up @@ -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",
Expand All @@ -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
}
Expand All @@ -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",
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions docs/resources/vpnvserver_appflowpolicy_binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -41,13 +41,13 @@ 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

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
```

0 comments on commit 193a59e

Please sign in to comment.