Skip to content

Commit

Permalink
Merge pull request #136 from citrix/new_resources
Browse files Browse the repository at this point in the history
New resources
  • Loading branch information
George Nikolopoulos authored Feb 16, 2021
2 parents f53a631 + bfd15f9 commit 8e6779a
Show file tree
Hide file tree
Showing 23 changed files with 2,540 additions and 77 deletions.
161 changes: 84 additions & 77 deletions citrixadc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,83 +78,90 @@ func providerSchema() map[string]*schema.Schema {

func providerResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"citrixadc_lbvserver": resourceCitrixAdcLbvserver(),
"citrixadc_service": resourceCitrixAdcService(),
"citrixadc_csvserver": resourceCitrixAdcCsvserver(),
"citrixadc_cspolicy": resourceCitrixAdcCspolicy(),
"citrixadc_csaction": resourceCitrixAdcCsaction(),
"citrixadc_sslaction": resourceCitrixAdcSslaction(),
"citrixadc_sslpolicy": resourceCitrixAdcSslpolicy(),
"citrixadc_sslcertkey": resourceCitrixAdcSslcertkey(),
"citrixadc_sslprofile": resourceCitrixAdcSslprofile(),
"citrixadc_sslparameter": resourceCitrixAdcSslparameter(),
"citrixadc_ssldhparam": resourceCitrixAdcSsldhparam(),
"citrixadc_sslcipher": resourceCitrixAdcSslcipher(),
"citrixadc_lbmonitor": resourceCitrixAdcLbmonitor(),
"citrixadc_servicegroup": resourceCitrixAdcServicegroup(),
"citrixadc_nsacl": resourceCitrixAdcNsacl(),
"citrixadc_nsacls": resourceCitrixAdcNsacls(),
"citrixadc_inat": resourceCitrixAdcInat(),
"citrixadc_rnat": resourceCitrixAdcRnats(),
"citrixadc_gslbsite": resourceCitrixAdcGslbsite(),
"citrixadc_gslbvserver": resourceCitrixAdcGslbvserver(),
"citrixadc_gslbservice": resourceCitrixAdcGslbservice(),
"citrixadc_server": resourceCitrixAdcServer(),
"citrixadc_responderaction": resourceCitrixAdcResponderaction(),
"citrixadc_responderpolicy": resourceCitrixAdcResponderpolicy(),
"citrixadc_responderpolicylabel": resourceCitrixAdcResponderpolicylabel(),
"citrixadc_rewriteaction": resourceCitrixAdcRewriteaction(),
"citrixadc_rewritepolicy": resourceCitrixAdcRewritepolicy(),
"citrixadc_rewritepolicylabel": resourceCitrixAdcRewritepolicylabel(),
"citrixadc_nsip": resourceCitrixAdcNsip(),
"citrixadc_nsip6": resourceCitrixAdcNsip6(),
"citrixadc_nsconfig_save": resourceCitrixAdcNsconfigSave(),
"citrixadc_nsconfig_clear": resourceCitrixAdcNsconfigClear(),
"citrixadc_nsconfig_update": resourceCitrixAdcNsconfigUpdate(),
"citrixadc_ipset": resourceCitrixAdcIpset(),
"citrixadc_route": resourceCitrixAdcRoute(),
"citrixadc_linkset": resourceCitrixAdcLinkset(),
"citrixadc_nsfeature": resourceCitrixAdcNsfeature(),
"citrixadc_systemuser": resourceCitrixAdcSystemuser(),
"citrixadc_systemgroup": resourceCitrixAdcSystemgroup(),
"citrixadc_systemcmdpolicy": resourceCitrixAdcSystemcmdpolicy(),
"citrixadc_interface": resourceCitrixAdcInterface(),
"citrixadc_nstcpprofile": resourceCitrixAdcNstcpprofile(),
"citrixadc_nshttpprofile": resourceCitrixAdcNshttpprofile(),
"citrixadc_nslicense": resourceCitrixAdcNslicense(),
"citrixadc_cluster": resourceCitrixAdcCluster(),
"citrixadc_clusterfiles_syncer": resourceCitrixAdcClusterfilesSyncer(),
"citrixadc_systemfile": resourceCitrixAdcSystemfile(),
"citrixadc_auditmessageaction": resourceCitrixAdcAuditmessageaction(),
"citrixadc_auditsyslogaction": resourceCitrixAdcAuditsyslogaction(),
"citrixadc_auditsyslogpolicy": resourceCitrixAdcAuditsyslogpolicy(),
"citrixadc_rebooter": resourceCitrixAdcRebooter(),
"citrixadc_installer": resourceCitrixAdcInstaller(),
"citrixadc_pinger": resourceCitrixAdcPinger(),
"citrixadc_nsrpcnode": resourceCitrixAdcNsrpcnode(),
"citrixadc_routerdynamicrouting": resourceCitrixAdcRouterdynamicrouting(),
"citrixadc_policyexpression": resourceCitrixAdcPolicyexpression(),
"citrixadc_systemextramgmtcpu": resourceCitrixAdcSystemextramgmtcpu(),
"citrixadc_netprofile": resourceCitrixAdcNetprofile(),
"citrixadc_servicegroup_lbmonitor_binding": resourceCitrixAdcServicegroup_lbmonitor_binding(),
"citrixadc_nsparam": resourceCitrixAdcNsparam(),
"citrixadc_sslvserver_sslpolicy_binding": resourceCitrixAdcSslvserver_sslpolicy_binding(),
"citrixadc_sslprofile_sslcipher_binding": resourceCitrixAdcSslprofile_sslcipher_binding(),
"citrixadc_policydataset": resourceCitrixAdcPolicydataset(),
"citrixadc_policydataset_value_binding": resourceCitrixAdcPolicydataset_value_binding(),
"citrixadc_password_resetter": resourceCitrixAdcPasswordResetter(),
"citrixadc_csvserver_cspolicy_binding": resourceCitrixAdcCsvserver_cspolicy_binding(),
"citrixadc_appfwprofile": resourceCitrixAdcAppfwprofile(),
"citrixadc_appfwpolicy": resourceCitrixAdcAppfwpolicy(),
"citrixadc_appfwfieldtype": resourceCitrixAdcAppfwfieldtype(),
"citrixadc_appfwpolicylabel": resourceCitrixAdcAppfwpolicylabel(),
"citrixadc_appfwjsoncontenttype": resourceCitrixAdcAppfwjsoncontenttype(),
"citrixadc_appfwxmlcontenttype": resourceCitrixAdcAppfwxmlcontenttype(),
"citrixadc_appfwprofile_starturl_binding": resourceCitrixAdcAppfwprofileStarturlBinding(),
"citrixadc_appfwprofile_denyurl_binding": resourceCitrixAdcAppfwprofileDenyurlBinding(),
"citrixadc_nslicenseserver": resourceCitrixAdcNslicenseserver(),
"citrixadc_nscapacity": resourceCitrixAdcNscapacity(),
"citrixadc_lbvserver_service_binding": resourceCitrixAdcLbvserver_service_binding(),
"citrixadc_lbvserver": resourceCitrixAdcLbvserver(),
"citrixadc_service": resourceCitrixAdcService(),
"citrixadc_csvserver": resourceCitrixAdcCsvserver(),
"citrixadc_cspolicy": resourceCitrixAdcCspolicy(),
"citrixadc_csaction": resourceCitrixAdcCsaction(),
"citrixadc_sslaction": resourceCitrixAdcSslaction(),
"citrixadc_sslpolicy": resourceCitrixAdcSslpolicy(),
"citrixadc_sslcertkey": resourceCitrixAdcSslcertkey(),
"citrixadc_sslprofile": resourceCitrixAdcSslprofile(),
"citrixadc_sslparameter": resourceCitrixAdcSslparameter(),
"citrixadc_ssldhparam": resourceCitrixAdcSsldhparam(),
"citrixadc_sslcipher": resourceCitrixAdcSslcipher(),
"citrixadc_lbmonitor": resourceCitrixAdcLbmonitor(),
"citrixadc_servicegroup": resourceCitrixAdcServicegroup(),
"citrixadc_nsacl": resourceCitrixAdcNsacl(),
"citrixadc_nsacls": resourceCitrixAdcNsacls(),
"citrixadc_inat": resourceCitrixAdcInat(),
"citrixadc_rnat": resourceCitrixAdcRnats(),
"citrixadc_gslbsite": resourceCitrixAdcGslbsite(),
"citrixadc_gslbvserver": resourceCitrixAdcGslbvserver(),
"citrixadc_gslbservice": resourceCitrixAdcGslbservice(),
"citrixadc_server": resourceCitrixAdcServer(),
"citrixadc_responderaction": resourceCitrixAdcResponderaction(),
"citrixadc_responderpolicy": resourceCitrixAdcResponderpolicy(),
"citrixadc_responderpolicylabel": resourceCitrixAdcResponderpolicylabel(),
"citrixadc_rewriteaction": resourceCitrixAdcRewriteaction(),
"citrixadc_rewritepolicy": resourceCitrixAdcRewritepolicy(),
"citrixadc_rewritepolicylabel": resourceCitrixAdcRewritepolicylabel(),
"citrixadc_nsip": resourceCitrixAdcNsip(),
"citrixadc_nsip6": resourceCitrixAdcNsip6(),
"citrixadc_nsconfig_save": resourceCitrixAdcNsconfigSave(),
"citrixadc_nsconfig_clear": resourceCitrixAdcNsconfigClear(),
"citrixadc_nsconfig_update": resourceCitrixAdcNsconfigUpdate(),
"citrixadc_ipset": resourceCitrixAdcIpset(),
"citrixadc_route": resourceCitrixAdcRoute(),
"citrixadc_linkset": resourceCitrixAdcLinkset(),
"citrixadc_nsfeature": resourceCitrixAdcNsfeature(),
"citrixadc_systemuser": resourceCitrixAdcSystemuser(),
"citrixadc_systemgroup": resourceCitrixAdcSystemgroup(),
"citrixadc_systemcmdpolicy": resourceCitrixAdcSystemcmdpolicy(),
"citrixadc_interface": resourceCitrixAdcInterface(),
"citrixadc_nstcpprofile": resourceCitrixAdcNstcpprofile(),
"citrixadc_nshttpprofile": resourceCitrixAdcNshttpprofile(),
"citrixadc_nslicense": resourceCitrixAdcNslicense(),
"citrixadc_cluster": resourceCitrixAdcCluster(),
"citrixadc_clusterfiles_syncer": resourceCitrixAdcClusterfilesSyncer(),
"citrixadc_systemfile": resourceCitrixAdcSystemfile(),
"citrixadc_auditmessageaction": resourceCitrixAdcAuditmessageaction(),
"citrixadc_auditsyslogaction": resourceCitrixAdcAuditsyslogaction(),
"citrixadc_auditsyslogpolicy": resourceCitrixAdcAuditsyslogpolicy(),
"citrixadc_rebooter": resourceCitrixAdcRebooter(),
"citrixadc_installer": resourceCitrixAdcInstaller(),
"citrixadc_pinger": resourceCitrixAdcPinger(),
"citrixadc_nsrpcnode": resourceCitrixAdcNsrpcnode(),
"citrixadc_routerdynamicrouting": resourceCitrixAdcRouterdynamicrouting(),
"citrixadc_policyexpression": resourceCitrixAdcPolicyexpression(),
"citrixadc_systemextramgmtcpu": resourceCitrixAdcSystemextramgmtcpu(),
"citrixadc_netprofile": resourceCitrixAdcNetprofile(),
"citrixadc_servicegroup_lbmonitor_binding": resourceCitrixAdcServicegroup_lbmonitor_binding(),
"citrixadc_nsparam": resourceCitrixAdcNsparam(),
"citrixadc_sslvserver_sslpolicy_binding": resourceCitrixAdcSslvserver_sslpolicy_binding(),
"citrixadc_sslprofile_sslcipher_binding": resourceCitrixAdcSslprofile_sslcipher_binding(),
"citrixadc_policydataset": resourceCitrixAdcPolicydataset(),
"citrixadc_policydataset_value_binding": resourceCitrixAdcPolicydataset_value_binding(),
"citrixadc_password_resetter": resourceCitrixAdcPasswordResetter(),
"citrixadc_csvserver_cspolicy_binding": resourceCitrixAdcCsvserver_cspolicy_binding(),
"citrixadc_appfwprofile": resourceCitrixAdcAppfwprofile(),
"citrixadc_appfwpolicy": resourceCitrixAdcAppfwpolicy(),
"citrixadc_appfwfieldtype": resourceCitrixAdcAppfwfieldtype(),
"citrixadc_appfwpolicylabel": resourceCitrixAdcAppfwpolicylabel(),
"citrixadc_appfwjsoncontenttype": resourceCitrixAdcAppfwjsoncontenttype(),
"citrixadc_appfwxmlcontenttype": resourceCitrixAdcAppfwxmlcontenttype(),
"citrixadc_appfwprofile_starturl_binding": resourceCitrixAdcAppfwprofileStarturlBinding(),
"citrixadc_appfwprofile_denyurl_binding": resourceCitrixAdcAppfwprofileDenyurlBinding(),
"citrixadc_nslicenseserver": resourceCitrixAdcNslicenseserver(),
"citrixadc_nscapacity": resourceCitrixAdcNscapacity(),
"citrixadc_lbvserver_service_binding": resourceCitrixAdcLbvserver_service_binding(),
"citrixadc_policystringmap": resourceCitrixAdcPolicystringmap(),
"citrixadc_policystringmap_pattern_binding": resourceCitrixAdcPolicystringmap_pattern_binding(),
"citrixadc_transformprofile": resourceCitrixAdcTransformprofile(),
"citrixadc_transformaction": resourceCitrixAdcTransformaction(),
"citrixadc_transformpolicy": resourceCitrixAdcTransformpolicy(),
"citrixadc_lbvserver_transformpolicy_binding": resourceCitrixAdcLbvserver_transformpolicy_binding(),
"citrixadc_csvserver_transformpolicy_binding": resourceCitrixAdcCsvserver_transformpolicy_binding(),
}
}

