Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIS: GLB Pool Development #1959

Merged
merged 2 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/IBM/ibm-cos-sdk-go v1.3.1
github.com/IBM/ibm-cos-sdk-go-config v1.0.0
github.com/IBM/keyprotect-go-client v0.3.5-0.20200325142150-b63163832e26
github.com/IBM/networking-go-sdk v0.8.0
github.com/IBM/networking-go-sdk v0.10.0
github.com/IBM/vpc-go-sdk v0.1.1
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5
github.com/Shopify/sarama v1.26.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ github.com/IBM/keyprotect-go-client v0.3.5-0.20200325142150-b63163832e26 h1:ktAE
github.com/IBM/keyprotect-go-client v0.3.5-0.20200325142150-b63163832e26/go.mod h1:5TwDM/4FRJq1ZOlwQL1xFahLWQ3TveR88VmL1u3njyI=
github.com/IBM/networking-go-sdk v0.8.0 h1:70M3kAYi93SiyjttYGUAXXfiz39F8b2cvaJVih/2MAc=
github.com/IBM/networking-go-sdk v0.8.0/go.mod h1:WB/PjK7LA6VuIOsGjv1gm6WS/Ki6nF8KmycwMU0bgIs=
github.com/IBM/networking-go-sdk v0.10.0 h1:ery9O0Xg7oreFYTxn6x+DEEQT1rkPX2dKyJtJk7KQ3I=
github.com/IBM/networking-go-sdk v0.10.0/go.mod h1:WB/PjK7LA6VuIOsGjv1gm6WS/Ki6nF8KmycwMU0bgIs=
github.com/IBM/vpc-go-sdk v0.1.1 h1:rzYDbHm6IAxLnL9TNk0y9syCSBbDQ/t1kaI7W51faYY=
github.com/IBM/vpc-go-sdk v0.1.1/go.mod h1:P0B/btm8+wm2gkTg1FgN2uwtjztEIJc7Kqq7HeZdBp4=
github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
Expand Down
26 changes: 26 additions & 0 deletions ibm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
cisdnsrecordsv1 "github.com/IBM/networking-go-sdk/dnsrecordsv1"
cisedgefunctionv1 "github.com/IBM/networking-go-sdk/edgefunctionsapiv1"
cisglbhealthcheckv1 "github.com/IBM/networking-go-sdk/globalloadbalancermonitorv1"
cisglbpoolv0 "github.com/IBM/networking-go-sdk/globalloadbalancerpoolsv0"
cissslv1 "github.com/IBM/networking-go-sdk/sslcertificateapiv1"
tg "github.com/IBM/networking-go-sdk/transitgatewayapisv1"
cisratelimitv1 "github.com/IBM/networking-go-sdk/zoneratelimitsv1"
Expand Down Expand Up @@ -190,6 +191,7 @@ type ClientSession interface {
IAMNamespaceAPI() (*ns.IbmCloudFunctionsNamespaceAPIV1, error)
CisZonesV1ClientSession() (*ciszonesv1.ZonesV1, error)
CisDNSRecordClientSession() (*cisdnsrecordsv1.DnsRecordsV1, error)
CisGLBPoolClientSession() (*cisglbpoolv0.GlobalLoadBalancerPoolsV0, error)
CisGLBHealthCheckClientSession() (*cisglbhealthcheckv1.GlobalLoadBalancerMonitorV1, error)
CisRLClientSession() (*cisratelimitv1.ZoneRateLimitsV1, error)
CisEdgeFunctionClientSession() (*cisedgefunctionv1.EdgeFunctionsApiV1, error)
Expand Down Expand Up @@ -319,6 +321,10 @@ type clientSession struct {
cisDNSErr error
cisDNSRecordsClient *cisdnsrecordsv1.DnsRecordsV1

// CIS Global Load Balancer Pool service options
cisGLBPoolErr error
cisGLBPoolClient *cisglbpoolv0.GlobalLoadBalancerPoolsV0

// CIS GLB health check service options
cisGLBHealthCheckErr error
cisGLBHealthCheckClient *cisglbhealthcheckv1.GlobalLoadBalancerMonitorV1
Expand Down Expand Up @@ -536,6 +542,11 @@ func (sess clientSession) CisDNSRecordClientSession() (*cisdnsrecordsv1.DnsRecor
return sess.cisDNSRecordsClient, sess.cisDNSErr
}

// CIS GLB Pool
func (sess clientSession) CisGLBPoolClientSession() (*cisglbpoolv0.GlobalLoadBalancerPoolsV0, error) {
return sess.cisGLBPoolClient, sess.cisGLBPoolErr
}

// CIS GLB Health Check/Monitor
func (sess clientSession) CisGLBHealthCheckClientSession() (*cisglbhealthcheckv1.GlobalLoadBalancerMonitorV1, error) {
return sess.cisGLBHealthCheckClient, sess.cisGLBHealthCheckErr
Expand Down Expand Up @@ -614,6 +625,7 @@ func (c *Config) ClientSession() (interface{}, error) {
session.transitgatewayErr = errEmptyBluemixCredentials
session.iamNamespaceErr = errEmptyBluemixCredentials
session.cisDNSErr = errEmptyBluemixCredentials
session.cisGLBPoolErr = errEmptyBluemixCredentials
session.cisGLBHealthCheckErr = errEmptyBluemixCredentials
session.cisZonesErr = errEmptyBluemixCredentials
session.cisRLErr = errEmptyBluemixCredentials
Expand Down Expand Up @@ -973,6 +985,20 @@ func (c *Config) ClientSession() (interface{}, error) {
session.cisDNSErr = fmt.Errorf("Error occured while configuring CIS DNS Service: %s", session.cisDNSErr)
}

// IBM Network CIS Global load balancer pool
cisGLBPoolOpt := &cisglbpoolv0.GlobalLoadBalancerPoolsV0Options{
URL: cisEndPoint,
Crn: core.StringPtr(""),
Authenticator: authenticator,
}
session.cisGLBPoolClient, session.cisGLBPoolErr =
cisglbpoolv0.NewGlobalLoadBalancerPoolsV0(cisGLBPoolOpt)
if session.cisGLBPoolErr != nil {
session.cisGLBPoolErr =
fmt.Errorf("Error occured while configuring CIS GLB Pool service: %s",
session.cisGLBPoolErr)
}

// IBM Network CIS Global load balancer health check/monitor
cisGLBHealthCheckOpt := &cisglbhealthcheckv1.GlobalLoadBalancerMonitorV1Options{
URL: cisEndPoint,
Expand Down
187 changes: 187 additions & 0 deletions ibm/data_source_ibm_cis_origin_pools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
package ibm

import (
"log"
"time"

"github.com/IBM/go-sdk-core/v3/core"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

const (
cisOriginPools = "cis_origin_pools"
)

func dataSourceIBMCISOriginPools() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMCISGLBPoolsRead,
Importer: &schema.ResourceImporter{},

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{
cisID: {
Type: schema.TypeString,
Required: true,
Description: "DNS Zone CRN",
},
cisOriginPools: {
Type: schema.TypeList,
Description: "Collection of GLB pools detail",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "GLB Pools id",
},
cisGLBPoolID: {
Type: schema.TypeString,
Computed: true,
Description: "GLB Pool id",
},
cisGLBPoolName: {
Type: schema.TypeString,
Description: "name",
Computed: true,
},
cisGLBPoolRegions: {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "List of regions",
},
cisGLBPoolDesc: {
Type: schema.TypeString,
Computed: true,
Description: "Description of the CIS Origin Pool",
},
cisGLBPoolEnabled: {
Type: schema.TypeBool,
Computed: true,
Description: "Boolean value set to true if cis origin pool needs to be enabled",
},
cisGLBPoolMinimumOrigins: {
Type: schema.TypeInt,
Computed: true,
Description: "Minimum number of Origins",
},
cisGLBPoolMonitor: {
Type: schema.TypeString,
Computed: true,
Description: "Monitor value",
},
cisGLBPoolNotificationEMail: {
Type: schema.TypeString,
Computed: true,
Description: "Email address configured to recieve the notifications",
},
cisGLBPoolOrigins: {
Type: schema.TypeList,
Computed: true,
Description: "Origins info",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
cisGLBPoolOriginsName: {
Type: schema.TypeString,
Computed: true,
},
cisGLBPoolOriginsAddress: {
Type: schema.TypeString,
Computed: true,
},
cisGLBPoolOriginsEnabled: {
Type: schema.TypeBool,
Computed: true,
},
cisGLBPoolOriginsWeight: {
Type: schema.TypeFloat,
Computed: true,
},
cisGLBPoolOriginsHealthy: {
Type: schema.TypeBool,
Computed: true,
},
cisGLBPoolOriginsDisabledAt: {
Type: schema.TypeString,
Computed: true,
},
cisGLBPoolOriginsFailureReason: {
Type: schema.TypeString,
Computed: true,
},
},
},
},
cisGLBPoolHealthy: {
Type: schema.TypeBool,
Computed: true,
Description: "Health status",
},
cisGLBPoolCreatedOn: {
Type: schema.TypeString,
Computed: true,
Description: "Creation date info",
},
cisGLBPoolModifiedOn: {
Type: schema.TypeString,
Computed: true,
Description: "Modified date info",
},
},
},
},
},
}
}

