diff --git a/citrixadc/provider.go b/citrixadc/provider.go index a08a6738d..335f44098 100644 --- a/citrixadc/provider.go +++ b/citrixadc/provider.go @@ -78,90 +78,92 @@ 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_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(), + "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(), + "citrixadc_sslvserver_sslcertkey_binding": resourceCitrixAdcSslvserver_sslcertkey_binding(), + "citrixadc_servicegroup_servicegroupmember_binding": resourceCitrixAdcServicegroup_servicegroupmember_binding(), } } diff --git a/citrixadc/resource_citrixadc_csvserver.go b/citrixadc/resource_citrixadc_csvserver.go index 10fff8a61..8c967d17c 100644 --- a/citrixadc/resource_citrixadc_csvserver.go +++ b/citrixadc/resource_citrixadc_csvserver.go @@ -696,8 +696,12 @@ func readCsvserverFunc(d *schema.ResourceData, meta interface{}) error { d.Set("ttl", data["ttl"]) d.Set("vipheader", data["vipheader"]) - if err := readSslcerts(d, meta, csvserverName); err != nil { - return err + _, sslok := d.GetOk("sslcertkey") + _, sniok := d.GetOk("snisslcertkeys") + if sslok || sniok { + if err := readSslcerts(d, meta, csvserverName); err != nil { + return err + } } if err := readSslpolicyBindings(d, meta, csvserverName); err != nil { diff --git a/citrixadc/resource_citrixadc_lbvserver.go b/citrixadc/resource_citrixadc_lbvserver.go index 4c5875e52..aefd2800a 100644 --- a/citrixadc/resource_citrixadc_lbvserver.go +++ b/citrixadc/resource_citrixadc_lbvserver.go @@ -890,8 +890,12 @@ func readLbvserverFunc(d *schema.ResourceData, meta interface{}) error { d.Set("vipheader", data["vipheader"]) d.Set("weight", data["weight"]) - if err := readSslcerts(d, meta, lbvserverName); err != nil { - return err + _, sslok := d.GetOk("sslcertkey") + _, sniok := d.GetOk("snisslcertkeys") + if sslok || sniok { + if err := readSslcerts(d, meta, lbvserverName); err != nil { + return err + } } if err := readSslpolicyBindings(d, meta, lbvserverName); err != nil { diff --git a/citrixadc/resource_citrixadc_servicegroup.go b/citrixadc/resource_citrixadc_servicegroup.go index 910343399..4ff851040 100644 --- a/citrixadc/resource_citrixadc_servicegroup.go +++ b/citrixadc/resource_citrixadc_servicegroup.go @@ -658,26 +658,30 @@ func readServicegroupFunc(d *schema.ResourceData, meta interface{}) error { d.Set("usip", data["usip"]) d.Set("weight", data["weight"]) - //boundMembers is of type []map[string]interface{} - servicegroupMembers := make([]string, 0, len(boundMembers)) - servicegroupMembersByServername := make([]string, 0, len(boundMembers)) - for _, member := range boundMembers { - ip := member["ip"].(string) - servername := member["servername"].(string) - port := member["port"].(float64) //TODO: why is this not int? - weight := member["weight"].(string) - // Heuristic rule - var strmember string - if servername == ip { - strmember = fmt.Sprintf("%s:%.0f:%s", ip, port, weight) - servicegroupMembers = append(servicegroupMembers, strmember) - } else { - strmember = fmt.Sprintf("%s:%.0f:%s", servername, port, weight) - servicegroupMembersByServername = append(servicegroupMembersByServername, strmember) + _, membersOk := d.GetOk("servicegroupmembers") + _, membersByNameOk := d.GetOk("servicegroupmembers_by_servername") + if membersOk || membersByNameOk { + //boundMembers is of type []map[string]interface{} + servicegroupMembers := make([]string, 0, len(boundMembers)) + servicegroupMembersByServername := make([]string, 0, len(boundMembers)) + for _, member := range boundMembers { + ip := member["ip"].(string) + servername := member["servername"].(string) + port := member["port"].(float64) //TODO: why is this not int? + weight := member["weight"].(string) + // Heuristic rule + var strmember string + if servername == ip { + strmember = fmt.Sprintf("%s:%.0f:%s", ip, port, weight) + servicegroupMembers = append(servicegroupMembers, strmember) + } else { + strmember = fmt.Sprintf("%s:%.0f:%s", servername, port, weight) + servicegroupMembersByServername = append(servicegroupMembersByServername, strmember) + } } + d.Set("servicegroupmembers", servicegroupMembers) + d.Set("servicegroupmembers_by_servername", servicegroupMembersByServername) } - d.Set("servicegroupmembers", servicegroupMembers) - d.Set("servicegroupmembers_by_servername", servicegroupMembersByServername) //vserverBindings is of type []map[string]interface{} var boundVserver string diff --git a/citrixadc/resource_citrixadc_servicegroup_servicegroupmember_binding.go b/citrixadc/resource_citrixadc_servicegroup_servicegroupmember_binding.go new file mode 100644 index 000000000..086131a67 --- /dev/null +++ b/citrixadc/resource_citrixadc_servicegroup_servicegroupmember_binding.go @@ -0,0 +1,273 @@ +package citrixadc + +import ( + "github.com/chiradeep/go-nitro/config/basic" + + "github.com/chiradeep/go-nitro/netscaler" + "github.com/hashicorp/terraform/helper/schema" + + "fmt" + "log" + "strconv" + "strings" +) + +func resourceCitrixAdcServicegroup_servicegroupmember_binding() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + Create: createServicegroup_servicegroupmember_bindingFunc, + Read: readServicegroup_servicegroupmember_bindingFunc, + Delete: deleteServicegroup_servicegroupmember_bindingFunc, + Schema: map[string]*schema.Schema{ + "customserverid": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "dbsttl": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Computed: true, + ForceNew: true, + }, + "hashid": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Computed: true, + ForceNew: true, + }, + "ip": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"servername"}, + }, + "nameserver": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "port": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Computed: true, + ForceNew: true, + }, + "serverid": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Computed: true, + ForceNew: true, + }, + "servername": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"ip"}, + }, + "servicegroupname": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "state": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "weight": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + } +} + +func createServicegroup_servicegroupmember_bindingFunc(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] citrixadc-provider: In createServicegroup_servicegroupmember_bindingFunc") + client := meta.(*NetScalerNitroClient).client + bindingIdSlice := make([]string, 0, 3) + + bindingIdSlice = append(bindingIdSlice, d.Get("servicegroupname").(string)) + + // Second id component will either be servername or ip + // ConflictsWith restriction ensures that only one of them is defined + if v, ok := d.GetOk("servername"); ok { + bindingIdSlice = append(bindingIdSlice, v.(string)) + } + if v, ok := d.GetOk("ip"); ok { + bindingIdSlice = append(bindingIdSlice, v.(string)) + } + + // Third component will be the port if defined + if v, ok := d.GetOk("port"); ok { + val := strconv.Itoa(v.(int)) + bindingIdSlice = append(bindingIdSlice, val) + } + + bindingId := strings.Join(bindingIdSlice, ",") + + servicegroup_servicegroupmember_binding := basic.Servicegroupservicegroupmemberbinding{ + Customserverid: d.Get("customserverid").(string), + Dbsttl: d.Get("dbsttl").(int), + Hashid: d.Get("hashid").(int), + Ip: d.Get("ip").(string), + Nameserver: d.Get("nameserver").(string), + Port: d.Get("port").(int), + Serverid: d.Get("serverid").(int), + Servername: d.Get("servername").(string), + Servicegroupname: d.Get("servicegroupname").(string), + State: d.Get("state").(string), + Weight: d.Get("weight").(int), + } + + err := client.UpdateUnnamedResource(netscaler.Servicegroup_servicegroupmember_binding.Type(), &servicegroup_servicegroupmember_binding) + if err != nil { + return err + } + + d.SetId(bindingId) + + err = readServicegroup_servicegroupmember_bindingFunc(d, meta) + if err != nil { + log.Printf("[ERROR] netscaler-provider: ?? we just created this servicegroup_servicegroupmember_binding but we can't read it ?? %s", bindingId) + return nil + } + return nil +} + +func readServicegroup_servicegroupmember_bindingFunc(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] citrixadc-provider: In readServicegroup_servicegroupmember_bindingFunc") + client := meta.(*NetScalerNitroClient).client + + bindingId := d.Id() + idSlice := strings.SplitN(bindingId, ",", 3) + servicegroupname := idSlice[0] + + // When ip is defined ADC will create a server with name equal to the ip address + // So no matter what the user actually defined servername will always be valid search criterion + servername := idSlice[1] + + // Port is optional + // Need to check if it actually exists + port := 0 + var err error + if len(idSlice) == 3 { + if port, err = strconv.Atoi(idSlice[2]); err != nil { + return err + } + } + + log.Printf("[DEBUG] citrixadc-provider: Reading servicegroup_servicegroupmember_binding state %v", bindingId) + + findParams := netscaler.FindParams{ + ResourceType: "servicegroup_servicegroupmember_binding", + ResourceName: servicegroupname, + ResourceMissingErrorCode: 258, + } + dataArr, err := client.FindResourceArrayWithParams(findParams) + log.Printf("[DEBUG] citrixadc-provider: dataArr: %v", dataArr) + // 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 servicegroup_servicegroupmember_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 port != 0 { + portEqual := int(v["port"].(float64)) == port + servernameEqual := v["servername"] == servername + if servernameEqual && portEqual { + foundIndex = i + break + } + } else { + log.Printf("[WARN] citrixadc-provider: port is zero") + if v["servername"].(string) == servername { + foundIndex = i + break + } + } + } + log.Printf("[WARN] citrixadc-provider: foundIndex: %v", foundIndex) + + // Resource is missing + if foundIndex == -1 { + log.Printf("[DEBUG] citrixadc-provider: FindResourceArrayWithParams monitor name not found in array") + log.Printf("[WARN] citrixadc-provider: Clearing servicegroup_servicegroupmember_binding state %s", bindingId) + d.SetId("") + return nil + } + // Fallthrough + + data := dataArr[foundIndex] + + d.Set("customserverid", data["customserverid"]) + d.Set("dbsttl", data["dbsttl"]) + d.Set("hashid", data["hashid"]) + d.Set("ip", data["ip"]) + d.Set("nameserver", data["nameserver"]) + d.Set("port", data["port"]) + d.Set("serverid", data["serverid"]) + d.Set("servername", data["servername"]) + d.Set("servicegroupname", data["servicegroupname"]) + d.Set("state", data["state"]) + d.Set("weight", data["weight"]) + + return nil + +} + +func deleteServicegroup_servicegroupmember_bindingFunc(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] citrixadc-provider: In deleteServicegroup_servicegroupmember_bindingFunc") + client := meta.(*NetScalerNitroClient).client + + bindingId := d.Id() + idSlice := strings.SplitN(bindingId, ",", 3) + servicegroupname := idSlice[0] + servername := idSlice[1] + port := 0 + var err error + if len(idSlice) == 3 { + if port, err = strconv.Atoi(idSlice[2]); err != nil { + return err + } + } + args := make([]string, 0, 3) + + // When ip is defined ADC will create a server with name equal to the ip address + // So no matter what the user actually defined servername will always be valid search criterion + args = append(args, fmt.Sprintf("servername:%s", servername)) + + // Port is optional + if port != 0 { + args = append(args, fmt.Sprintf("port:%v", port)) + } + + err = client.DeleteResourceWithArgs("servicegroup_servicegroupmember_binding", servicegroupname, args) + + if err != nil { + return err + } + + d.SetId("") + + return nil +} diff --git a/citrixadc/resource_citrixadc_servicegroup_servicegroupmember_binding_test.go b/citrixadc/resource_citrixadc_servicegroup_servicegroupmember_binding_test.go new file mode 100644 index 000000000..becb6fcc2 --- /dev/null +++ b/citrixadc/resource_citrixadc_servicegroup_servicegroupmember_binding_test.go @@ -0,0 +1,383 @@ +/* +Copyright 2016 Citrix Systems, Inc + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package citrixadc + +import ( + "fmt" + "github.com/chiradeep/go-nitro/netscaler" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "strconv" + "strings" + "testing" +) + +const testAccServicegroup_servicegroupmember_binding_ipv4_step1 = ` + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + servicetype = "HTTP" +} + +resource "citrixadc_servicegroup_servicegroupmember_binding" "tf_binding" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + ip = "10.78.22.33" + port = 80 +} +` + +const testAccServicegroup_servicegroupmember_binding_ipv4_step2 = ` + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + servicetype = "HTTP" +} +` + +func TestAccServicegroup_servicegroupmember_binding_ipv4(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckServicegroup_servicegroupmember_bindingDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccServicegroup_servicegroupmember_binding_ipv4_step1, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_servicegroupmember_bindingExist("citrixadc_servicegroup_servicegroupmember_binding.tf_binding", nil), + testAccCheckServicegroup_servicegroupmember_binding_not_exists("tf_servicegroup,10.78.22.33,80", true), + ), + }, + resource.TestStep{ + Config: testAccServicegroup_servicegroupmember_binding_ipv4_step2, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_servicegroupmember_binding_not_exists("tf_servicegroup,10.78.22.33,80", false), + ), + }, + }, + }) +} + +const testAccServicegroup_servicegroupmember_binding_ipv6_step1 = ` + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + servicetype = "HTTP" +} + +resource "citrixadc_servicegroup_servicegroupmember_binding" "tf_binding" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + ip = "ff::8839" + port = 80 +} +` + +const testAccServicegroup_servicegroupmember_binding_ipv6_step2 = ` + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + servicetype = "HTTP" +} +` + +func TestAccServicegroup_servicegroupmember_binding_ipv6(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckServicegroup_servicegroupmember_bindingDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccServicegroup_servicegroupmember_binding_ipv6_step1, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_servicegroupmember_bindingExist("citrixadc_servicegroup_servicegroupmember_binding.tf_binding", nil), + testAccCheckServicegroup_servicegroupmember_binding_not_exists("tf_servicegroup,ff::8839,80", true), + ), + }, + resource.TestStep{ + Config: testAccServicegroup_servicegroupmember_binding_ipv6_step2, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_servicegroupmember_binding_not_exists("tf_servicegroup,ff::8839,80", false), + ), + }, + }, + }) +} + +const testAccServicegroup_servicegroupmember_binding_server_no_port_step1 = ` + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + servicetype = "HTTP" + autoscale = "DNS" +} +resource "citrixadc_server" "tf_server" { + name = "tf_server" + domain = "example.com" + querytype = "SRV" +} + +resource "citrixadc_servicegroup_servicegroupmember_binding" "tf_binding" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + servername = citrixadc_server.tf_server.name +} +` + +const testAccServicegroup_servicegroupmember_binding_server_no_port_step2 = ` + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + servicetype = "HTTP" + autoscale = "DNS" +} +resource "citrixadc_server" "tf_server" { + name = "tf_server" + domain = "example.com" + querytype = "SRV" +} +` + +func TestAccServicegroup_servicegroupmember_binding_server_no_port(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckServicegroup_servicegroupmember_bindingDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccServicegroup_servicegroupmember_binding_server_no_port_step1, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_servicegroupmember_bindingExist("citrixadc_servicegroup_servicegroupmember_binding.tf_binding", nil), + testAccCheckServicegroup_servicegroupmember_binding_not_exists("tf_servicegroup,tf_server", true), + ), + }, + resource.TestStep{ + Config: testAccServicegroup_servicegroupmember_binding_server_no_port_step2, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_servicegroupmember_binding_not_exists("tf_servicegroup,tf_server", false), + ), + }, + }, + }) +} + +const testAccServicegroup_servicegroupmember_binding_server_with_port_step1 = ` + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + servicetype = "HTTP" + autoscale = "DNS" +} +resource "citrixadc_server" "tf_server" { + name = "tf_server" + ipaddress = "10.22.44.33" +} + +resource "citrixadc_servicegroup_servicegroupmember_binding" "tf_binding" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + servername = citrixadc_server.tf_server.name + port = 80 +} +` + +const testAccServicegroup_servicegroupmember_binding_server_with_port_step2 = ` + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + servicetype = "HTTP" + autoscale = "DNS" +} +resource "citrixadc_server" "tf_server" { + name = "tf_server" + ipaddress = "10.22.44.33" +} + +` + +func TestAccServicegroup_servicegroupmember_binding_server_with_port(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckServicegroup_servicegroupmember_bindingDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccServicegroup_servicegroupmember_binding_server_with_port_step1, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_servicegroupmember_bindingExist("citrixadc_servicegroup_servicegroupmember_binding.tf_binding", nil), + testAccCheckServicegroup_servicegroupmember_binding_not_exists("tf_servicegroup,tf_server,80", true), + ), + }, + resource.TestStep{ + Config: testAccServicegroup_servicegroupmember_binding_server_with_port_step2, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_servicegroupmember_binding_not_exists("tf_servicegroup,tf_server,80", false), + ), + }, + }, + }) +} + +func testAccCheckServicegroup_servicegroupmember_bindingExist(n string, id *string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No servicegroup_servicegroupmember_binding name is set") + } + + if id != nil { + if *id != "" && *id != rs.Primary.ID { + return fmt.Errorf("Resource ID has changed!") + } + + *id = rs.Primary.ID + } + + client := testAccProvider.Meta().(*NetScalerNitroClient).client + + bindingId := rs.Primary.ID + idSlice := strings.SplitN(bindingId, ",", 3) + servicegroupname := idSlice[0] + + servername := idSlice[1] + + port := 0 + var err error + if len(idSlice) == 3 { + if port, err = strconv.Atoi(idSlice[2]); err != nil { + return err + } + } + + findParams := netscaler.FindParams{ + ResourceType: "servicegroup_servicegroupmember_binding", + ResourceName: servicegroupname, + ResourceMissingErrorCode: 258, + } + + dataArr, err := client.FindResourceArrayWithParams(findParams) + // Unexpected error + if err != nil { + return err + } + + // Iterate through results to find the one with the right policy name + foundIndex := -1 + for i, v := range dataArr { + if port != 0 { + portEqual := int(v["port"].(float64)) == port + servernameEqual := v["servername"] == servername + if servernameEqual && portEqual { + foundIndex = i + break + } + } else { + if v["servername"].(string) == servername { + foundIndex = i + break + } + } + } + if foundIndex == -1 { + return fmt.Errorf("servicegroup_servicegroupmember_binding %s not found", bindingId) + } + + return nil + } +} + +func testAccCheckServicegroup_servicegroupmember_binding_not_exists(bindingId string, invert bool) resource.TestCheckFunc { + return func(s *terraform.State) error { + + client := testAccProvider.Meta().(*NetScalerNitroClient).client + + idSlice := strings.SplitN(bindingId, ",", 3) + servicegroupname := idSlice[0] + + servername := idSlice[1] + + port := 0 + var err error + if len(idSlice) == 3 { + if port, err = strconv.Atoi(idSlice[2]); err != nil { + return err + } + } + + findParams := netscaler.FindParams{ + ResourceType: "servicegroup_servicegroupmember_binding", + ResourceName: servicegroupname, + ResourceMissingErrorCode: 258, + } + + dataArr, err := client.FindResourceArrayWithParams(findParams) + // Unexpected error + if err != nil { + return err + } + + // Iterate through results to find the one with the right policy name + foundIndex := -1 + for i, v := range dataArr { + if port != 0 { + portEqual := int(v["port"].(float64)) == port + servernameEqual := v["servername"] == servername + if servernameEqual && portEqual { + foundIndex = i + break + } + } else { + if v["servername"].(string) == servername { + foundIndex = i + break + } + } + } + if !invert { + if foundIndex != -1 { + return fmt.Errorf("servicegroup_servicegroupmember_binding %s found. Should have been deleted", bindingId) + } + } else { + if foundIndex == -1 { + return fmt.Errorf("servicegroup_servicegroupmember_binding %s not found.", bindingId) + } + } + + return nil + } +} + +func testAccCheckServicegroup_servicegroupmember_bindingDestroy(s *terraform.State) error { + nsClient := testAccProvider.Meta().(*NetScalerNitroClient).client + + for _, rs := range s.RootModule().Resources { + if rs.Type != "citrixadc_servicegroup_servicegroupmember_binding" { + continue + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No name is set") + } + + _, err := nsClient.FindResource(netscaler.Servicegroup_servicegroupmember_binding.Type(), rs.Primary.ID) + if err == nil { + return fmt.Errorf("servicegroup_servicegroupmember_binding %s still exists", rs.Primary.ID) + } + + } + + return nil +} diff --git a/citrixadc/resource_citrixadc_servicegroup_test.go b/citrixadc/resource_citrixadc_servicegroup_test.go index 247731a0d..04691d7b9 100644 --- a/citrixadc/resource_citrixadc_servicegroup_test.go +++ b/citrixadc/resource_citrixadc_servicegroup_test.go @@ -175,11 +175,6 @@ func TestAccServicegroupAssertNonUpdateableAttributes(t *testing.T) { testHelperVerifyImmutabilityFunc(c, t, servicegroupType, servicegroupName, servicegroupInstance, "td") servicegroupInstance.Td = 0 - //autoscale - servicegroupInstance.Autoscale = "ENABLED" - testHelperVerifyImmutabilityFunc(c, t, servicegroupType, servicegroupName, servicegroupInstance, "autoscale") - servicegroupInstance.Autoscale = "" - //memberport servicegroupInstance.Memberport = 80 testHelperVerifyImmutabilityFunc(c, t, servicegroupType, servicegroupName, servicegroupInstance, "memberport") diff --git a/citrixadc/resource_citrixadc_sslvserver_sslcertkey_binding.go b/citrixadc/resource_citrixadc_sslvserver_sslcertkey_binding.go new file mode 100644 index 000000000..050d273ab --- /dev/null +++ b/citrixadc/resource_citrixadc_sslvserver_sslcertkey_binding.go @@ -0,0 +1,197 @@ +package citrixadc + +import ( + "github.com/chiradeep/go-nitro/config/ssl" + + "github.com/chiradeep/go-nitro/netscaler" + "github.com/hashicorp/terraform/helper/schema" + + "fmt" + "log" + "strings" +) + +func resourceCitrixAdcSslvserver_sslcertkey_binding() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + Create: createSslvserver_sslcertkey_bindingFunc, + Read: readSslvserver_sslcertkey_bindingFunc, + Delete: deleteSslvserver_sslcertkey_bindingFunc, + Schema: map[string]*schema.Schema{ + "ca": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Computed: true, + ForceNew: true, + }, + "certkeyname": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "crlcheck": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "ocspcheck": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "skipcaname": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Computed: true, + ForceNew: true, + }, + "snicert": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Computed: true, + ForceNew: true, + }, + "vservername": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + }, + } +} + +func createSslvserver_sslcertkey_bindingFunc(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] citrixadc-provider: In createSslvserver_sslcertkey_bindingFunc") + client := meta.(*NetScalerNitroClient).client + vservername := d.Get("vservername").(string) + certkeyname := d.Get("certkeyname").(string) + bindingId := fmt.Sprintf("%s,%s", vservername, certkeyname) + + sslvserver_sslcertkey_binding := ssl.Sslvserversslcertkeybinding{ + Ca: d.Get("ca").(bool), + Certkeyname: d.Get("certkeyname").(string), + Crlcheck: d.Get("crlcheck").(string), + Ocspcheck: d.Get("ocspcheck").(string), + Skipcaname: d.Get("skipcaname").(bool), + Snicert: d.Get("snicert").(bool), + Vservername: d.Get("vservername").(string), + } + + err := client.UpdateUnnamedResource(netscaler.Sslvserver_sslcertkey_binding.Type(), &sslvserver_sslcertkey_binding) + if err != nil { + return err + } + + d.SetId(bindingId) + + err = readSslvserver_sslcertkey_bindingFunc(d, meta) + if err != nil { + log.Printf("[ERROR] netscaler-provider: ?? we just created this sslvserver_sslcertkey_binding but we can't read it ?? %s", bindingId) + return nil + } + return nil +} + +func readSslvserver_sslcertkey_bindingFunc(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] citrixadc-provider: In readSslvserver_sslcertkey_bindingFunc") + client := meta.(*NetScalerNitroClient).client + + bindingId := d.Id() + idSlice := strings.SplitN(bindingId, ",", 2) + + vservername := idSlice[0] + certkeyname := idSlice[1] + + log.Printf("[DEBUG] citrixadc-provider: Reading sslvserver_sslcertkey_binding state %s", bindingId) + findParams := netscaler.FindParams{ + ResourceType: "sslvserver_sslcertkey_binding", + ResourceName: vservername, + ResourceMissingErrorCode: 461, + } + 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 sslvserver_sslcertkey_binding state %s", bindingId) + d.SetId("") + return nil + } + + // Iterate through results to find the one with the right certkeyname + foundIndex := -1 + for i, v := range dataArr { + if v["certkeyname"].(string) == certkeyname { + 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 sslvserver_sslcertkey_binding state %s", bindingId) + d.SetId("") + return nil + } + // Fallthrough + + data := dataArr[foundIndex] + + d.Set("ca", data["ca"]) + d.Set("certkeyname", data["certkeyname"]) + d.Set("crlcheck", data["crlcheck"]) + d.Set("ocspcheck", data["ocspcheck"]) + d.Set("skipcaname", data["skipcaname"]) + d.Set("snicert", data["snicert"]) + d.Set("vservername", data["vservername"]) + + return nil + +} + +func deleteSslvserver_sslcertkey_bindingFunc(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] citrixadc-provider: In deleteSslvserver_sslcertkey_bindingFunc") + client := meta.(*NetScalerNitroClient).client + + bindingId := d.Id() + idSlice := strings.Split(bindingId, ",") + + vservername := idSlice[0] + certkeyname := idSlice[1] + + args := make([]string, 0) + args = append(args, fmt.Sprintf("certkeyname:%v", certkeyname)) + + if v, ok := d.GetOk("ca"); ok { + args = append(args, fmt.Sprintf("ca:%v", v)) + } + + if v, ok := d.GetOk("crlcheck"); ok { + args = append(args, fmt.Sprintf("crlcheck:%v", v)) + } + + if v, ok := d.GetOk("snicert"); ok { + args = append(args, fmt.Sprintf("snicert:%v", v)) + } + + if v, ok := d.GetOk("ocspcheck"); ok { + args = append(args, fmt.Sprintf("ocspcheck:%v", v)) + } + + err := client.DeleteResourceWithArgs(netscaler.Sslvserver_sslcertkey_binding.Type(), vservername, args) + if err != nil { + return err + } + d.SetId("") + + return nil +} diff --git a/citrixadc/resource_citrixadc_sslvserver_sslcertkey_binding_test.go b/citrixadc/resource_citrixadc_sslvserver_sslcertkey_binding_test.go new file mode 100644 index 000000000..54e754fb7 --- /dev/null +++ b/citrixadc/resource_citrixadc_sslvserver_sslcertkey_binding_test.go @@ -0,0 +1,333 @@ +/* +Copyright 2016 Citrix Systems, Inc + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package citrixadc + +import ( + "fmt" + "github.com/chiradeep/go-nitro/netscaler" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "strings" + "testing" +) + +const testAccSslvserver_sslcertkey_binding_lb_step1 = ` +resource "citrixadc_sslcertkey" "tf_sslcertkey" { + certkey = "tf_sslcertkey" + cert = "/var/tmp/certificate2.crt" + key = "/var/tmp/key2.pem" + notificationperiod = 40 + expirymonitor = "ENABLED" +} + +resource "citrixadc_sslcertkey" "tf_cacertkey" { + certkey = "tf_cacertkey" + cert = "/var/tmp/ca.crt" +} + +resource "citrixadc_lbvserver" "tf_lbvserver" { + ipv46 = "10.10.10.44" + name = "tf_lbvserver" + port = 443 + servicetype = "SSL" + sslprofile = "ns_default_ssl_profile_frontend" +} + +resource "citrixadc_sslvserver_sslcertkey_binding" "tf_binding" { + vservername = citrixadc_lbvserver.tf_lbvserver.name + certkeyname = citrixadc_sslcertkey.tf_cacertkey.certkey + ca = true +} +` +const testAccSslvserver_sslcertkey_binding_lb_step2 = ` +resource "citrixadc_sslcertkey" "tf_sslcertkey" { + certkey = "tf_sslcertkey" + cert = "/var/tmp/certificate2.crt" + key = "/var/tmp/key2.pem" + notificationperiod = 40 + expirymonitor = "ENABLED" +} + +resource "citrixadc_sslcertkey" "tf_cacertkey" { + certkey = "tf_cacertkey" + cert = "/var/tmp/ca.crt" +} + +resource "citrixadc_lbvserver" "tf_lbvserver" { + ipv46 = "10.10.10.44" + name = "tf_lbvserver" + port = 443 + servicetype = "SSL" + sslprofile = "ns_default_ssl_profile_frontend" +} + +resource "citrixadc_sslvserver_sslcertkey_binding" "tf_binding" { + vservername = citrixadc_lbvserver.tf_lbvserver.name + certkeyname = citrixadc_sslcertkey.tf_sslcertkey.certkey +} +` + +const testAccSslvserver_sslcertkey_binding_lb_step3 = ` +resource "citrixadc_sslcertkey" "tf_sslcertkey" { + certkey = "tf_sslcertkey" + cert = "/var/tmp/certificate2.crt" + key = "/var/tmp/key2.pem" + notificationperiod = 40 + expirymonitor = "ENABLED" +} + +resource "citrixadc_sslcertkey" "tf_cacertkey" { + certkey = "tf_cacertkey" + cert = "/var/tmp/ca.crt" +} + +resource "citrixadc_lbvserver" "tf_lbvserver" { + ipv46 = "10.10.10.44" + name = "tf_lbvserver" + port = 443 + servicetype = "SSL" + sslprofile = "ns_default_ssl_profile_frontend" +} + +resource "citrixadc_sslvserver_sslcertkey_binding" "tf_binding" { + vservername = citrixadc_lbvserver.tf_lbvserver.name + certkeyname = citrixadc_sslcertkey.tf_sslcertkey.certkey + snicert = true +} +` + +const testAccSslvserver_sslcertkey_binding_cs_step1 = ` +resource "citrixadc_sslcertkey" "tf_sslcertkey" { + certkey = "tf_sslcertkey" + cert = "/var/tmp/certificate2.crt" + key = "/var/tmp/key2.pem" + notificationperiod = 40 + expirymonitor = "ENABLED" +} + +resource "citrixadc_sslcertkey" "tf_cacertkey" { + certkey = "tf_cacertkey" + cert = "/var/tmp/ca.crt" +} + + +resource "citrixadc_csvserver" "tf_csvserver" { + ipv46 = "10.10.10.55" + name = "tf_csvserver" + port = 443 + servicetype = "SSL" + sslprofile = "ns_default_ssl_profile_frontend" +} + +resource "citrixadc_sslvserver_sslcertkey_binding" "tf_binding" { + vservername = citrixadc_csvserver.tf_csvserver.name + certkeyname = citrixadc_sslcertkey.tf_cacertkey.certkey + ca = true +} +` + +const testAccSslvserver_sslcertkey_binding_cs_step2 = ` +resource "citrixadc_sslcertkey" "tf_sslcertkey" { + certkey = "tf_sslcertkey" + cert = "/var/tmp/certificate2.crt" + key = "/var/tmp/key2.pem" + notificationperiod = 40 + expirymonitor = "ENABLED" +} + +resource "citrixadc_sslcertkey" "tf_cacertkey" { + certkey = "tf_cacertkey" + cert = "/var/tmp/ca.crt" +} + + +resource "citrixadc_csvserver" "tf_csvserver" { + ipv46 = "10.10.10.55" + name = "tf_csvserver" + port = 443 + servicetype = "SSL" + sslprofile = "ns_default_ssl_profile_frontend" +} + +resource "citrixadc_sslvserver_sslcertkey_binding" "tf_binding" { + vservername = citrixadc_csvserver.tf_csvserver.name + certkeyname = citrixadc_sslcertkey.tf_sslcertkey.certkey +} +` + +const testAccSslvserver_sslcertkey_binding_cs_step3 = ` +resource "citrixadc_sslcertkey" "tf_sslcertkey" { + certkey = "tf_sslcertkey" + cert = "/var/tmp/certificate2.crt" + key = "/var/tmp/key2.pem" + notificationperiod = 40 + expirymonitor = "ENABLED" +} + +resource "citrixadc_sslcertkey" "tf_cacertkey" { + certkey = "tf_cacertkey" + cert = "/var/tmp/ca.crt" +} + + +resource "citrixadc_csvserver" "tf_csvserver" { + ipv46 = "10.10.10.55" + name = "tf_csvserver" + port = 443 + servicetype = "SSL" + sslprofile = "ns_default_ssl_profile_frontend" +} + +resource "citrixadc_sslvserver_sslcertkey_binding" "tf_binding" { + vservername = citrixadc_csvserver.tf_csvserver.name + certkeyname = citrixadc_sslcertkey.tf_sslcertkey.certkey + snicert = true +} +` + +func TestAccSslvserver_sslcertkey_binding_lb(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckSslvserver_sslcertkey_bindingDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccSslvserver_sslcertkey_binding_lb_step1, + Check: resource.ComposeTestCheckFunc( + testAccCheckSslvserver_sslcertkey_bindingExist("citrixadc_sslvserver_sslcertkey_binding.tf_binding", nil), + ), + }, + resource.TestStep{ + Config: testAccSslvserver_sslcertkey_binding_lb_step2, + Check: resource.ComposeTestCheckFunc( + testAccCheckSslvserver_sslcertkey_bindingExist("citrixadc_sslvserver_sslcertkey_binding.tf_binding", nil), + ), + }, + resource.TestStep{ + Config: testAccSslvserver_sslcertkey_binding_lb_step3, + Check: resource.ComposeTestCheckFunc( + testAccCheckSslvserver_sslcertkey_bindingExist("citrixadc_sslvserver_sslcertkey_binding.tf_binding", nil), + ), + }, + }, + }) +} + +func TestAccSslvserver_sslcertkey_binding_cs(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckSslvserver_sslcertkey_bindingDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccSslvserver_sslcertkey_binding_cs_step1, + Check: resource.ComposeTestCheckFunc( + testAccCheckSslvserver_sslcertkey_bindingExist("citrixadc_sslvserver_sslcertkey_binding.tf_binding", nil), + ), + }, + resource.TestStep{ + Config: testAccSslvserver_sslcertkey_binding_cs_step2, + Check: resource.ComposeTestCheckFunc( + testAccCheckSslvserver_sslcertkey_bindingExist("citrixadc_sslvserver_sslcertkey_binding.tf_binding", nil), + ), + }, + resource.TestStep{ + Config: testAccSslvserver_sslcertkey_binding_cs_step3, + Check: resource.ComposeTestCheckFunc( + testAccCheckSslvserver_sslcertkey_bindingExist("citrixadc_sslvserver_sslcertkey_binding.tf_binding", nil), + ), + }, + }, + }) +} + +func testAccCheckSslvserver_sslcertkey_bindingExist(n string, id *string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No sslvserver_sslcertkey_binding name is set") + } + + if id != nil { + if *id != "" && *id != rs.Primary.ID { + return fmt.Errorf("Resource ID has changed!") + } + + *id = rs.Primary.ID + } + + client := testAccProvider.Meta().(*NetScalerNitroClient).client + + bindingId := rs.Primary.ID + idSlice := strings.SplitN(bindingId, ",", 2) + + vservername := idSlice[0] + certkeyname := idSlice[1] + + findParams := netscaler.FindParams{ + ResourceType: "sslvserver_sslcertkey_binding", + ResourceName: vservername, + ResourceMissingErrorCode: 461, + } + dataArr, err := client.FindResourceArrayWithParams(findParams) + + if err != nil { + return err + } + + // Iterate through results to find the one with the right certkeyname + foundIndex := -1 + for i, v := range dataArr { + if v["certkeyname"].(string) == certkeyname { + foundIndex = i + break + } + } + + // Resource is missing + if foundIndex == -1 { + return fmt.Errorf("Cannot find binding %v", bindingId) + } + + return nil + } +} + +func testAccCheckSslvserver_sslcertkey_bindingDestroy(s *terraform.State) error { + nsClient := testAccProvider.Meta().(*NetScalerNitroClient).client + + for _, rs := range s.RootModule().Resources { + if rs.Type != "citrixadc_sslvserver_sslcertkey_binding" { + continue + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No name is set") + } + + _, err := nsClient.FindResource(netscaler.Sslvserver_sslcertkey_binding.Type(), rs.Primary.ID) + if err == nil { + return fmt.Errorf("sslvserver_sslcertkey_binding %s still exists", rs.Primary.ID) + } + + } + + return nil +} diff --git a/examples/servicegroup_servicegroupmemeber_binding/provider.tf b/examples/servicegroup_servicegroupmemeber_binding/provider.tf new file mode 100644 index 000000000..95295b020 --- /dev/null +++ b/examples/servicegroup_servicegroupmemeber_binding/provider.tf @@ -0,0 +1,10 @@ +terraform { + required_providers { + citrixadc = { + source = "citrix/citrixadc" + } + } +} +provider "citrixadc" { + endpoint = "http://localhost:8080" +} diff --git a/examples/servicegroup_servicegroupmemeber_binding/resources.tf b/examples/servicegroup_servicegroupmemeber_binding/resources.tf new file mode 100644 index 000000000..043b6c9b8 --- /dev/null +++ b/examples/servicegroup_servicegroupmemeber_binding/resources.tf @@ -0,0 +1,22 @@ +resource "citrixadc_server" "tf_server" { + name = "tf_server" + domain = "example.com" + querytype = "SRV" +} + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + servicetype = "HTTP" + autoscale = "DNS" +} + +resource "citrixadc_servicegroup_servicegroupmember_binding" "tf_binding" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + servername = citrixadc_server.tf_server.name +} + +resource "citrixadc_servicegroup_servicegroupmember_binding" "tf_binding2" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + ip = "10.78.22.33" + port = 80 +} diff --git a/examples/sslvserver_sslcertkey_binding/provider.tf b/examples/sslvserver_sslcertkey_binding/provider.tf new file mode 100644 index 000000000..e96880608 --- /dev/null +++ b/examples/sslvserver_sslcertkey_binding/provider.tf @@ -0,0 +1,10 @@ +terraform { + required_providers { + citrixadc = { + source = "citrix/citrixadc" + } + } +} +provider "citrixadc" { + endpoint = "http://localhost:8000" +} diff --git a/examples/sslvserver_sslcertkey_binding/resources.tf b/examples/sslvserver_sslcertkey_binding/resources.tf new file mode 100644 index 000000000..716bbe69d --- /dev/null +++ b/examples/sslvserver_sslcertkey_binding/resources.tf @@ -0,0 +1,22 @@ +resource "citrixadc_sslcertkey" "tf_sslcertkey" { + certkey = "tf_sslcertkey" + cert = "/var/tmp/certificate2.crt" + key = "/var/tmp/key2.pem" + notificationperiod = 40 + expirymonitor = "ENABLED" +} + +resource "citrixadc_lbvserver" "tf_lbvserver" { + ipv46 = "10.10.10.44" + name = "tf_lbvserver" + port = 443 + servicetype = "SSL" + sslprofile = "ns_default_ssl_profile_frontend" +} + + +resource "citrixadc_sslvserver_sslcertkey_binding" "tf_binding" { + vservername = citrixadc_lbvserver.tf_lbvserver.name + certkeyname = citrixadc_sslcertkey.tf_sslcertkey.certkey + snicert = true +}