Expand Down
205 changes: 205 additions & 0 deletions citrixadc/resource_citrixadc_csvserver_transformpolicy_binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
package citrixadc

import (
"github.com/chiradeep/go-nitro/config/cs"

"github.com/chiradeep/go-nitro/netscaler"
"github.com/hashicorp/terraform/helper/schema"

"fmt"
"log"
"strings"
)

func resourceCitrixAdcCsvserver_transformpolicy_binding() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Create: createCsvserver_transformpolicy_bindingFunc,
Read: readCsvserver_transformpolicy_bindingFunc,
Delete: deleteCsvserver_transformpolicy_bindingFunc,
Schema: map[string]*schema.Schema{
"bindpoint": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"gotopriorityexpression": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"invoke": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
},
"labelname": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"labeltype": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"policyname": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"priority": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
},
"targetlbvserver": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
}
}

func createCsvserver_transformpolicy_bindingFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In createCsvserver_transformpolicy_bindingFunc")
client := meta.(*NetScalerNitroClient).client
name := d.Get("name").(string)
policyname := d.Get("policyname").(string)
bindingId := fmt.Sprintf("%s,%s", name, policyname)
csvserver_transformpolicy_binding := cs.Csvservertransformpolicybinding{
Bindpoint: d.Get("bindpoint").(string),
Gotopriorityexpression: d.Get("gotopriorityexpression").(string),
Invoke: d.Get("invoke").(bool),
Labelname: d.Get("labelname").(string),
Labeltype: d.Get("labeltype").(string),
Name: d.Get("name").(string),
Policyname: d.Get("policyname").(string),
Priority: d.Get("priority").(int),
Targetlbvserver: d.Get("targetlbvserver").(string),
}

