-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1210 from citrix/systemgroup_systemcmdpolicy_bind…
…ing-and-systemgroup_systemuser_binding Added systemgroup_systemcmdpolicy_binding and systemgroup_systemuser_…
- Loading branch information
Showing
9 changed files
with
850 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
citrixadc/resource_citrixadc_systemgroup_systemcmdpolicy_binding.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package citrixadc | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/citrix/adc-nitro-go/resource/config/system" | ||
"github.com/citrix/adc-nitro-go/service" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
|
||
"fmt" | ||
"log" | ||
"strings" | ||
) | ||
|
||
func resourceCitrixAdcSystemgroup_systemcmdpolicy_binding() *schema.Resource { | ||
return &schema.Resource{ | ||
SchemaVersion: 1, | ||
Create: createSystemgroup_systemcmdpolicy_bindingFunc, | ||
Read: readSystemgroup_systemcmdpolicy_bindingFunc, | ||
Delete: deleteSystemgroup_systemcmdpolicy_bindingFunc, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"groupname": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"policyname": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"priority": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func createSystemgroup_systemcmdpolicy_bindingFunc(d *schema.ResourceData, meta interface{}) error { | ||
log.Printf("[DEBUG] citrixadc-provider: In createSystemgroup_systemcmdpolicy_bindingFunc") | ||
client := meta.(*NetScalerNitroClient).client | ||
groupname := d.Get("groupname") | ||
policyname := d.Get("policyname") | ||
bindingId := fmt.Sprintf("%s,%s", groupname, policyname) | ||
systemgroup_systemcmdpolicy_binding := system.Systemgroupsystemcmdpolicybinding{ | ||
Groupname: d.Get("groupname").(string), | ||
Policyname: d.Get("policyname").(string), | ||
Priority: d.Get("priority").(int), | ||
} | ||
|
||
_, err := client.AddResource(service.Systemgroup_systemcmdpolicy_binding.Type(), bindingId, &systemgroup_systemcmdpolicy_binding) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(bindingId) | ||
|
||
err = readSystemgroup_systemcmdpolicy_bindingFunc(d, meta) | ||
if err != nil { | ||
log.Printf("[ERROR] netscaler-provider: ?? we just created this systemgroup_systemcmdpolicy_binding but we can't read it ?? %s", bindingId) | ||
return nil | ||
} | ||
return nil | ||
} | ||
|
||
func readSystemgroup_systemcmdpolicy_bindingFunc(d *schema.ResourceData, meta interface{}) error { | ||
log.Printf("[DEBUG] citrixadc-provider: In readSystemgroup_systemcmdpolicy_bindingFunc") | ||
client := meta.(*NetScalerNitroClient).client | ||
bindingId := d.Id() | ||
idSlice := strings.SplitN(bindingId, ",", 2) | ||
|
||
groupname := idSlice[0] | ||
policyname := idSlice[1] | ||
|
||
log.Printf("[DEBUG] citrixadc-provider: Reading systemgroup_systemcmdpolicy_binding state %s", bindingId) | ||
|
||
findParams := service.FindParams{ | ||
ResourceType: "systemgroup_systemcmdpolicy_binding", | ||
ResourceName: groupname, | ||
ResourceMissingErrorCode: 258, | ||
} | ||
dataArr, err := client.FindResourceArrayWithParams(findParams) | ||
|
||
// Unexpected error | ||
if err != nil { | ||
log.Printf("[DEBUG] citrixadc-provider: Error during FindResourceArrayWithParams %s", err.Error()) | ||
return err | ||
} | ||
|
||
// Resource is missing | ||
if len(dataArr) == 0 { | ||
log.Printf("[DEBUG] citrixadc-provider: FindResourceArrayWithParams returned empty array") | ||
log.Printf("[WARN] citrixadc-provider: Clearing systemgroup_systemcmdpolicy_binding state %s", bindingId) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
// Iterate through results to find the one with the right id | ||
foundIndex := -1 | ||
for i, v := range dataArr { | ||
if v["policyname"].(string) == policyname { | ||
foundIndex = i | ||
break | ||
} | ||
} | ||
|
||
// Resource is missing | ||
if foundIndex == -1 { | ||
log.Printf("[DEBUG] citrixadc-provider: FindResourceArrayWithParams secondIdComponent not found in array") | ||
log.Printf("[WARN] citrixadc-provider: Clearing systemgroup_systemcmdpolicy_binding state %s", bindingId) | ||
d.SetId("") | ||
return nil | ||
} | ||
// Fallthrough | ||
|
||
data := dataArr[foundIndex] | ||
|
||
d.Set("groupname", data["groupname"]) | ||
d.Set("policyname", data["policyname"]) | ||
setToInt("priority", d, data["priority"]) | ||
|
||
return nil | ||
|
||
} | ||
|
||
func deleteSystemgroup_systemcmdpolicy_bindingFunc(d *schema.ResourceData, meta interface{}) error { | ||
log.Printf("[DEBUG] citrixadc-provider: In deleteSystemgroup_systemcmdpolicy_bindingFunc") | ||
client := meta.(*NetScalerNitroClient).client | ||
|
||
bindingId := d.Id() | ||
idSlice := strings.SplitN(bindingId, ",", 2) | ||
|
||
name := idSlice[0] | ||
policyname := idSlice[1] | ||
|
||
args := make([]string, 0) | ||
args = append(args, fmt.Sprintf("policyname:%s", url.QueryEscape(policyname))) | ||
|
||
err := client.DeleteResourceWithArgs(service.Systemgroup_systemcmdpolicy_binding.Type(), name, args) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId("") | ||
|
||
return nil | ||
} |
Oops, something went wrong.