func dataSourceIBMCISGLBPoolsRead(d *schema.ResourceData, meta interface{}) error {
cisClient, err := meta.(ClientSession).CisGLBPoolClientSession()
if err != nil {
return err
}

crn := d.Get(cisID).(string)
cisClient.Crn = core.StringPtr(crn)

opt := cisClient.NewListAllLoadBalancerPoolsOptions()
result, resp, err := cisClient.ListAllLoadBalancerPools(opt)
if err != nil {
log.Printf("Error listing global load balancer pools detail: %s", resp)
return err
}

pools := make([]map[string]interface{}, 0)
for _, instance := range result.Result {
pool := map[string]interface{}{}
pool["id"] = convertCisToTfTwoVar(*instance.ID, crn)
pool[cisGLBPoolID] = *instance.ID
pool[cisGLBPoolName] = *instance.Name
pool[cisGLBPoolOrigins] = flattenOrigins(instance.Origins)
pool[cisGLBPoolRegions] = instance.CheckRegions
pool[cisGLBPoolDesc] = *instance.Description
pool[cisGLBPoolEnabled] = *instance.Enabled
pool[cisGLBPoolNotificationEMail] = *instance.NotificationEmail
pool[cisGLBPoolCreatedOn] = *instance.CreatedOn
pool[cisGLBPoolModifiedOn] = *instance.ModifiedOn
if instance.Monitor != nil {
pool[cisGLBPoolMonitor] = *instance.Monitor
}
if instance.Healthy != nil {
pool[cisGLBPoolHealthy] = *instance.Healthy
}

pools = append(pools, pool)
}
d.SetId(dataSourceIBMCISGLBPoolsID(d))
d.Set(cisOriginPools, pools)
return nil
}