err := client.UpdateUnnamedResource(netscaler.Csvserver_transformpolicy_binding.Type(), &csvserver_transformpolicy_binding)
if err != nil {
return err
}

d.SetId(bindingId)

err = readCsvserver_transformpolicy_bindingFunc(d, meta)
if err != nil {
log.Printf("[ERROR] netscaler-provider: ?? we just created this csvserver_transformpolicy_binding but we can't read it ?? %s", bindingId)
return nil
}
return nil
}

func readCsvserver_transformpolicy_bindingFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In readCsvserver_transformpolicy_bindingFunc")
client := meta.(*NetScalerNitroClient).client

bindingId := d.Id()
idSlice := strings.SplitN(bindingId, ",", 2)
name := idSlice[0]
policyname := idSlice[1]

log.Printf("[DEBUG] citrixadc-provider: Reading csvserver_transformpolicy_binding state %v", bindingId)

findParams := netscaler.FindParams{
ResourceType: "csvserver_transformpolicy_binding",
ResourceName: name,
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 csvserver_transformpolicy_binding state %s", bindingId)
d.SetId("")
return nil
}

// Iterate through results to find the one with the right policy name
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 monitor name not found in array")
log.Printf("[WARN] citrixadc-provider: Clearing csvserver_transformpolicy_binding state %s", bindingId)
d.SetId("")
return nil
}
// Fallthrough

data := dataArr[foundIndex]

d.Set("name", data["name"])
d.Set("bindpoint", data["bindpoint"])
d.Set("gotopriorityexpression", data["gotopriorityexpression"])
d.Set("invoke", data["invoke"])
d.Set("labelname", data["labelname"])
d.Set("labeltype", data["labeltype"])
d.Set("name", data["name"])
d.Set("policyname", data["policyname"])
d.Set("priority", data["priority"])
d.Set("targetlbvserver", data["targetlbvserver"])

return nil

}

func deleteCsvserver_transformpolicy_bindingFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteCsvserver_transformpolicy_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", policyname))

if bindpoint, ok := d.GetOk("bindpoint"); ok {
args = append(args, fmt.Sprintf("bindpoint:%v", bindpoint))
}

if priority, ok := d.GetOk("priority"); ok {
args = append(args, fmt.Sprintf("priority:%v", priority))
}

err := client.DeleteResourceWithArgs("csvserver_transformpolicy_binding", name, args)
if err != nil {
return err
}
d.SetId("")

return nil
}
Loading

0 comments on commit 8e6779a

Please sign in to comment.