From 1c9987e2c0e449d4a6a00a073669c1eb42e85e59 Mon Sep 17 00:00:00 2001 From: George Nikolopoulos Date: Tue, 14 Jul 2020 17:32:26 +0300 Subject: [PATCH] Implement resource servicegroup_lbmonitor_binding with examples Signed-off-by: George Nikolopoulos --- citrixadc/provider.go | 117 ++++---- ...itrixadc_servicegroup_lbmonitor_binding.go | 236 ++++++++++++++++ ...adc_servicegroup_lbmonitor_binding_test.go | 252 ++++++++++++++++++ .../provider.tf | 3 + .../resources.tf | 42 +++ 5 files changed, 592 insertions(+), 58 deletions(-) create mode 100644 citrixadc/resource_citrixadc_servicegroup_lbmonitor_binding.go create mode 100644 citrixadc/resource_citrixadc_servicegroup_lbmonitor_binding_test.go create mode 100644 examples/servicegroup_lbmonitor_binding/provider.tf create mode 100644 examples/servicegroup_lbmonitor_binding/resources.tf diff --git a/citrixadc/provider.go b/citrixadc/provider.go index bf5ec761c..bc4fd51ca 100644 --- a/citrixadc/provider.go +++ b/citrixadc/provider.go @@ -78,64 +78,65 @@ 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_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(), } } diff --git a/citrixadc/resource_citrixadc_servicegroup_lbmonitor_binding.go b/citrixadc/resource_citrixadc_servicegroup_lbmonitor_binding.go new file mode 100644 index 000000000..c3db69aff --- /dev/null +++ b/citrixadc/resource_citrixadc_servicegroup_lbmonitor_binding.go @@ -0,0 +1,236 @@ +package citrixadc + +import ( + "github.com/chiradeep/go-nitro/config/basic" + + "github.com/chiradeep/go-nitro/netscaler" + "github.com/hashicorp/terraform/helper/schema" + + "fmt" + "log" + "strings" +) + +func resourceCitrixAdcServicegroup_lbmonitor_binding() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + Create: createServicegroup_lbmonitor_bindingFunc, + Read: readServicegroup_lbmonitor_bindingFunc, + Delete: deleteServicegroup_lbmonitor_bindingFunc, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + 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, + }, + "monitorname": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "monstate": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "nameserver": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "passive": &schema.Schema{ + Type: schema.TypeBool, + 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, + }, + "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_lbmonitor_bindingFunc(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] citrixadc-provider: In createServicegroup_lbmonitor_bindingFunc") + client := meta.(*NetScalerNitroClient).client + servicegroupName := d.Get("servicegroupname") + monitorName := d.Get("monitorname") + // Use `,` as the separator since it is invalid character for servicegroup and monitor name + servicegroupLbmonitorBindingId := fmt.Sprintf("%s,%s", servicegroupName, monitorName) + + servicegroup_lbmonitor_binding := basic.Servicegrouplbmonitorbinding{ + Customserverid: d.Get("customserverid").(string), + Dbsttl: d.Get("dbsttl").(int), + Hashid: d.Get("hashid").(int), + Monitorname: d.Get("monitorname").(string), + Monstate: d.Get("monstate").(string), + Nameserver: d.Get("nameserver").(string), + Passive: d.Get("passive").(bool), + Port: d.Get("port").(int), + Serverid: d.Get("serverid").(int), + Servicegroupname: d.Get("servicegroupname").(string), + State: d.Get("state").(string), + Weight: d.Get("weight").(int), + } + + err := client.UpdateUnnamedResource(netscaler.Servicegroup_lbmonitor_binding.Type(), &servicegroup_lbmonitor_binding) + if err != nil { + return err + } + + d.SetId(servicegroupLbmonitorBindingId) + + err = readServicegroup_lbmonitor_bindingFunc(d, meta) + if err != nil { + log.Printf("[ERROR] netscaler-provider: ?? we just created this servicegroup_lbmonitor_binding but we can't read it ?? %s", servicegroupLbmonitorBindingId) + return nil + } + return nil +} + +func readServicegroup_lbmonitor_bindingFunc(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] citrixadc-provider: In readServicegroup_lbmonitor_bindingFunc") + client := meta.(*NetScalerNitroClient).client + servicegroupLbmonitorBindingId := d.Id() + idSlice := strings.Split(servicegroupLbmonitorBindingId, ",") + + if len(idSlice) < 2 { + return fmt.Errorf("Cannot deduce monitorname from id string") + } + + if len(idSlice) > 2 { + return fmt.Errorf("Too many separators \",\" in id string") + } + + servicegroupName := idSlice[0] + monitorName := idSlice[1] + + log.Printf("[DEBUG] citrixadc-provider: Reading servicegroup_lbmonitor_binding state %s", servicegroupLbmonitorBindingId) + findParams := netscaler.FindParams{ + ResourceType: "servicegroup_lbmonitor_binding", + ResourceName: servicegroupName, + 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 servicegroup_lbmonitor_binding state %s", servicegroupLbmonitorBindingId) + d.SetId("") + return nil + } + + // Iterate through results to find the one with the right monitor name + foundIndex := -1 + for i, v := range dataArr { + if v["monitor_name"].(string) == monitorName { + 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 servicegroup_lbmonitor_binding state %s", servicegroupLbmonitorBindingId) + d.SetId("") + return nil + } + // Fallthrough + + data := dataArr[foundIndex] + + d.Set("name", data["name"]) + d.Set("customserverid", data["customserverid"]) + d.Set("dbsttl", data["dbsttl"]) + d.Set("hashid", data["hashid"]) + d.Set("monitorname", data["monitor_name"]) + d.Set("monstate", data["monstate"]) + d.Set("nameserver", data["nameserver"]) + d.Set("passive", data["passive"]) + d.Set("port", data["port"]) + d.Set("serverid", data["serverid"]) + d.Set("servicegroupname", data["servicegroupname"]) + d.Set("state", data["state"]) + d.Set("weight", data["weight"]) + + return nil + +} + +func deleteServicegroup_lbmonitor_bindingFunc(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] citrixadc-provider: In deleteServicegroup_lbmonitor_bindingFunc") + client := meta.(*NetScalerNitroClient).client + servicegroupLbmonitorBindingId := d.Id() + idSlice := strings.Split(servicegroupLbmonitorBindingId, ",") + + servicegroupName := idSlice[0] + monitorName := idSlice[1] + + args := make([]string, 0) + args = append(args, fmt.Sprintf("monitor_name:%s", monitorName)) + if v, ok := d.GetOk("port"); ok { + args = append(args, fmt.Sprintf("port:%v", v)) + } + + err := client.DeleteResourceWithArgs(netscaler.Servicegroup_lbmonitor_binding.Type(), servicegroupName, args) + if err != nil { + return err + } + + d.SetId("") + + return nil +} diff --git a/citrixadc/resource_citrixadc_servicegroup_lbmonitor_binding_test.go b/citrixadc/resource_citrixadc_servicegroup_lbmonitor_binding_test.go new file mode 100644 index 000000000..be60f4284 --- /dev/null +++ b/citrixadc/resource_citrixadc_servicegroup_lbmonitor_binding_test.go @@ -0,0 +1,252 @@ +/* +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" +) + +func TestAccServicegroup_lbmonitor_binding_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckServicegroup_lbmonitor_bindingDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccServicegroup_lbmonitor_binding_basic_step1, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_lbmonitor_bindingExist("citrixadc_servicegroup_lbmonitor_binding.bind1", nil), + testAccCheckServicegroup_lbmonitor_bindingExist("citrixadc_servicegroup_lbmonitor_binding.bind2", nil), + ), + }, + resource.TestStep{ + Config: testAccServicegroup_lbmonitor_binding_basic_step2, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_lbmonitor_bindingExist("citrixadc_servicegroup_lbmonitor_binding.bind1", nil), + testAccCheckServicegroup_lbmonitor_bindingExist("citrixadc_servicegroup_lbmonitor_binding.bind2", nil), + ), + }, + resource.TestStep{ + Config: testAccServicegroup_lbmonitor_binding_basic_step3, + Check: resource.ComposeTestCheckFunc( + testAccCheckServicegroup_lbmonitor_bindingExist("citrixadc_servicegroup_lbmonitor_binding.bind1", nil), + ), + }, + }, + }) +} + +func testAccCheckServicegroup_lbmonitor_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 lb vserver name is set") + } + + if id != nil { + if *id != "" && *id != rs.Primary.ID { + return fmt.Errorf("Resource ID has changed!") + } + + *id = rs.Primary.ID + } + + nsClient := testAccProvider.Meta().(*NetScalerNitroClient).client + + servicegroupLbmonitorBindingId := rs.Primary.ID + idSlice := strings.Split(servicegroupLbmonitorBindingId, ",") + servicegroupName := idSlice[0] + monitorName := idSlice[1] + + findParams := netscaler.FindParams{ + ResourceType: "servicegroup_lbmonitor_binding", + ResourceName: servicegroupName, + ResourceMissingErrorCode: 258, + } + + dataArr, err := nsClient.FindResourceArrayWithParams(findParams) + + if err != nil { + return err + } + + found := false + + for _, v := range dataArr { + if v["monitor_name"].(string) == monitorName { + found = true + break + } + } + + if !found { + return fmt.Errorf("binding %s not found", n) + } + + return nil + } +} + +func testAccCheckServicegroup_lbmonitor_bindingDestroy(s *terraform.State) error { + nsClient := testAccProvider.Meta().(*NetScalerNitroClient).client + + for _, rs := range s.RootModule().Resources { + if rs.Type != "citrixadc_servicegroup_lbmonitor_binding" { + continue + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No name is set") + } + + _, err := nsClient.FindResource(netscaler.Servicegroup_lbmonitor_binding.Type(), rs.Primary.ID) + if err == nil { + return fmt.Errorf("LB vserver %s still exists", rs.Primary.ID) + } + + } + + return nil +} + +const testAccServicegroup_lbmonitor_binding_basic_step1 = ` +resource "citrixadc_lbvserver" "tf_lbvserver" { + name = "tf_lbvserver" + ipv46 = "192.168.13.46" + port = "80" + servicetype = "HTTP" +} + +resource "citrixadc_lbmonitor" "tfmonitor1" { + monitorname = "tf-monitor1" + type = "HTTP" +} + +resource "citrixadc_lbmonitor" "tfmonitor2" { + monitorname = "tfmonitor2" + type = "PING" +} + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + lbvservers = [citrixadc_lbvserver.tf_lbvserver.name] + servicetype = "HTTP" + servicegroupmembers = [ + "192.168.33.33:80:1", + ] + +} + +resource "citrixadc_servicegroup_lbmonitor_binding" "bind1" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + monitorname = citrixadc_lbmonitor.tfmonitor1.monitorname + weight = 80 +} + +resource "citrixadc_servicegroup_lbmonitor_binding" "bind2" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + monitorname = citrixadc_lbmonitor.tfmonitor2.monitorname + weight = 20 +} + +` + +const testAccServicegroup_lbmonitor_binding_basic_step2 = ` +resource "citrixadc_lbvserver" "tf_lbvserver" { + name = "tf_lbvserver" + ipv46 = "192.168.13.46" + port = "80" + servicetype = "HTTP" +} + +resource "citrixadc_lbmonitor" "tfmonitor1" { + monitorname = "tf-monitor1" + type = "HTTP" +} + +resource "citrixadc_lbmonitor" "tfmonitor2" { + monitorname = "tfmonitor2" + type = "PING" +} + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + lbvservers = [citrixadc_lbvserver.tf_lbvserver.name] + servicetype = "HTTP" + servicegroupmembers = [ + "192.168.33.33:80:1", + ] + +} + +resource "citrixadc_servicegroup_lbmonitor_binding" "bind1" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + monitorname = citrixadc_lbmonitor.tfmonitor1.monitorname + weight = 50 +} + +resource "citrixadc_servicegroup_lbmonitor_binding" "bind2" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + monitorname = citrixadc_lbmonitor.tfmonitor2.monitorname + weight = 50 +} + +` + +const testAccServicegroup_lbmonitor_binding_basic_step3 = ` +resource "citrixadc_lbvserver" "tf_lbvserver" { + name = "tf_lbvserver" + ipv46 = "192.168.13.46" + port = "80" + servicetype = "HTTP" +} + +resource "citrixadc_lbmonitor" "tfmonitor1" { + monitorname = "tf-monitor1" + type = "HTTP" +} + +resource "citrixadc_lbmonitor" "tfmonitor2" { + monitorname = "tfmonitor2" + type = "PING" +} + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + lbvservers = [citrixadc_lbvserver.tf_lbvserver.name] + servicetype = "HTTP" + servicegroupmembers = [ + "192.168.33.33:80:1", + ] + +} + +resource "citrixadc_servicegroup_lbmonitor_binding" "bind1" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + monitorname = citrixadc_lbmonitor.tfmonitor1.monitorname + weight = 50 +} + +` diff --git a/examples/servicegroup_lbmonitor_binding/provider.tf b/examples/servicegroup_lbmonitor_binding/provider.tf new file mode 100644 index 000000000..3d4508593 --- /dev/null +++ b/examples/servicegroup_lbmonitor_binding/provider.tf @@ -0,0 +1,3 @@ +provider "citrixadc" { + endpoint = "http://localhost:8080" +} diff --git a/examples/servicegroup_lbmonitor_binding/resources.tf b/examples/servicegroup_lbmonitor_binding/resources.tf new file mode 100644 index 000000000..bc77ff1c9 --- /dev/null +++ b/examples/servicegroup_lbmonitor_binding/resources.tf @@ -0,0 +1,42 @@ +resource "citrixadc_lbvserver" "tf_lbvserver" { + name = "tf_lbvserver" + ipv46 = "192.168.13.46" + port = "80" + servicetype = "HTTP" +} + +resource "citrixadc_lbmonitor" "tfmonitor1" { + monitorname = "tf-monitor1" + type = "HTTP" +} + +resource "citrixadc_lbmonitor" "tfmonitor2" { + monitorname = "tfmonitor2" + type = "PING" +} + +resource "citrixadc_servicegroup" "tf_servicegroup" { + servicegroupname = "tf_servicegroup" + lbvservers = [citrixadc_lbvserver.tf_lbvserver.name] + servicetype = "HTTP" + servicegroupmembers = [ + "192.168.33.33:80:1", + ] + + # Don't use lbmonitor inside servicegroup when using the explicit bindings +} + +# Import command example +# terraform import citrixadc_servicegroup_lbmonitor_binding.bind1 tf_servicegroup,tfmonitor1 + +resource "citrixadc_servicegroup_lbmonitor_binding" "bind1" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + monitorname = citrixadc_lbmonitor.tfmonitor1.monitorname + weight = 80 +} + +resource "citrixadc_servicegroup_lbmonitor_binding" "bind2" { + servicegroupname = citrixadc_servicegroup.tf_servicegroup.servicegroupname + monitorname = citrixadc_lbmonitor.tfmonitor2.monitorname + weight = 20 +}