func dataSourceIBMCISGLBPoolsID(d *schema.ResourceData) string {
return time.Now().UTC().String()
}
36 changes: 36 additions & 0 deletions ibm/data_source_ibm_cis_origin_pools_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ibm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccIBMCisPoolsDataSource_Basic(t *testing.T) {
node := "data.ibm_cis_origin_pools.test"
rnd := acctest.RandString(10)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMCisPoolsDataSourceConfig(rnd, cisDomainStatic),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(node, "cis_origin_pools.0.id"),
resource.TestCheckResourceAttrSet(node, "cis_origin_pools.0.pool_id"),
resource.TestCheckResourceAttrSet(node, "cis_origin_pools.0.description"),
),
},
},
})
}

func testAccCheckIBMCisPoolsDataSourceConfig(resourceID, cisDomainStatic string) string {
return testAccCheckCisPoolConfigCisDSBasic(resourceID, cisDomainStatic) + fmt.Sprintf(`
data "ibm_cis_origin_pools" "test" {
cis_id = ibm_cis_origin_pool.origin_pool.cis_id
}
`)
}
1 change: 1 addition & 0 deletions ibm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func Provider() terraform.ResourceProvider {
"ibm_certificate_manager_certificate": dataIBMCertificateManagerCertificate(),
"ibm_cis": dataSourceIBMCISInstance(),
"ibm_cis_dns_records": dataSourceIBMCISDNSRecords(),
"ibm_cis_origin_pools": dataSourceIBMCISOriginPools(),
"ibm_cis_healthchecks": dataSourceIBMCISHealthChecks(),
"ibm_cis_domain": dataSourceIBMCISDomain(),
"ibm_cis_firewall": dataIBMCISFirewallRecord(),
Expand Down
2 changes: 1 addition & 1 deletion ibm/resource_ibm_cis_global_load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func testAccCheckCisGlbConfigCisDS_Update(id string, cisDomain string) string {
}

func testAccCheckCisGlbConfigCisRI_Basic(id string, cisDomain string) string {
return testAccCheckCisPoolConfigCisRI_Basic(id, cisDomain) + fmt.Sprintf(`
return testAccCheckCisPoolConfigCisRIBasic(id, cisDomain) + fmt.Sprintf(`
resource "ibm_cis_global_load_balancer" "%[1]s" {
cis_id = ibm_cis.cis.id
domain_id = ibm_cis_domain.cis_domain.id
Expand Down
Loading