diff --git a/ibm/config.go b/ibm/config.go index 716e1cb48d..79171a5f8f 100644 --- a/ibm/config.go +++ b/ibm/config.go @@ -22,6 +22,7 @@ import ( cisedgefunctionv1 "github.com/IBM/networking-go-sdk/edgefunctionsapiv1" cisglbhealthcheckv1 "github.com/IBM/networking-go-sdk/globalloadbalancermonitorv1" cisglbpoolv0 "github.com/IBM/networking-go-sdk/globalloadbalancerpoolsv0" + cisglbv1 "github.com/IBM/networking-go-sdk/globalloadbalancerv1" cissslv1 "github.com/IBM/networking-go-sdk/sslcertificateapiv1" tg "github.com/IBM/networking-go-sdk/transitgatewayapisv1" cisratelimitv1 "github.com/IBM/networking-go-sdk/zoneratelimitsv1" @@ -191,6 +192,7 @@ type ClientSession interface { IAMNamespaceAPI() (*ns.IbmCloudFunctionsNamespaceAPIV1, error) CisZonesV1ClientSession() (*ciszonesv1.ZonesV1, error) CisDNSRecordClientSession() (*cisdnsrecordsv1.DnsRecordsV1, error) + CisGLBClientSession() (*cisglbv1.GlobalLoadBalancerV1, error) CisGLBPoolClientSession() (*cisglbpoolv0.GlobalLoadBalancerPoolsV0, error) CisGLBHealthCheckClientSession() (*cisglbhealthcheckv1.GlobalLoadBalancerMonitorV1, error) CisRLClientSession() (*cisratelimitv1.ZoneRateLimitsV1, error) @@ -325,6 +327,10 @@ type clientSession struct { cisGLBPoolErr error cisGLBPoolClient *cisglbpoolv0.GlobalLoadBalancerPoolsV0 + // CIS GLB service options + cisGLBErr error + cisGLBClient *cisglbv1.GlobalLoadBalancerV1 + // CIS GLB health check service options cisGLBHealthCheckErr error cisGLBHealthCheckClient *cisglbhealthcheckv1.GlobalLoadBalancerMonitorV1 @@ -547,6 +553,11 @@ func (sess clientSession) CisGLBPoolClientSession() (*cisglbpoolv0.GlobalLoadBal return sess.cisGLBPoolClient, sess.cisGLBPoolErr } +// CIS GLB +func (sess clientSession) CisGLBClientSession() (*cisglbv1.GlobalLoadBalancerV1, error) { + return sess.cisGLBClient, sess.cisGLBErr +} + // CIS GLB Health Check/Monitor func (sess clientSession) CisGLBHealthCheckClientSession() (*cisglbhealthcheckv1.GlobalLoadBalancerMonitorV1, error) { return sess.cisGLBHealthCheckClient, sess.cisGLBHealthCheckErr @@ -626,6 +637,7 @@ func (c *Config) ClientSession() (interface{}, error) { session.iamNamespaceErr = errEmptyBluemixCredentials session.cisDNSErr = errEmptyBluemixCredentials session.cisGLBPoolErr = errEmptyBluemixCredentials + session.cisGLBErr = errEmptyBluemixCredentials session.cisGLBHealthCheckErr = errEmptyBluemixCredentials session.cisZonesErr = errEmptyBluemixCredentials session.cisRLErr = errEmptyBluemixCredentials @@ -999,6 +1011,20 @@ func (c *Config) ClientSession() (interface{}, error) { session.cisGLBPoolErr) } + // IBM Network CIS Global load balancer + cisGLBOpt := &cisglbv1.GlobalLoadBalancerV1Options{ + URL: cisEndPoint, + Authenticator: authenticator, + Crn: core.StringPtr(""), + ZoneIdentifier: core.StringPtr(""), + } + session.cisGLBClient, session.cisGLBErr = cisglbv1.NewGlobalLoadBalancerV1(cisGLBOpt) + if session.cisGLBErr != nil { + session.cisGLBErr = + fmt.Errorf("Error occured while configuring CIS GLB service: %s", + session.cisGLBErr) + } + // IBM Network CIS Global load balancer health check/monitor cisGLBHealthCheckOpt := &cisglbhealthcheckv1.GlobalLoadBalancerMonitorV1Options{ URL: cisEndPoint, @@ -1072,6 +1098,7 @@ func (c *Config) ClientSession() (interface{}, error) { fmt.Errorf("Error occured while configuring CIS SSL certificate service: %s", session.cisSSLErr) } + return session, nil } diff --git a/ibm/data_source_ibm_cis_global_load_balancers.go b/ibm/data_source_ibm_cis_global_load_balancers.go new file mode 100644 index 0000000000..491471e821 --- /dev/null +++ b/ibm/data_source_ibm_cis_global_load_balancers.go @@ -0,0 +1,225 @@ +package ibm + +import ( + "log" + "time" + + "github.com/IBM/go-sdk-core/v3/core" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +const cisGLB = "cis_glb" + +func dataSourceIBMCISGlbs() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + cisID: { + Type: schema.TypeString, + Description: "CIS instance crn", + Required: true, + }, + cisDomainID: { + Type: schema.TypeString, + Description: "Associated CIS domain", + Required: true, + DiffSuppressFunc: suppressDomainIDDiff, + }, + cisGLB: { + Type: schema.TypeList, + Description: "Collection of GLB detail", + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Description: "identifier with zone id", + Computed: true, + }, + cisGLBID: { + Type: schema.TypeString, + Description: "global load balancer id", + Computed: true, + }, + cisGLBName: { + Type: schema.TypeString, + Description: "name", + Computed: true, + }, + cisGLBFallbackPoolID: { + Type: schema.TypeString, + Description: "fallback pool ID", + Computed: true, + }, + cisGLBDefaultPoolIDs: { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "List of default Pool IDs", + }, + cisGLBDesc: { + Type: schema.TypeString, + Computed: true, + Description: "Description for the load balancer instance", + }, + cisGLBTTL: { + Type: schema.TypeInt, + Computed: true, + Description: "TTL value", + }, + cisGLBProxied: { + Type: schema.TypeBool, + Computed: true, + Description: "set to true if proxy needs to be enabled", + }, + cisGLBSessionAffinity: { + Type: schema.TypeString, + Computed: true, + Description: "Session affinity info", + }, + cisGLBEnabled: { + Type: schema.TypeBool, + Computed: true, + Description: "set to true of LB needs to enabled", + }, + cisGLBCreatedOn: { + Type: schema.TypeString, + Computed: true, + Description: "Load balancer creation date", + }, + cisGLBModifiedOn: { + Type: schema.TypeString, + Computed: true, + Description: "Load balancer modified date", + }, + cisGLBPopPools: { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + cisGLBPopPoolsPop: { + Type: schema.TypeString, + Computed: true, + Description: "pop pools region", + }, + + cisGLBPopPoolsPoolIDs: { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + cisGLBRegionPools: { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + cisGLBRegionPoolsRegion: { + Type: schema.TypeString, + Computed: true, + }, + cisGLBRegionPoolsPoolIDs: { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + }, + }, + }, + }, + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(10 * time.Minute), + }, + Read: dataSourceCISGlbsRead, + Importer: &schema.ResourceImporter{}, + } +} + +func dataSourceCISGlbsRead(d *schema.ResourceData, meta interface{}) error { + cisClient, err := meta.(ClientSession).CisGLBClientSession() + if err != nil { + return err + } + + crn := d.Get(cisID).(string) + zoneID := d.Get(cisDomainID).(string) + cisClient.Crn = core.StringPtr(crn) + cisClient.ZoneIdentifier = core.StringPtr(zoneID) + + opt := cisClient.NewListAllLoadBalancersOptions() + + result, resp, err := cisClient.ListAllLoadBalancers(opt) + if err != nil { + log.Printf("[WARN] List all GLB failed: %v\n", resp) + return err + } + glbs := result.Result + + glbList := make([]map[string]interface{}, 0) + for _, glbObj := range glbs { + glbOutput := map[string]interface{}{} + glbOutput["id"] = convertCisToTfThreeVar(*glbObj.ID, zoneID, crn) + glbOutput[cisGLBID] = *glbObj.ID + glbOutput[cisGLBName] = *glbObj.Name + glbOutput[cisGLBDefaultPoolIDs] = convertCisToTfTwoVarSlice(glbObj.DefaultPools, crn) + glbOutput[cisGLBDesc] = *glbObj.Description + glbOutput[cisGLBFallbackPoolID] = convertCisToTfTwoVar(*glbObj.FallbackPool, crn) + glbOutput[cisGLBTTL] = *glbObj.TTL + glbOutput[cisGLBProxied] = *glbObj.Proxied + glbOutput[cisGLBEnabled] = *glbObj.Enabled + glbOutput[cisGLBSessionAffinity] = *glbObj.SessionAffinity + glbOutput[cisGLBCreatedOn] = *glbObj.CreatedOn + glbOutput[cisGLBModifiedOn] = *glbObj.ModifiedOn + flattenPopPools := flattenDataSourcePopPools( + glbObj.PopPools, cisGLBPopPoolsPop, crn) + glbOutput[cisGLBPopPools] = flattenPopPools + flattenRegionPools := flattenDataSourceRegionPools( + glbObj.RegionPools, cisGLBRegionPoolsRegion, crn) + glbOutput[cisGLBRegionPools] = flattenRegionPools + glbList = append(glbList, glbOutput) + } + d.SetId(dataSourceCISGlbsCheckID(d)) + d.Set(cisGLB, glbList) + return nil +} + +// dataSourceCISGlbCheckID returns a reasonable ID glb list +func dataSourceCISGlbsCheckID(d *schema.ResourceData) string { + return time.Now().UTC().String() +} + +func flattenDataSourcePopPools(pools interface{}, geoType string, cisID string) []interface{} { + result := make([]interface{}, 0) + for k, v := range pools.(map[string]interface{}) { + poolIds := convertCisToTfTwoVarSlice(expandStringList(v.([]interface{})), cisID) + pool := map[string]interface{}{ + cisGLBPopPoolsPop: k, + cisGLBPopPoolsPoolIDs: poolIds, + } + result = append(result, pool) + } + return result +} + +func flattenDataSourceRegionPools(pools interface{}, geoType string, cisID string) []interface{} { + result := make([]interface{}, 0) + for k, v := range pools.(map[string]interface{}) { + poolIds := convertCisToTfTwoVarSlice(expandStringList(v.([]interface{})), cisID) + pool := map[string]interface{}{ + cisGLBRegionPoolsRegion: k, + cisGLBRegionPoolsPoolIDs: poolIds, + } + result = append(result, pool) + } + return result +} diff --git a/ibm/data_source_ibm_cis_global_load_balancers_test.go b/ibm/data_source_ibm_cis_global_load_balancers_test.go new file mode 100644 index 0000000000..08f42e9200 --- /dev/null +++ b/ibm/data_source_ibm_cis_global_load_balancers_test.go @@ -0,0 +1,34 @@ +package ibm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccIBMCisGLBDataSource_basic(t *testing.T) { + node := "data.ibm_cis_global_load_balancers.test" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMCisGLBDataSourceConfig(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(node, "cis_glb.0.id"), + resource.TestCheckResourceAttrSet(node, "cis_glb.0.glb_id"), + ), + }, + }, + }) +} + +func testAccCheckIBMCisGLBDataSourceConfig() string { + // status filter defaults to empty + return testAccCheckCisGlbConfigCisDSBasic("test", cisDomainStatic) + fmt.Sprintf(` + data "ibm_cis_global_load_balancers" "test" { + cis_id = ibm_cis_global_load_balancer.test.cis_id + domain_id = ibm_cis_global_load_balancer.test.domain_id + }`) +} diff --git a/ibm/provider.go b/ibm/provider.go index b9b0ef349c..b72b475feb 100644 --- a/ibm/provider.go +++ b/ibm/provider.go @@ -169,6 +169,7 @@ func Provider() terraform.ResourceProvider { "ibm_certificate_manager_certificate": dataIBMCertificateManagerCertificate(), "ibm_cis": dataSourceIBMCISInstance(), "ibm_cis_dns_records": dataSourceIBMCISDNSRecords(), + "ibm_cis_global_load_balancers": dataSourceIBMCISGlbs(), "ibm_cis_origin_pools": dataSourceIBMCISOriginPools(), "ibm_cis_healthchecks": dataSourceIBMCISHealthChecks(), "ibm_cis_domain": dataSourceIBMCISDomain(), diff --git a/ibm/resource_ibm_cis_global_load_balancer.go b/ibm/resource_ibm_cis_global_load_balancer.go index 2ceda870ea..5e0b945c0c 100644 --- a/ibm/resource_ibm_cis_global_load_balancer.go +++ b/ibm/resource_ibm_cis_global_load_balancer.go @@ -3,38 +3,61 @@ package ibm import ( "fmt" "log" - "reflect" - "strings" + "github.com/IBM/go-sdk-core/v3/core" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) - v1 "github.com/IBM-Cloud/bluemix-go/api/cis/cisv1" +const ( + cisGLBID = "glb_id" + cisGLBName = "name" + cisGLBFallbackPoolID = "fallback_pool_id" + cisGLBDefaultPoolIDs = "default_pool_ids" + cisGLBDesc = "description" + cisGLBProxied = "proxied" + cisGLBTTL = "ttl" + cisGLBSessionAffinity = "session_affinity" + cisGLBEnabled = "enabled" + cisGLBPopPools = "pop_pools" + cisGLBPopPoolsPop = "pop" + cisGLBPopPoolsPoolIDs = "pool_ids" + cisGLBRegionPools = "region_pools" + cisGLBRegionPoolsRegion = "region" + cisGLBRegionPoolsPoolIDs = "pool_ids" + cisGLBCreatedOn = "created_on" + cisGLBModifiedOn = "modified_on" ) func resourceIBMCISGlb() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ - "cis_id": { + cisID: { Type: schema.TypeString, Description: "CIS instance crn", Required: true, }, - "domain_id": { + cisDomainID: { + Type: schema.TypeString, + Description: "Associated CIS domain", + Required: true, + DiffSuppressFunc: suppressDomainIDDiff, + }, + cisGLBID: { Type: schema.TypeString, - Description: "Associated CIS domain", - Required: true, + Description: "global load balancer id", + Computed: true, }, - "name": { + cisGLBName: { Type: schema.TypeString, Description: "name", Required: true, }, - "fallback_pool_id": { + cisGLBFallbackPoolID: { Type: schema.TypeString, Description: "fallback pool ID", Required: true, }, - "default_pool_ids": { + cisGLBDefaultPoolIDs: { Type: schema.TypeSet, Required: true, Elem: &schema.Schema{ @@ -43,27 +66,28 @@ func resourceIBMCISGlb() *schema.Resource { Description: "List of default Pool IDs", //ValidateFunc: validation.StringLenBetween(1, 32), }, - "description": { + cisGLBDesc: { Type: schema.TypeString, Optional: true, Description: "Description for the load balancer instance", //ValidateFunc: validation.StringLenBetween(0, 1024), }, - "ttl": { + cisGLBTTL: { Type: schema.TypeInt, Optional: true, + Default: 60, ConflictsWith: []string{"proxied"}, Description: "TTL value", // this is set to zero regardless of config when proxied=true }, - "proxied": { + cisGLBProxied: { Type: schema.TypeBool, Optional: true, Default: false, - ConflictsWith: []string{"ttl"}, + ConflictsWith: []string{cisGLBTTL}, Description: "set to true if proxy needs to be enabled", }, - "session_affinity": { + cisGLBSessionAffinity: { Type: schema.TypeString, Optional: true, Default: "none", @@ -71,23 +95,24 @@ func resourceIBMCISGlb() *schema.Resource { ValidateFunc: validateAllowedStringValue([]string{"none", "cookie"}), Description: "Session affinity info", }, - "enabled": { + cisGLBEnabled: { Type: schema.TypeBool, Optional: true, Default: true, Description: "set to true of LB needs to enabled", }, - "pop_pools": { + cisGLBPopPools: { Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "pop": { - Type: schema.TypeString, - Required: true, + cisGLBPopPoolsPop: { + Type: schema.TypeString, + Required: true, + Description: "pop pools region", }, - "pool_ids": { + cisGLBPopPoolsPoolIDs: { Type: schema.TypeList, Required: true, Elem: &schema.Schema{ @@ -98,17 +123,17 @@ func resourceIBMCISGlb() *schema.Resource { }, }, - "region_pools": { + cisGLBRegionPools: { Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "region": { + cisGLBRegionPoolsRegion: { Type: schema.TypeString, Required: true, }, - "pool_ids": { + cisGLBRegionPoolsPoolIDs: { Type: schema.TypeList, Required: true, Elem: &schema.Schema{ @@ -118,209 +143,180 @@ func resourceIBMCISGlb() *schema.Resource { }, }, }, - "created_on": { + cisGLBCreatedOn: { Type: schema.TypeString, Computed: true, Description: "Load balancer creation date", }, - "modified_on": { + cisGLBModifiedOn: { Type: schema.TypeString, Computed: true, Description: "Load balancer modified date", }, }, - Create: resourceCISGlbCreate, - Read: resourceCISGlbRead, - Update: resourceCISGlbUpdate, - Delete: resourceCISGlbDelete, - // No Exists due to errors in CIS API returning incorrect return codes on 404 + Create: resourceCISGlbCreate, + Read: resourceCISGlbRead, + Update: resourceCISGlbUpdate, + Delete: resourceCISGlbDelete, Importer: &schema.ResourceImporter{}, } } func resourceCISGlbCreate(d *schema.ResourceData, meta interface{}) error { - cisClient, err := meta.(ClientSession).CisAPI() + cisClient, err := meta.(ClientSession).CisGLBClientSession() if err != nil { return err } - cisId := d.Get("cis_id").(string) - name := d.Get("name").(string) - zoneId, _, err := convertTftoCisTwoVar(d.Get("domain_id").(string)) - if err != nil { - return err + crn := d.Get(cisID).(string) + zoneID, _, err := convertTftoCisTwoVar(d.Get(cisDomainID).(string)) + cisClient.Crn = core.StringPtr(crn) + cisClient.ZoneIdentifier = core.StringPtr(zoneID) + + tfDefaultPoolIds := expandStringList(d.Get(cisGLBDefaultPoolIDs).(*schema.Set).List()) + defaultPoolIds, _, err := convertTfToCisTwoVarSlice(tfDefaultPoolIds) + fbPoolID := d.Get(cisGLBFallbackPoolID).(string) + fallbackPool, _, err := convertTftoCisTwoVar(fbPoolID) + + opt := cisClient.NewCreateLoadBalancerOptions() + opt.SetName(d.Get(cisGLBName).(string)) + opt.SetDefaultPools(defaultPoolIds) + opt.SetFallbackPool(fallbackPool) + opt.SetProxied(d.Get(cisGLBProxied).(bool)) + opt.SetSessionAffinity(d.Get(cisGLBSessionAffinity).(string)) + + if description, ok := d.GetOk(cisGLBDesc); ok { + opt.SetDescription(description.(string)) } - - var glb *v1.Glb - var glbObj v1.Glb - glbNew := v1.GlbBody{} - glbNew.Name = name - - tfDefaultPools := expandStringList(d.Get("default_pool_ids").(*schema.Set).List()) - defaultPoolIds, _, err := convertTfToCisTwoVarSlice(tfDefaultPools) - glbNew.DefaultPools = defaultPoolIds - // glbNew.RegionPools - // glbNew.PopPools - - fbPoolId := d.Get("fallback_pool_id").(string) - glbNew.FallbackPool, _, err = convertTftoCisTwoVar(fbPoolId) - glbNew.Proxied = d.Get("proxied").(bool) - glbNew.SessionAffinity = d.Get("session_affinity").(string) - - if description, ok := d.GetOk("description"); ok { - glbNew.Desc = description.(string) - } - if ttl, ok := d.GetOk("ttl"); ok { - glbNew.Ttl = ttl.(int) + if ttl, ok := d.GetOk(cisGLBTTL); ok { + opt.SetTTL(int64(ttl.(int))) } - if regionPools, ok := d.GetOk("region_pools"); ok { - expandedRegionPools, err := expandGeoPools(regionPools, "region") + if regionPools, ok := d.GetOk(cisGLBRegionPools); ok { + expandedRegionPools, err := expandGeoPools(regionPools, cisGLBRegionPoolsRegion) if err != nil { return err } - glbNew.RegionPools = expandedRegionPools + opt.SetRegionPools(expandedRegionPools) } - - if popPools, ok := d.GetOk("pop_pools"); ok { - expandedPopPools, err := expandGeoPools(popPools, "pop") + if popPools, ok := d.GetOk(cisGLBPopPools); ok { + expandedPopPools, err := expandGeoPools(popPools, cisGLBPopPoolsPop) if err != nil { return err } - glbNew.PopPools = expandedPopPools + opt.SetPopPools(expandedPopPools) } - glb, err = cisClient.Glbs().CreateGlb(cisId, zoneId, glbNew) + result, resp, err := cisClient.CreateLoadBalancer(opt) if err != nil { - log.Printf("CreateGlbs Failed %s\n", err) + log.Printf("Create GLB failed %s\n", resp) return err } - glbObj = *glb - d.SetId(convertCisToTfThreeVar(glbObj.Id, zoneId, cisId)) - + d.SetId(convertCisToTfThreeVar(*result.Result.ID, zoneID, crn)) return resourceCISGlbUpdate(d, meta) } -func expandGeoPools(pool interface{}, geoType string) (map[string][]string, error) { - pools := pool.(*schema.Set).List() - expandPool := make(map[string][]string) - for _, v := range pools { - locationConfig := v.(map[string]interface{}) - location := locationConfig[geoType].(string) - if _, p := expandPool[location]; !p { - geoPools := expandStringList(locationConfig["pool_ids"].([]interface{})) - expandPool[location], _, _ = convertTfToCisTwoVarSlice(geoPools) - } else { - return nil, fmt.Errorf("duplicate entry specified for %s pool in location %q. each location must only be specified once", geoType, location) - } - } - return expandPool, nil -} func resourceCISGlbRead(d *schema.ResourceData, meta interface{}) error { - cisClient, err := meta.(ClientSession).CisAPI() + cisClient, err := meta.(ClientSession).CisGLBClientSession() if err != nil { return err } + // Extract CIS Ids from TF Id - glbId, zoneId, cisId, err := convertTfToCisThreeVar(d.Id()) + glbID, zoneID, crn, err := convertTfToCisThreeVar(d.Id()) if err != nil { return err } - var glb *v1.Glb - glb, err = cisClient.Glbs().GetGlb(cisId, zoneId, glbId) + cisClient.Crn = core.StringPtr(crn) + cisClient.ZoneIdentifier = core.StringPtr(zoneID) + + opt := cisClient.NewGetLoadBalancerSettingsOptions(glbID) + + result, resp, err := cisClient.GetLoadBalancerSettings(opt) if err != nil { - if checkCisGlbDeleted(d, meta, err, glb) { - d.SetId("") - return nil - } - log.Printf("[WARN] Error getting zone during GlbRead %v\n", err) + log.Printf("[WARN] GLB Read failed: %v\n", resp) return err } - glbObj := *glb - d.Set("cis_id", cisId) - d.Set("domain_id", convertCisToTfTwoVar(zoneId, cisId)) - d.Set("name", glbObj.Name) - d.Set("default_pool_ids", convertCisToTfTwoVarSlice(glbObj.DefaultPools, cisId)) - d.Set("description", glbObj.Desc) - d.Set("fallback_pool_id", convertCisToTfTwoVar(glbObj.FallbackPool, cisId)) - d.Set("ttl", glbObj.Ttl) - d.Set("proxied", glbObj.Proxied) - d.Set("enabled", glbObj.Enabled) - d.Set("session_affinity", glbObj.SessionAffinity) - if err := d.Set("pop_pools", flattenPools(glbObj.PopPools, "pop", cisId)); err != nil { - log.Printf("[WARN] Error setting pop_pools on cis load balancer %q: %s", d.Id(), err) - } - - if err := d.Set("region_pools", flattenPools(glbObj.RegionPools, "region", cisId)); err != nil { - log.Printf("[WARN] Error setting region_pools on cis load balancer %q: %s", d.Id(), err) - } + glbObj := result.Result + d.Set(cisID, crn) + d.Set(cisDomainID, zoneID) + d.Set(cisGLBID, glbObj.ID) + d.Set(cisGLBName, glbObj.Name) + d.Set(cisGLBDefaultPoolIDs, convertCisToTfTwoVarSlice(glbObj.DefaultPools, crn)) + d.Set(cisGLBDesc, glbObj.Description) + d.Set(cisGLBFallbackPoolID, convertCisToTfTwoVar(*glbObj.FallbackPool, crn)) + d.Set(cisGLBTTL, glbObj.TTL) + d.Set(cisGLBProxied, glbObj.Proxied) + d.Set(cisGLBEnabled, glbObj.Enabled) + d.Set(cisGLBSessionAffinity, glbObj.SessionAffinity) + flattenPopPools := flattenPools( + glbObj.PopPools, cisGLBPopPoolsPop, crn) + d.Set(cisGLBPopPools, flattenPopPools) + flattenRegionPools := flattenPools( + glbObj.RegionPools, cisGLBRegionPoolsRegion, crn) + d.Set(cisGLBRegionPools, flattenRegionPools) return nil } -func flattenPools(pools map[string][]string, geoType string, cisId string) []interface{} { - result := make([]interface{}, 0) - for k, v := range pools { - pool := map[string]interface{}{ - geoType: k, - "pool_ids": convertCisToTfTwoVarSlice(v, cisId), - } - result = append(result, pool) - } - return result -} func resourceCISGlbUpdate(d *schema.ResourceData, meta interface{}) error { - cisClient, err := meta.(ClientSession).CisAPI() + cisClient, err := meta.(ClientSession).CisGLBClientSession() if err != nil { return err } // Extract CIS Ids from TF Id - glbId, zoneId, cisId, err := convertTfToCisThreeVar(d.Id()) + glbID, zoneID, crn, err := convertTfToCisThreeVar(d.Id()) if err != nil { return err } - glbUpdate := v1.GlbBody{} + cisClient.Crn = core.StringPtr(crn) + cisClient.ZoneIdentifier = core.StringPtr(zoneID) - if d.HasChange("name") || d.HasChange("default_pool_ids") || d.HasChange("fallback_pool_id") || d.HasChange("proxied") || d.HasChange("session_affinity") || d.HasChange("description") || d.HasChange("ttl") || d.HasChange("enabled") || d.HasChange("pop_pools") || d.HasChange("region_pools") { + if d.HasChange(cisGLBName) || d.HasChange(cisGLBDefaultPoolIDs) || + d.HasChange(cisGLBFallbackPoolID) || d.HasChange(cisGLBProxied) || + d.HasChange(cisGLBSessionAffinity) || d.HasChange(cisGLBDesc) || + d.HasChange(cisGLBTTL) || d.HasChange(cisGLBEnabled) || + d.HasChange(cisGLBPopPools) || d.HasChange(cisGLBRegionPools) { - name := d.Get("name").(string) - glbUpdate.Name = name - tfDefaultPools := expandStringList(d.Get("default_pool_ids").(*schema.Set).List()) + tfDefaultPools := expandStringList(d.Get(cisGLBDefaultPoolIDs).(*schema.Set).List()) defaultPoolIds, _, err := convertTfToCisTwoVarSlice(tfDefaultPools) - glbUpdate.DefaultPools = defaultPoolIds - fbPoolId := d.Get("fallback_pool_id").(string) - glbUpdate.FallbackPool, _, err = convertTftoCisTwoVar(fbPoolId) - glbUpdate.Proxied = d.Get("proxied").(bool) - glbUpdate.SessionAffinity = d.Get("session_affinity").(string) - - if description, ok := d.GetOk("description"); ok { - glbUpdate.Desc = description.(string) + fbPoolID := d.Get(cisGLBFallbackPoolID).(string) + fallbackPool, _, _ := convertTftoCisTwoVar(fbPoolID) + + opt := cisClient.NewEditLoadBalancerOptions(glbID) + opt.SetName(d.Get(cisGLBName).(string)) + opt.SetProxied(d.Get(cisGLBProxied).(bool)) + opt.SetSessionAffinity(d.Get(cisGLBSessionAffinity).(string)) + opt.SetDefaultPools(defaultPoolIds) + opt.SetFallbackPool(fallbackPool) + if description, ok := d.GetOk(cisGLBDesc); ok { + opt.SetDescription(description.(string)) } - if ttl, ok := d.GetOk("ttl"); ok { - glbUpdate.Ttl = ttl.(int) + if ttl, ok := d.GetOk(cisGLBTTL); ok { + opt.SetTTL(int64(ttl.(int))) } - if enabled, ok := d.GetOk("enabled"); ok { - glbUpdate.Enabled = enabled.(bool) + if enabled, ok := d.GetOk(cisGLBEnabled); ok { + opt.SetEnabled(enabled.(bool)) } - if regionPools, ok := d.GetOk("region_pools"); ok { - expandedRegionPools, err := expandGeoPools(regionPools, "region") + if regionPools, ok := d.GetOk(cisGLBRegionPools); ok { + expandedRegionPools, err := expandGeoPools(regionPools, cisGLBRegionPoolsRegion) if err != nil { return err } - glbUpdate.RegionPools = expandedRegionPools + opt.SetRegionPools(expandedRegionPools) } - - if popPools, ok := d.GetOk("pop_pools"); ok { - expandedPopPools, err := expandGeoPools(popPools, "pop") + if popPools, ok := d.GetOk(cisGLBPopPools); ok { + expandedPopPools, err := expandGeoPools(popPools, cisGLBPopPoolsPop) if err != nil { return err } - glbUpdate.PopPools = expandedPopPools + opt.SetPopPools(expandedPopPools) } - _, err = cisClient.Glbs().UpdateGlb(cisId, zoneId, glbId, glbUpdate) + + _, resp, err := cisClient.EditLoadBalancer(opt) if err != nil { - log.Printf("[WARN] Error getting zone during GlbUpdate %v\n", err) + log.Printf("[WARN] Error updating GLB %v\n", resp) return err } } @@ -329,54 +325,80 @@ func resourceCISGlbUpdate(d *schema.ResourceData, meta interface{}) error { } func resourceCISGlbDelete(d *schema.ResourceData, meta interface{}) error { - cisClient, err := meta.(ClientSession).CisAPI() + cisClient, err := meta.(ClientSession).CisGLBClientSession() if err != nil { return err } - glbId, zoneId, cisId, _ := convertTfToCisThreeVar(d.Id()) - var glb *v1.Glb - emptyGlb := new(v1.Glb) - - glb, err = cisClient.Glbs().GetGlb(cisId, zoneId, glbId) + // Extract CIS Ids from TF Id + glbID, zoneID, crn, err := convertTfToCisThreeVar(d.Id()) if err != nil { - if checkCisGlbDeleted(d, meta, err, glb) { - d.SetId("") - return nil - } - log.Printf("[WARN] Error getting zone during GlbRead %v\n", err) return err } + cisClient.Crn = core.StringPtr(crn) + cisClient.ZoneIdentifier = core.StringPtr(zoneID) + opt := cisClient.NewDeleteLoadBalancerOptions(glbID) - glbObj := *glb - if !reflect.DeepEqual(emptyGlb, glbObj) { - err = cisClient.Glbs().DeleteGlb(cisId, zoneId, glbId) - if err != nil { - log.Printf("[WARN] DeleteGlb Failed %s\n", err) - return err - } + result, resp, err := cisClient.DeleteLoadBalancer(opt) + if err != nil { + log.Printf("[WARN] Error deleting GLB %v\n", resp) + return err } - - d.SetId("") + log.Printf("Deletion successful : %s", *result.Result.ID) return nil } -func checkCisGlbDeleted(d *schema.ResourceData, meta interface{}, errCheck error, glb *v1.Glb) bool { - // Check if error is due to removal of Cis resource and hence all subresources - if strings.Contains(errCheck.Error(), "Object not found") || - strings.Contains(errCheck.Error(), "status code: 404") || - strings.Contains(errCheck.Error(), "Invalid zone identifier") { //code 400 - log.Printf("[WARN] Removing resource from state because it's not found via the CIS API") - return true +func resourceCISGlbExists(d *schema.ResourceData, meta interface{}) (bool, error) { + cisClient, err := meta.(ClientSession).CisGLBClientSession() + if err != nil { + return false, err + } + // Extract CIS Ids from TF Id + glbID, zoneID, crn, err := convertTfToCisThreeVar(d.Id()) + if err != nil { + return false, err + } + cisClient.Crn = core.StringPtr(crn) + cisClient.ZoneIdentifier = core.StringPtr(zoneID) + opt := cisClient.NewGetLoadBalancerSettingsOptions(glbID) + + _, response, err := cisClient.GetLoadBalancerSettings(opt) + if err != nil { + if response != nil && response.StatusCode == 404 { + log.Printf("global load balancer does not exist.") + return false, nil + } + log.Printf("[WARN] Error getting GLB %v\n", response) + return false, err } - _, _, cisId, _ := convertTfToCisThreeVar(d.Id()) - exists, errNew := rcInstanceExists(cisId, "ibm_cis", meta) - if errNew != nil { - log.Printf("resourceCISglbRead - Failure validating service exists %s\n", errNew) - return false + return true, nil +} + +func expandGeoPools(pool interface{}, geoType string) (map[string][]string, error) { + pools := pool.(*schema.Set).List() + expandPool := make(map[string][]string) + for _, v := range pools { + locationConfig := v.(map[string]interface{}) + location := locationConfig[geoType].(string) + if _, p := expandPool[location]; !p { + geoPools := expandStringList(locationConfig[cisGLBRegionPoolsPoolIDs].([]interface{})) + expandPool[location], _, _ = convertTfToCisTwoVarSlice(geoPools) + } else { + return nil, fmt.Errorf("duplicate entry specified for %s pool in location %q. "+ + "each location must only be specified once", geoType, location) + } } - if !exists { - log.Printf("[WARN] Removing glb from state because parent cis instance is in removed state") - return true + return expandPool, nil +} + +func flattenPools(pools interface{}, geoType string, cisID string) []interface{} { + result := make([]interface{}, 0) + for k, v := range pools.(map[string]interface{}) { + poolIds := convertCisToTfTwoVarSlice(expandStringList(v.([]interface{})), cisID) + pool := map[string]interface{}{ + cisGLBRegionPoolsRegion: k, + cisGLBPopPoolsPoolIDs: poolIds, + } + result = append(result, pool) } - return false + return result } diff --git a/ibm/resource_ibm_cis_global_load_balancer_test.go b/ibm/resource_ibm_cis_global_load_balancer_test.go index a363c76b63..39fa0a032b 100644 --- a/ibm/resource_ibm_cis_global_load_balancer_test.go +++ b/ibm/resource_ibm_cis_global_load_balancer_test.go @@ -1,14 +1,11 @@ package ibm import ( - //"errors" "fmt" "log" "testing" - //"regexp" - - //"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/IBM/go-sdk-core/v3/core" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" ) @@ -26,7 +23,7 @@ func TestAccIBMCisGlb_Basic(t *testing.T) { CheckDestroy: testAccCheckCisGlbDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckCisGlbConfigCisDS_Basic("test", cisDomainStatic), + Config: testAccCheckCisGlbConfigCisDSBasic("test", cisDomainStatic), ExpectNonEmptyPlan: true, Check: resource.ComposeTestCheckFunc( testAccCheckCisGlbExists(name, &glb), @@ -38,7 +35,7 @@ func TestAccIBMCisGlb_Basic(t *testing.T) { ), }, { - Config: testAccCheckCisGlbConfigCisDS_Update("test", cisDomainStatic), + Config: testAccCheckCisGlbConfigCisDSUpdate("test", cisDomainStatic), ExpectNonEmptyPlan: true, Check: resource.ComposeTestCheckFunc( testAccCheckCisGlbExists(name, &glb), @@ -65,7 +62,7 @@ func TestAccIBMCisGlb_CreateAfterManualDestroy(t *testing.T) { CheckDestroy: testAccCheckCisGlbDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckCisGlbConfigCisDS_Basic("test", cisDomainStatic), + Config: testAccCheckCisGlbConfigCisDSBasic("test", cisDomainStatic), Check: resource.ComposeTestCheckFunc( testAccCheckCisGlbExists(name, &glbOne), testAccCisGlbManuallyDelete(&glbOne), @@ -73,7 +70,7 @@ func TestAccIBMCisGlb_CreateAfterManualDestroy(t *testing.T) { ExpectNonEmptyPlan: true, }, { - Config: testAccCheckCisGlbConfigCisDS_Basic("test", cisDomainStatic), + Config: testAccCheckCisGlbConfigCisDSBasic("test", cisDomainStatic), Check: resource.ComposeTestCheckFunc( testAccCheckCisGlbExists(name, &glbTwo), func(state *terraform.State) error { @@ -101,7 +98,7 @@ func TestAccIBMCisGlb_CreateAfterManualCisRIDestroy(t *testing.T) { CheckDestroy: testAccCheckCisGlbDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckCisGlbConfigCisRI_Basic("test", cisDomainTest), + Config: testAccCheckCisGlbConfigCisRIBasic("test", cisDomainTest), Check: resource.ComposeTestCheckFunc( testAccCheckCisGlbExists(name, &glbOne), testAccCisGlbManuallyDelete(&glbOne), @@ -113,8 +110,8 @@ func TestAccIBMCisGlb_CreateAfterManualCisRIDestroy(t *testing.T) { for _, r := range state.RootModule().Resources { if r.Type == "ibm_cis_pool" { log.Printf("[WARN] Manually removing pool") - poolId, cisId, _ := convertTftoCisTwoVar(r.Primary.ID) - _ = cisClient.Pools().DeletePool(cisId, poolId) + poolID, cisID, _ := convertTftoCisTwoVar(r.Primary.ID) + _ = cisClient.Pools().DeletePool(cisID, poolID) } @@ -122,9 +119,9 @@ func TestAccIBMCisGlb_CreateAfterManualCisRIDestroy(t *testing.T) { for _, r := range state.RootModule().Resources { if r.Type == "ibm_cis_domain" { log.Printf("[WARN] Manually removing domain") - zoneId, cisId, _ := convertTftoCisTwoVar(r.Primary.ID) - _ = cisClient.Zones().DeleteZone(cisId, zoneId) - cisPtr := &cisId + zoneID, cisID, _ := convertTftoCisTwoVar(r.Primary.ID) + _ = cisClient.Zones().DeleteZone(cisID, zoneID) + cisPtr := &cisID log.Printf("[WARN] Manually removing Cis Instance") _ = testAccCisInstanceManuallyDeleteUnwrapped(state, cisPtr) } @@ -136,7 +133,7 @@ func TestAccIBMCisGlb_CreateAfterManualCisRIDestroy(t *testing.T) { ExpectNonEmptyPlan: true, }, { - Config: testAccCheckCisGlbConfigCisRI_Basic("test", cisDomainTest), + Config: testAccCheckCisGlbConfigCisRIBasic("test", cisDomainTest), Check: resource.ComposeTestCheckFunc( testAccCheckCisGlbExists(name, &glbTwo), func(state *terraform.State) error { @@ -159,18 +156,16 @@ func TestAccIBMCisGlb_import(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckCisGlbConfigCisDS_Basic("test", cisDomainStatic), + { + Config: testAccCheckCisGlbConfigCisDSBasic("test", cisDomainStatic), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(name, "proxied", "false"), // default value ), }, - resource.TestStep{ + { ResourceName: name, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "wait_time_minutes"}, }, }, }) @@ -191,8 +186,6 @@ func TestAccIBMCisGlb_SessionAffinity(t *testing.T) { testAccCheckCisGlbExists(name, &glb), // explicitly verify that our session_affinity has been set resource.TestCheckResourceAttr(name, "session_affinity", "cookie"), - //resource.TestCheckResourceAttr(name, "pop_pools.#", "0"), - //resource.TestCheckResourceAttr(name, "region_pools.#", "0"), ), }, }, @@ -200,7 +193,7 @@ func TestAccIBMCisGlb_SessionAffinity(t *testing.T) { } func testAccCheckCisGlbDestroy(s *terraform.State) error { - cisClient, err := testAccProvider.Meta().(ClientSession).CisAPI() + cisClient, err := testAccProvider.Meta().(ClientSession).CisGLBClientSession() if err != nil { return err } @@ -208,8 +201,16 @@ func testAccCheckCisGlbDestroy(s *terraform.State) error { if rs.Type != "ibm_cis_global_load_balancer" { continue } - glbId, zoneId, cisId, _ := convertTfToCisThreeVar(rs.Primary.ID) - _, err = cisClient.Glbs().GetGlb(cisId, zoneId, glbId) + glbID, zoneID, crn, err := convertTfToCisThreeVar(rs.Primary.ID) + if err != nil { + return err + } + cisClient.Crn = core.StringPtr(crn) + cisClient.ZoneIdentifier = core.StringPtr(zoneID) + + opt := cisClient.NewGetLoadBalancerSettingsOptions(glbID) + + _, _, err = cisClient.GetLoadBalancerSettings(opt) if err == nil { return fmt.Errorf("Global Load balancer still exists") } @@ -218,16 +219,22 @@ func testAccCheckCisGlbDestroy(s *terraform.State) error { return nil } -func testAccCisGlbManuallyDelete(tfGlbId *string) resource.TestCheckFunc { +func testAccCisGlbManuallyDelete(tfGlbID *string) resource.TestCheckFunc { return func(s *terraform.State) error { - cisClient, err := testAccProvider.Meta().(ClientSession).CisAPI() + cisClient, err := testAccProvider.Meta().(ClientSession).CisGLBClientSession() if err != nil { return err } - tfGlb := *tfGlbId + tfGlb := *tfGlbID log.Printf("[WARN] Manually removing glb") - glbId, zoneId, cisId, _ := convertTfToCisThreeVar(tfGlb) - err = cisClient.Glbs().DeleteGlb(cisId, zoneId, glbId) + glbID, zoneID, crn, err := convertTfToCisThreeVar(tfGlb) + if err != nil { + return err + } + cisClient.Crn = core.StringPtr(crn) + cisClient.ZoneIdentifier = core.StringPtr(zoneID) + opt := cisClient.NewDeleteLoadBalancerOptions(glbID) + _, _, err = cisClient.DeleteLoadBalancer(opt) if err != nil { return fmt.Errorf("Error deleting IBMCISGlb Record: %s", err) } @@ -235,7 +242,7 @@ func testAccCisGlbManuallyDelete(tfGlbId *string) resource.TestCheckFunc { } } -func testAccCheckCisGlbExists(n string, tfGlbId *string) resource.TestCheckFunc { +func testAccCheckCisGlbExists(n string, tfGlbID *string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -245,18 +252,29 @@ func testAccCheckCisGlbExists(n string, tfGlbId *string) resource.TestCheckFunc if rs.Primary.ID == "" { return fmt.Errorf("No Load Balancer ID is set") } - glbId, zoneId, cisId, _ := convertTfToCisThreeVar(rs.Primary.ID) - cisClient, err := testAccProvider.Meta().(ClientSession).CisAPI() - foundGlb, err := cisClient.Glbs().GetGlb(rs.Primary.Attributes["cis_id"], zoneId, glbId) + cisClient, err := testAccProvider.Meta().(ClientSession).CisGLBClientSession() if err != nil { return err } - *tfGlbId = convertCisToTfThreeVar(foundGlb.Id, zoneId, cisId) + glbID, zoneID, crn, err := convertTfToCisThreeVar(rs.Primary.ID) + if err != nil { + return err + } + cisClient.Crn = core.StringPtr(crn) + cisClient.ZoneIdentifier = core.StringPtr(zoneID) + + opt := cisClient.NewGetLoadBalancerSettingsOptions(glbID) + + result, _, err := cisClient.GetLoadBalancerSettings(opt) + if err != nil { + return fmt.Errorf("Global Load balancer exists") + } + *tfGlbID = convertCisToTfThreeVar(*result.Result.ID, zoneID, crn) return nil } } -func testAccCheckCisGlbConfigCisDS_Basic(id string, cisDomain string) string { +func testAccCheckCisGlbConfigCisDSBasic(id string, cisDomain string) string { return testAccCheckCisPoolConfigFullySpecified(id, cisDomain) + fmt.Sprintf(` resource "ibm_cis_global_load_balancer" "%[1]s" { cis_id = data.ibm_cis.cis.id @@ -265,10 +283,10 @@ func testAccCheckCisGlbConfigCisDS_Basic(id string, cisDomain string) string { fallback_pool_id = ibm_cis_origin_pool.origin_pool.id default_pool_ids = [ibm_cis_origin_pool.origin_pool.id] } - `, id, cisDomainStatic, cisInstance) + `, id, cisDomainStatic) } -func testAccCheckCisGlbConfigCisDS_Update(id string, cisDomain string) string { +func testAccCheckCisGlbConfigCisDSUpdate(id string, cisDomain string) string { return testAccCheckCisPoolConfigFullySpecified(id, cisDomain) + fmt.Sprintf(` resource "ibm_cis_global_load_balancer" "%[1]s" { cis_id = data.ibm_cis.cis.id @@ -285,10 +303,10 @@ func testAccCheckCisGlbConfigCisDS_Update(id string, cisDomain string) string { pool_ids = [ibm_cis_origin_pool.origin_pool.id] } } - `, id, cisDomainStatic, cisInstance) + `, id, cisDomainStatic) } -func testAccCheckCisGlbConfigCisRI_Basic(id string, cisDomain string) string { +func testAccCheckCisGlbConfigCisRIBasic(id string, cisDomain string) string { return testAccCheckCisPoolConfigCisRIBasic(id, cisDomain) + fmt.Sprintf(` resource "ibm_cis_global_load_balancer" "%[1]s" { cis_id = ibm_cis.cis.id @@ -296,7 +314,7 @@ func testAccCheckCisGlbConfigCisRI_Basic(id string, cisDomain string) string { name = "%[2]s" fallback_pool_id = ibm_cis_origin_pool.origin_pool.id default_pool_ids = [ibm_cis_origin_pool.origin_pool.id] - } + } `, id, cisDomain, "testacc_ds_cis") } @@ -310,5 +328,5 @@ func testAccCheckCisGlbConfigSessionAffinity(id string, cisDomainStatic string) default_pool_ids = [ibm_cis_origin_pool.origin_pool.id] session_affinity = "cookie" } - `, id, cisDomainStatic, cisInstance) + `, id, cisDomainStatic) } diff --git a/website/docs/d/cis_global_load_balancers.html.markdown b/website/docs/d/cis_global_load_balancers.html.markdown new file mode 100644 index 0000000000..2d84527022 --- /dev/null +++ b/website/docs/d/cis_global_load_balancers.html.markdown @@ -0,0 +1,51 @@ +--- +layout: "ibm" +page_title: "IBM: ibm_cis_global_load_balancers" +sidebar_current: "docs-ibm-datasources-cis-global_load_balancers" +description: |- +Manages IBM Cloud Internet Services Global Load Balancers resource. +--- + +# ibm_cis_global_load_balancers + +Import the details of an existing IBM Cloud Internet Service global load balancers as a read-only data source. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. + +## Example Usage + +```hcl + +data "ibm_cis_global_load_balancers" "test" { + cis_id = var.cis_crn + domain_id = var.zone_id +} + +``` + +## Argument Reference + +The following arguments are supported: + +- `cis_id` - (Required, string) The resource crn id of the CIS on which zones were created. +- `domain_id` - (Required, string) The ID of the domain to retrive the load balancers from. + +## Attribute Reference + +The following attributes are exported: + +- `id` - Load balancer ID, domain id and CRN. Ex. id:domain-id:crn +- `glb_id` - Load balancer ID. +- `name` - The DNS name to associate with the load balancer. This can be a hostname, e.g. "www" or the fully qualified name "www.example.com". "example.com" is also accepted. +- `fallback_pool_id` - The pool ID to use when all other pools are detected as unhealthy. +- `default_pool_ids` - A list of pool IDs ordered by their failover priority. Used whenever region/pop pools are not defined. +- `description` - Free text description. +- `proxied` - Whether the hostname gets ibm's origin protection. Defaults to `false`. +- `session_affinity` - Associates all requests coming from an end-user with a single origin. ibm will set a cookie on the initial response to the client, such that consequent requests with the cookie in the request will go to the same origin, so long as it is available. +- `ttl` - Time to live (TTL) of the DNS entry for the IP address returned by this load balancer. +- `enabled` - Indicates if the load balancer is enabled or not. + Region and pop pools are not currently implemented in this version of the provider. +- `region_pools` - A set containing mappings of region/country codes to a list of pool IDs (ordered by their failover priority) for the given region. + - `region` - A region code. Multiple entries should not be specified with the same region. + - `pool_ids` - A list of pool IDs in failover priority to use in the given region. +- `pop_pools` - A set containing mappings of IBM Point-of-Presence (PoP) identifiers to a list of pool IDs (ordered by their failover priority) for the PoP (datacenter). This feature is only available to enterprise customers. + - `pop` - A 3-letter code for the Point-of-Presence.Multiple entries should not be specified with the same PoP. + - `pool_ids` - A list of pool IDs in failover priority to use for traffic reaching the given PoP. diff --git a/website/docs/r/cis_global_load_balancer.html.markdown b/website/docs/r/cis_global_load_balancer.html.markdown index 85b9b768a9..63279e2bf2 100644 --- a/website/docs/r/cis_global_load_balancer.html.markdown +++ b/website/docs/r/cis_global_load_balancer.html.markdown @@ -8,7 +8,7 @@ description: |- # ibm_cis_global_load_balancer -Provides a IBM CIS Global Load Balancer resource. This sits in front of a number of defined pools of origins, directs traffic to available origins and provides various options for geographically-aware load balancing. This resource is associated with an IBM Cloud Internet Services instance, a CIS Domain resource and CIS Origin pool resources. +Provides a IBM CIS Global Load Balancer resource. This sits in front of a number of defined pools of origins, directs traffic to available origins and provides various options for geographically-aware load balancing. This resource is associated with an IBM Cloud Internet Services instance, a CIS Domain resource and CIS Origin pool resources. ## Example Usage @@ -29,7 +29,7 @@ resource "ibm_cis_global_load_balancer" "example" { region="WEU" pool_ids = [ibm_cis_origin_pool.example.id] } - pop_pools{ + pop_pools{ pop="LAX" pool_ids = [ibm_cis_origin_pool.example.id] } @@ -50,47 +50,47 @@ resource "ibm_cis_origin_pool" "example" { The following arguments are supported: -* `cis_id` - (Required,string) The ID of the CIS service instance -* `domain_id` - (Required,string) The ID of the domain to add the load balancer to. -* `name` - (Required,string) The DNS name to associate with the load balancer. This can be a hostname, e.g. "www" or the fully qualified name "www.example.com". "example.com" is also accepted. -* `fallback_pool_id` - (Required,string) The pool ID to use when all other pools are detected as unhealthy. -* `default_pool_ids` - (Required,map) A list of pool IDs ordered by their failover priority. Used whenever region/pop pools are not defined. -* `description` - (Optional,string) Free text description. -* `proxied` - (Optional,bool) Whether the hostname gets ibm's origin protection. Defaults to `false`. -* `session_affinity` - (Optional,string) Associates all requests coming from an end-user with a single origin. ibm will set a cookie on the initial response to the client, such that consequent requests with the cookie in the request will go to the same origin, so long as it is available. -* `ttl` - (Optional,int) Time to live (TTL) of the DNS entry for the IP address returned by this load balancer. -* `enabled` - (Optional,bool) Indicates if the load balancer is enabled or not. -Region and pop pools are not currently implemented in this version of the provider. -* `region_pools` - (Optional,set) A set containing mappings of region/country codes to a list of pool IDs (ordered by their failover priority) for the given region. - * `region` - (Required,string) A region code. Multiple entries should not be specified with the same region. - * `pool_ids` - (Required,string) A list of pool IDs in failover priority to use in the given region. -* `pop_pools` - (Optional,set) A set containing mappings of IBM Point-of-Presence (PoP) identifiers to a list of pool IDs (ordered by their failover priority) for the PoP (datacenter). This feature is only available to enterprise customers. - * `pop` - (Required,string) A 3-letter code for the Point-of-Presence.Multiple entries should not be specified with the same PoP. - * `pool_ids` - (Required,string) A list of pool IDs in failover priority to use for traffic reaching the given PoP. +- `cis_id` - (Required,string) The ID of the CIS service instance +- `domain_id` - (Required,string) The ID of the domain to add the load balancer to. +- `name` - (Required,string) The DNS name to associate with the load balancer. This can be a hostname, e.g. "www" or the fully qualified name "www.example.com". "example.com" is also accepted. +- `fallback_pool_id` - (Required,string) The pool ID to use when all other pools are detected as unhealthy. +- `default_pool_ids` - (Required,map) A list of pool IDs ordered by their failover priority. Used whenever region/pop pools are not defined. +- `description` - (Optional,string) Free text description. +- `proxied` - (Optional,bool) Whether the hostname gets ibm's origin protection. Defaults to `false`. +- `session_affinity` - (Optional,string) Associates all requests coming from an end-user with a single origin. ibm will set a cookie on the initial response to the client, such that consequent requests with the cookie in the request will go to the same origin, so long as it is available. +- `ttl` - (Optional,int) Time to live (TTL) of the DNS entry for the IP address returned by this load balancer. +- `enabled` - (Optional,bool) Indicates if the load balancer is enabled or not. + Region and pop pools are not currently implemented in this version of the provider. +- `region_pools` - (Optional,set) A set containing mappings of region/country codes to a list of pool IDs (ordered by their failover priority) for the given region. + - `region` - (Required,string) A region code. Multiple entries should not be specified with the same region. + - `pool_ids` - (Required,string) A list of pool IDs in failover priority to use in the given region. +- `pop_pools` - (Optional,set) A set containing mappings of IBM Point-of-Presence (PoP) identifiers to a list of pool IDs (ordered by their failover priority) for the PoP (datacenter). This feature is only available to enterprise customers. + - `pop` - (Required,string) A 3-letter code for the Point-of-Presence.Multiple entries should not be specified with the same PoP. + - `pool_ids` - (Required,string) A list of pool IDs in failover priority to use for traffic reaching the given PoP. ## Attributes Reference The following attributes are exported: -* `id` - Unique identifier for the global load balancer. -`name` - The fully qualified name of the load balancer, e.g. "www.example.com". -* `created_on` - The RFC3339 timestamp of when the load balancer was created. -* `modified_on` - The RFC3339 timestamp of when the load balancer was last modified. +- `id` - Unique identifier for the global load balancer. Ex. :: +- `glb_id` - Unique identifier for the global load balancer. +- `created_on` - The RFC3339 timestamp of when the load balancer was created. +- `modified_on` - The RFC3339 timestamp of when the load balancer was last modified. ## Import -The `ibm_cis_global_load_balancer` resource can be imported using the `id`. The ID is formed from the `Global Load Balancer ID`, the `Domain ID` of the domain and the `CRN` (Cloud Resource Name) concatentated usinga `:` character. +The `ibm_cis_global_load_balancer` resource can be imported using the `id`. The ID is formed from the `Global Load Balancer ID`, the `Domain ID` of the domain and the `CRN` (Cloud Resource Name) concatentated usinga `:` character. -The Domain ID and CRN will be located on the **Overview** page of the Internet Services instance under the **Domain** heading of the UI, or via using the `bx cis` CLI commands. +The Domain ID and CRN will be located on the **Overview** page of the Internet Services instance under the **Domain** heading of the UI, or via using the `ibmcloud cis` CLI commands. -* **Domain ID** is a 32 digit character string of the form: `9caf68812ae9b3f0377fdf986751a78f` +- **Domain ID** is a 32 digit character string of the form: `9caf68812ae9b3f0377fdf986751a78f` -* **CRN** is a 120 digit character string of the form: `crn:v1:bluemix:public:internet-svcs:global:a/4ea1882a2d3401ed1e459979941966ea:31fa970d-51d0-4b05-893e-251cba75a7b3::` - -* **Glb ID** is a 32 digit character string of the form: `57d96f0da6ed76251b475971b097205c`. The id of an existing GLB is not avaiable via the UI. It can be retrieved programatically via the CIS API or via the CLI using the CIS command to list the defined GLBs: `bx cis glbs ` +- **CRN** is a 120 digit character string of the form: `crn:v1:bluemix:public:internet-svcs:global:a/4ea1882a2d3401ed1e459979941966ea:31fa970d-51d0-4b05-893e-251cba75a7b3::` +- **Glb ID** is a 32 digit character string of the form: `57d96f0da6ed76251b475971b097205c`. The id of an existing GLB is not avaiable via the UI. It can be retrieved programatically via the CIS API or via the CLI using the CIS command to list the defined GLBs: `ibmcloud cis glbs ` ``` $ terraform import ibm_cis_global_load_balancer.myorg :: $ terraform import ibm_cis_domain.myorg 57d96f0da6ed76251b475971b097205c:9caf68812ae9b3f0377fdf986751a78f:crn:v1:bluemix:public:internet-svcs:global:a/4ea1882a2d3401ed1e459979941966ea:31fa970d-51d0-4b05-893e-251cba75a7b3:: +``` diff --git a/website/ibm.erb b/website/ibm.erb index 4a384b19e1..f6b846792f 100644 --- a/website/ibm.erb +++ b/website/ibm.erb @@ -74,6 +74,9 @@ > cis_healthchecks + > + cis_global_load_balancers + > cis_origin_pools