From 4219a0095207781073a1be3e93e3b5b2eebaa051 Mon Sep 17 00:00:00 2001 From: Kumar Ganesan Date: Tue, 13 Oct 2020 10:33:53 +0530 Subject: [PATCH 1/2] CIS: GLB Pool vendor changes --- go.mod | 2 +- go.sum | 2 + .../IBM/networking-go-sdk/common/version.go | 2 +- .../global_load_balancer_pools_v0.go | 1066 +++++++++++++++++ vendor/modules.txt | 3 +- 5 files changed, 1072 insertions(+), 3 deletions(-) create mode 100644 vendor/github.com/IBM/networking-go-sdk/globalloadbalancerpoolsv0/global_load_balancer_pools_v0.go diff --git a/go.mod b/go.mod index 9d5fb27cb8..4a82df9072 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ceae060dcc..46de74ccc5 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/vendor/github.com/IBM/networking-go-sdk/common/version.go b/vendor/github.com/IBM/networking-go-sdk/common/version.go index 4a1b59d340..f9392df3d5 100644 --- a/vendor/github.com/IBM/networking-go-sdk/common/version.go +++ b/vendor/github.com/IBM/networking-go-sdk/common/version.go @@ -17,4 +17,4 @@ package common // Version of the SDK -const Version = "0.8.0" +const Version = "0.10.0" diff --git a/vendor/github.com/IBM/networking-go-sdk/globalloadbalancerpoolsv0/global_load_balancer_pools_v0.go b/vendor/github.com/IBM/networking-go-sdk/globalloadbalancerpoolsv0/global_load_balancer_pools_v0.go new file mode 100644 index 0000000000..74891f1db3 --- /dev/null +++ b/vendor/github.com/IBM/networking-go-sdk/globalloadbalancerpoolsv0/global_load_balancer_pools_v0.go @@ -0,0 +1,1066 @@ +/** + * (C) Copyright IBM Corp. 2020. + * + * 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 globalloadbalancerpoolsv0 : Operations and models for the GlobalLoadBalancerPoolsV0 service +package globalloadbalancerpoolsv0 + +import ( + "encoding/json" + "github.com/IBM/go-sdk-core/v4/core" + common "github.com/IBM/networking-go-sdk/common" + "reflect" +) + +// GlobalLoadBalancerPoolsV0 : GLB Pools +// +// Version: 0.0.1 +type GlobalLoadBalancerPoolsV0 struct { + Service *core.BaseService + + // Full CRN of the service instance. + Crn *string +} + +// DefaultServiceURL is the default URL to make service requests to. +const DefaultServiceURL = "https://api.cis.cloud.ibm.com" + +// DefaultServiceName is the default key used to find external configuration information. +const DefaultServiceName = "global_load_balancer_pools" + +// GlobalLoadBalancerPoolsV0Options : Service options +type GlobalLoadBalancerPoolsV0Options struct { + ServiceName string + URL string + Authenticator core.Authenticator + + // Full CRN of the service instance. + Crn *string `validate:"required"` +} + +// NewGlobalLoadBalancerPoolsV0UsingExternalConfig : constructs an instance of GlobalLoadBalancerPoolsV0 with passed in options and external configuration. +func NewGlobalLoadBalancerPoolsV0UsingExternalConfig(options *GlobalLoadBalancerPoolsV0Options) (globalLoadBalancerPools *GlobalLoadBalancerPoolsV0, err error) { + if options.ServiceName == "" { + options.ServiceName = DefaultServiceName + } + + if options.Authenticator == nil { + options.Authenticator, err = core.GetAuthenticatorFromEnvironment(options.ServiceName) + if err != nil { + return + } + } + + globalLoadBalancerPools, err = NewGlobalLoadBalancerPoolsV0(options) + if err != nil { + return + } + + err = globalLoadBalancerPools.Service.ConfigureService(options.ServiceName) + if err != nil { + return + } + + if options.URL != "" { + err = globalLoadBalancerPools.Service.SetServiceURL(options.URL) + } + return +} + +// NewGlobalLoadBalancerPoolsV0 : constructs an instance of GlobalLoadBalancerPoolsV0 with passed in options. +func NewGlobalLoadBalancerPoolsV0(options *GlobalLoadBalancerPoolsV0Options) (service *GlobalLoadBalancerPoolsV0, err error) { + serviceOptions := &core.ServiceOptions{ + URL: DefaultServiceURL, + Authenticator: options.Authenticator, + } + + err = core.ValidateStruct(options, "options") + if err != nil { + return + } + + baseService, err := core.NewBaseService(serviceOptions) + if err != nil { + return + } + + if options.URL != "" { + err = baseService.SetServiceURL(options.URL) + if err != nil { + return + } + } + + service = &GlobalLoadBalancerPoolsV0{ + Service: baseService, + Crn: options.Crn, + } + + return +} + +// SetServiceURL sets the service URL +func (globalLoadBalancerPools *GlobalLoadBalancerPoolsV0) SetServiceURL(url string) error { + return globalLoadBalancerPools.Service.SetServiceURL(url) +} + +// ListAllLoadBalancerPools : List all pools +// List all configured load balancer pools. +func (globalLoadBalancerPools *GlobalLoadBalancerPoolsV0) ListAllLoadBalancerPools(listAllLoadBalancerPoolsOptions *ListAllLoadBalancerPoolsOptions) (result *ListLoadBalancerPoolsResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(listAllLoadBalancerPoolsOptions, "listAllLoadBalancerPoolsOptions") + if err != nil { + return + } + + pathSegments := []string{"v1", "load_balancers/pools"} + pathParameters := []string{*globalLoadBalancerPools.Crn} + + builder := core.NewRequestBuilder(core.GET) + _, err = builder.ConstructHTTPURL(globalLoadBalancerPools.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range listAllLoadBalancerPoolsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("global_load_balancer_pools", "V0", "ListAllLoadBalancerPools") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = globalLoadBalancerPools.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalListLoadBalancerPoolsResp) + if err != nil { + return + } + response.Result = result + + return +} + +// CreateLoadBalancerPool : Create pool +// Create a new load balancer pool. +func (globalLoadBalancerPools *GlobalLoadBalancerPoolsV0) CreateLoadBalancerPool(createLoadBalancerPoolOptions *CreateLoadBalancerPoolOptions) (result *LoadBalancerPoolResp, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(createLoadBalancerPoolOptions, "createLoadBalancerPoolOptions") + if err != nil { + return + } + + pathSegments := []string{"v1", "load_balancers/pools"} + pathParameters := []string{*globalLoadBalancerPools.Crn} + + builder := core.NewRequestBuilder(core.POST) + _, err = builder.ConstructHTTPURL(globalLoadBalancerPools.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range createLoadBalancerPoolOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("global_load_balancer_pools", "V0", "CreateLoadBalancerPool") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if createLoadBalancerPoolOptions.Name != nil { + body["name"] = createLoadBalancerPoolOptions.Name + } + if createLoadBalancerPoolOptions.CheckRegions != nil { + body["check_regions"] = createLoadBalancerPoolOptions.CheckRegions + } + if createLoadBalancerPoolOptions.Origins != nil { + body["origins"] = createLoadBalancerPoolOptions.Origins + } + if createLoadBalancerPoolOptions.Description != nil { + body["description"] = createLoadBalancerPoolOptions.Description + } + if createLoadBalancerPoolOptions.MinimumOrigins != nil { + body["minimum_origins"] = createLoadBalancerPoolOptions.MinimumOrigins + } + if createLoadBalancerPoolOptions.Enabled != nil { + body["enabled"] = createLoadBalancerPoolOptions.Enabled + } + if createLoadBalancerPoolOptions.Monitor != nil { + body["monitor"] = createLoadBalancerPoolOptions.Monitor + } + if createLoadBalancerPoolOptions.NotificationEmail != nil { + body["notification_email"] = createLoadBalancerPoolOptions.NotificationEmail + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = globalLoadBalancerPools.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalLoadBalancerPoolResp) + if err != nil { + return + } + response.Result = result + + return +} + +// GetLoadBalancerPool : Get pool +// Get a single configured load balancer pool. +func (globalLoadBalancerPools *GlobalLoadBalancerPoolsV0) GetLoadBalancerPool(getLoadBalancerPoolOptions *GetLoadBalancerPoolOptions) (result *LoadBalancerPoolResp, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getLoadBalancerPoolOptions, "getLoadBalancerPoolOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getLoadBalancerPoolOptions, "getLoadBalancerPoolOptions") + if err != nil { + return + } + + pathSegments := []string{"v1", "load_balancers/pools"} + pathParameters := []string{*globalLoadBalancerPools.Crn, *getLoadBalancerPoolOptions.PoolIdentifier} + + builder := core.NewRequestBuilder(core.GET) + _, err = builder.ConstructHTTPURL(globalLoadBalancerPools.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range getLoadBalancerPoolOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("global_load_balancer_pools", "V0", "GetLoadBalancerPool") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = globalLoadBalancerPools.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalLoadBalancerPoolResp) + if err != nil { + return + } + response.Result = result + + return +} + +// DeleteLoadBalancerPool : Delete pool +// Delete a specific configured load balancer pool. +func (globalLoadBalancerPools *GlobalLoadBalancerPoolsV0) DeleteLoadBalancerPool(deleteLoadBalancerPoolOptions *DeleteLoadBalancerPoolOptions) (result *DeleteLoadBalancerPoolResp, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteLoadBalancerPoolOptions, "deleteLoadBalancerPoolOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(deleteLoadBalancerPoolOptions, "deleteLoadBalancerPoolOptions") + if err != nil { + return + } + + pathSegments := []string{"v1", "load_balancers/pools"} + pathParameters := []string{*globalLoadBalancerPools.Crn, *deleteLoadBalancerPoolOptions.PoolIdentifier} + + builder := core.NewRequestBuilder(core.DELETE) + _, err = builder.ConstructHTTPURL(globalLoadBalancerPools.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range deleteLoadBalancerPoolOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("global_load_balancer_pools", "V0", "DeleteLoadBalancerPool") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = globalLoadBalancerPools.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalDeleteLoadBalancerPoolResp) + if err != nil { + return + } + response.Result = result + + return +} + +// EditLoadBalancerPool : Edit pool +// Edit a specific configured load balancer pool. +func (globalLoadBalancerPools *GlobalLoadBalancerPoolsV0) EditLoadBalancerPool(editLoadBalancerPoolOptions *EditLoadBalancerPoolOptions) (result *LoadBalancerPoolResp, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(editLoadBalancerPoolOptions, "editLoadBalancerPoolOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(editLoadBalancerPoolOptions, "editLoadBalancerPoolOptions") + if err != nil { + return + } + + pathSegments := []string{"v1", "load_balancers/pools"} + pathParameters := []string{*globalLoadBalancerPools.Crn, *editLoadBalancerPoolOptions.PoolIdentifier} + + builder := core.NewRequestBuilder(core.PUT) + _, err = builder.ConstructHTTPURL(globalLoadBalancerPools.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range editLoadBalancerPoolOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("global_load_balancer_pools", "V0", "EditLoadBalancerPool") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if editLoadBalancerPoolOptions.Name != nil { + body["name"] = editLoadBalancerPoolOptions.Name + } + if editLoadBalancerPoolOptions.CheckRegions != nil { + body["check_regions"] = editLoadBalancerPoolOptions.CheckRegions + } + if editLoadBalancerPoolOptions.Origins != nil { + body["origins"] = editLoadBalancerPoolOptions.Origins + } + if editLoadBalancerPoolOptions.Description != nil { + body["description"] = editLoadBalancerPoolOptions.Description + } + if editLoadBalancerPoolOptions.MinimumOrigins != nil { + body["minimum_origins"] = editLoadBalancerPoolOptions.MinimumOrigins + } + if editLoadBalancerPoolOptions.Enabled != nil { + body["enabled"] = editLoadBalancerPoolOptions.Enabled + } + if editLoadBalancerPoolOptions.Monitor != nil { + body["monitor"] = editLoadBalancerPoolOptions.Monitor + } + if editLoadBalancerPoolOptions.NotificationEmail != nil { + body["notification_email"] = editLoadBalancerPoolOptions.NotificationEmail + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = globalLoadBalancerPools.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalLoadBalancerPoolResp) + if err != nil { + return + } + response.Result = result + + return +} + +// CreateLoadBalancerPoolOptions : The CreateLoadBalancerPool options. +type CreateLoadBalancerPoolOptions struct { + // name. + Name *string `json:"name,omitempty"` + + // regions check. + CheckRegions []string `json:"check_regions,omitempty"` + + // origins. + Origins []LoadBalancerPoolReqOriginsItem `json:"origins,omitempty"` + + // desc. + Description *string `json:"description,omitempty"` + + // The minimum number of origins that must be healthy for this pool to serve traffic. + MinimumOrigins *int64 `json:"minimum_origins,omitempty"` + + // enabled/disabled. + Enabled *bool `json:"enabled,omitempty"` + + // monitor. + Monitor *string `json:"monitor,omitempty"` + + // notification email. + NotificationEmail *string `json:"notification_email,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewCreateLoadBalancerPoolOptions : Instantiate CreateLoadBalancerPoolOptions +func (*GlobalLoadBalancerPoolsV0) NewCreateLoadBalancerPoolOptions() *CreateLoadBalancerPoolOptions { + return &CreateLoadBalancerPoolOptions{} +} + +// SetName : Allow user to set Name +func (options *CreateLoadBalancerPoolOptions) SetName(name string) *CreateLoadBalancerPoolOptions { + options.Name = core.StringPtr(name) + return options +} + +// SetCheckRegions : Allow user to set CheckRegions +func (options *CreateLoadBalancerPoolOptions) SetCheckRegions(checkRegions []string) *CreateLoadBalancerPoolOptions { + options.CheckRegions = checkRegions + return options +} + +// SetOrigins : Allow user to set Origins +func (options *CreateLoadBalancerPoolOptions) SetOrigins(origins []LoadBalancerPoolReqOriginsItem) *CreateLoadBalancerPoolOptions { + options.Origins = origins + return options +} + +// SetDescription : Allow user to set Description +func (options *CreateLoadBalancerPoolOptions) SetDescription(description string) *CreateLoadBalancerPoolOptions { + options.Description = core.StringPtr(description) + return options +} + +// SetMinimumOrigins : Allow user to set MinimumOrigins +func (options *CreateLoadBalancerPoolOptions) SetMinimumOrigins(minimumOrigins int64) *CreateLoadBalancerPoolOptions { + options.MinimumOrigins = core.Int64Ptr(minimumOrigins) + return options +} + +// SetEnabled : Allow user to set Enabled +func (options *CreateLoadBalancerPoolOptions) SetEnabled(enabled bool) *CreateLoadBalancerPoolOptions { + options.Enabled = core.BoolPtr(enabled) + return options +} + +// SetMonitor : Allow user to set Monitor +func (options *CreateLoadBalancerPoolOptions) SetMonitor(monitor string) *CreateLoadBalancerPoolOptions { + options.Monitor = core.StringPtr(monitor) + return options +} + +// SetNotificationEmail : Allow user to set NotificationEmail +func (options *CreateLoadBalancerPoolOptions) SetNotificationEmail(notificationEmail string) *CreateLoadBalancerPoolOptions { + options.NotificationEmail = core.StringPtr(notificationEmail) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateLoadBalancerPoolOptions) SetHeaders(param map[string]string) *CreateLoadBalancerPoolOptions { + options.Headers = param + return options +} + +// DeleteLoadBalancerPoolOptions : The DeleteLoadBalancerPool options. +type DeleteLoadBalancerPoolOptions struct { + // pool identifier. + PoolIdentifier *string `json:"pool_identifier" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteLoadBalancerPoolOptions : Instantiate DeleteLoadBalancerPoolOptions +func (*GlobalLoadBalancerPoolsV0) NewDeleteLoadBalancerPoolOptions(poolIdentifier string) *DeleteLoadBalancerPoolOptions { + return &DeleteLoadBalancerPoolOptions{ + PoolIdentifier: core.StringPtr(poolIdentifier), + } +} + +// SetPoolIdentifier : Allow user to set PoolIdentifier +func (options *DeleteLoadBalancerPoolOptions) SetPoolIdentifier(poolIdentifier string) *DeleteLoadBalancerPoolOptions { + options.PoolIdentifier = core.StringPtr(poolIdentifier) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteLoadBalancerPoolOptions) SetHeaders(param map[string]string) *DeleteLoadBalancerPoolOptions { + options.Headers = param + return options +} + +// DeleteLoadBalancerPoolRespResult : result. +type DeleteLoadBalancerPoolRespResult struct { + // identifier. + ID *string `json:"id" validate:"required"` +} + + +// UnmarshalDeleteLoadBalancerPoolRespResult unmarshals an instance of DeleteLoadBalancerPoolRespResult from the specified map of raw messages. +func UnmarshalDeleteLoadBalancerPoolRespResult(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DeleteLoadBalancerPoolRespResult) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// EditLoadBalancerPoolOptions : The EditLoadBalancerPool options. +type EditLoadBalancerPoolOptions struct { + // pool identifier. + PoolIdentifier *string `json:"pool_identifier" validate:"required"` + + // name. + Name *string `json:"name,omitempty"` + + // regions check. + CheckRegions []string `json:"check_regions,omitempty"` + + // origins. + Origins []LoadBalancerPoolReqOriginsItem `json:"origins,omitempty"` + + // desc. + Description *string `json:"description,omitempty"` + + // The minimum number of origins that must be healthy for this pool to serve traffic. + MinimumOrigins *int64 `json:"minimum_origins,omitempty"` + + // enabled/disabled. + Enabled *bool `json:"enabled,omitempty"` + + // monitor. + Monitor *string `json:"monitor,omitempty"` + + // notification email. + NotificationEmail *string `json:"notification_email,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewEditLoadBalancerPoolOptions : Instantiate EditLoadBalancerPoolOptions +func (*GlobalLoadBalancerPoolsV0) NewEditLoadBalancerPoolOptions(poolIdentifier string) *EditLoadBalancerPoolOptions { + return &EditLoadBalancerPoolOptions{ + PoolIdentifier: core.StringPtr(poolIdentifier), + } +} + +// SetPoolIdentifier : Allow user to set PoolIdentifier +func (options *EditLoadBalancerPoolOptions) SetPoolIdentifier(poolIdentifier string) *EditLoadBalancerPoolOptions { + options.PoolIdentifier = core.StringPtr(poolIdentifier) + return options +} + +// SetName : Allow user to set Name +func (options *EditLoadBalancerPoolOptions) SetName(name string) *EditLoadBalancerPoolOptions { + options.Name = core.StringPtr(name) + return options +} + +// SetCheckRegions : Allow user to set CheckRegions +func (options *EditLoadBalancerPoolOptions) SetCheckRegions(checkRegions []string) *EditLoadBalancerPoolOptions { + options.CheckRegions = checkRegions + return options +} + +// SetOrigins : Allow user to set Origins +func (options *EditLoadBalancerPoolOptions) SetOrigins(origins []LoadBalancerPoolReqOriginsItem) *EditLoadBalancerPoolOptions { + options.Origins = origins + return options +} + +// SetDescription : Allow user to set Description +func (options *EditLoadBalancerPoolOptions) SetDescription(description string) *EditLoadBalancerPoolOptions { + options.Description = core.StringPtr(description) + return options +} + +// SetMinimumOrigins : Allow user to set MinimumOrigins +func (options *EditLoadBalancerPoolOptions) SetMinimumOrigins(minimumOrigins int64) *EditLoadBalancerPoolOptions { + options.MinimumOrigins = core.Int64Ptr(minimumOrigins) + return options +} + +// SetEnabled : Allow user to set Enabled +func (options *EditLoadBalancerPoolOptions) SetEnabled(enabled bool) *EditLoadBalancerPoolOptions { + options.Enabled = core.BoolPtr(enabled) + return options +} + +// SetMonitor : Allow user to set Monitor +func (options *EditLoadBalancerPoolOptions) SetMonitor(monitor string) *EditLoadBalancerPoolOptions { + options.Monitor = core.StringPtr(monitor) + return options +} + +// SetNotificationEmail : Allow user to set NotificationEmail +func (options *EditLoadBalancerPoolOptions) SetNotificationEmail(notificationEmail string) *EditLoadBalancerPoolOptions { + options.NotificationEmail = core.StringPtr(notificationEmail) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *EditLoadBalancerPoolOptions) SetHeaders(param map[string]string) *EditLoadBalancerPoolOptions { + options.Headers = param + return options +} + +// GetLoadBalancerPoolOptions : The GetLoadBalancerPool options. +type GetLoadBalancerPoolOptions struct { + // pool identifier. + PoolIdentifier *string `json:"pool_identifier" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetLoadBalancerPoolOptions : Instantiate GetLoadBalancerPoolOptions +func (*GlobalLoadBalancerPoolsV0) NewGetLoadBalancerPoolOptions(poolIdentifier string) *GetLoadBalancerPoolOptions { + return &GetLoadBalancerPoolOptions{ + PoolIdentifier: core.StringPtr(poolIdentifier), + } +} + +// SetPoolIdentifier : Allow user to set PoolIdentifier +func (options *GetLoadBalancerPoolOptions) SetPoolIdentifier(poolIdentifier string) *GetLoadBalancerPoolOptions { + options.PoolIdentifier = core.StringPtr(poolIdentifier) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *GetLoadBalancerPoolOptions) SetHeaders(param map[string]string) *GetLoadBalancerPoolOptions { + options.Headers = param + return options +} + +// ListAllLoadBalancerPoolsOptions : The ListAllLoadBalancerPools options. +type ListAllLoadBalancerPoolsOptions struct { + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListAllLoadBalancerPoolsOptions : Instantiate ListAllLoadBalancerPoolsOptions +func (*GlobalLoadBalancerPoolsV0) NewListAllLoadBalancerPoolsOptions() *ListAllLoadBalancerPoolsOptions { + return &ListAllLoadBalancerPoolsOptions{} +} + +// SetHeaders : Allow user to set Headers +func (options *ListAllLoadBalancerPoolsOptions) SetHeaders(param map[string]string) *ListAllLoadBalancerPoolsOptions { + options.Headers = param + return options +} + +// LoadBalancerPoolPackOriginsItem : LoadBalancerPoolPackOriginsItem struct +type LoadBalancerPoolPackOriginsItem struct { + // name. + Name *string `json:"name,omitempty"` + + // address. + Address *string `json:"address,omitempty"` + + // enabled/disabled. + Enabled *bool `json:"enabled,omitempty"` + + // healthy. + Healthy *bool `json:"healthy,omitempty"` + + // weight. + Weight *float64 `json:"weight,omitempty"` + + // Pool origin disabled date. + DisabledAt *string `json:"disabled_at,omitempty"` + + // Reason for failure. + FailureReason *string `json:"failure_reason,omitempty"` +} + + +// UnmarshalLoadBalancerPoolPackOriginsItem unmarshals an instance of LoadBalancerPoolPackOriginsItem from the specified map of raw messages. +func UnmarshalLoadBalancerPoolPackOriginsItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(LoadBalancerPoolPackOriginsItem) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "address", &obj.Address) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "enabled", &obj.Enabled) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "healthy", &obj.Healthy) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "weight", &obj.Weight) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "disabled_at", &obj.DisabledAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "failure_reason", &obj.FailureReason) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// LoadBalancerPoolReqOriginsItem : items. +type LoadBalancerPoolReqOriginsItem struct { + // name. + Name *string `json:"name,omitempty"` + + // address. + Address *string `json:"address,omitempty"` + + // enabled/disabled. + Enabled *bool `json:"enabled,omitempty"` + + // weight. + Weight *float64 `json:"weight,omitempty"` +} + + +// UnmarshalLoadBalancerPoolReqOriginsItem unmarshals an instance of LoadBalancerPoolReqOriginsItem from the specified map of raw messages. +func UnmarshalLoadBalancerPoolReqOriginsItem(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(LoadBalancerPoolReqOriginsItem) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "address", &obj.Address) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "enabled", &obj.Enabled) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "weight", &obj.Weight) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// DeleteLoadBalancerPoolResp : load balancer pool delete response. +type DeleteLoadBalancerPoolResp struct { + // succcess response. + Success *bool `json:"success" validate:"required"` + + // errors. + Errors [][]string `json:"errors" validate:"required"` + + // messages. + Messages [][]string `json:"messages" validate:"required"` + + // result. + Result *DeleteLoadBalancerPoolRespResult `json:"result" validate:"required"` +} + + +// UnmarshalDeleteLoadBalancerPoolResp unmarshals an instance of DeleteLoadBalancerPoolResp from the specified map of raw messages. +func UnmarshalDeleteLoadBalancerPoolResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(DeleteLoadBalancerPoolResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalDeleteLoadBalancerPoolRespResult) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ListLoadBalancerPoolsResp : list load balancer pools response. +type ListLoadBalancerPoolsResp struct { + // success response. + Success *bool `json:"success" validate:"required"` + + // errors. + Errors [][]string `json:"errors" validate:"required"` + + // messages. + Messages [][]string `json:"messages" validate:"required"` + + // result. + Result []LoadBalancerPoolPack `json:"result" validate:"required"` + + // result information. + ResultInfo *ResultInfo `json:"result_info" validate:"required"` +} + + +// UnmarshalListLoadBalancerPoolsResp unmarshals an instance of ListLoadBalancerPoolsResp from the specified map of raw messages. +func UnmarshalListLoadBalancerPoolsResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ListLoadBalancerPoolsResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalLoadBalancerPoolPack) + if err != nil { + return + } + err = core.UnmarshalModel(m, "result_info", &obj.ResultInfo, UnmarshalResultInfo) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// LoadBalancerPoolPack : load balancer pool pack. +type LoadBalancerPoolPack struct { + // identifier. + ID *string `json:"id,omitempty"` + + // created date. + CreatedOn *string `json:"created_on,omitempty"` + + // modified date. + ModifiedOn *string `json:"modified_on,omitempty"` + + // desc. + Description *string `json:"description,omitempty"` + + // name. + Name *string `json:"name" validate:"required"` + + // enabled/disabled. + Enabled *bool `json:"enabled,omitempty"` + + // healthy. + Healthy *bool `json:"healthy,omitempty"` + + // monitor. + Monitor *string `json:"monitor,omitempty"` + + // Minimum origin count. + MinimumOrigins *int64 `json:"minimum_origins,omitempty"` + + // regions check. + CheckRegions []string `json:"check_regions,omitempty"` + + // original. + Origins []LoadBalancerPoolPackOriginsItem `json:"origins" validate:"required"` + + // notification email. + NotificationEmail *string `json:"notification_email,omitempty"` +} + + +// UnmarshalLoadBalancerPoolPack unmarshals an instance of LoadBalancerPoolPack from the specified map of raw messages. +func UnmarshalLoadBalancerPoolPack(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(LoadBalancerPoolPack) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_on", &obj.CreatedOn) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "modified_on", &obj.ModifiedOn) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "enabled", &obj.Enabled) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "healthy", &obj.Healthy) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "monitor", &obj.Monitor) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "minimum_origins", &obj.MinimumOrigins) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "check_regions", &obj.CheckRegions) + if err != nil { + return + } + err = core.UnmarshalModel(m, "origins", &obj.Origins, UnmarshalLoadBalancerPoolPackOriginsItem) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "notification_email", &obj.NotificationEmail) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// LoadBalancerPoolResp : get load balancer pool response. +type LoadBalancerPoolResp struct { + // success response. + Success *bool `json:"success" validate:"required"` + + // errors. + Errors [][]string `json:"errors" validate:"required"` + + // messages. + Messages [][]string `json:"messages" validate:"required"` + + // load balancer pool pack. + Result *LoadBalancerPoolPack `json:"result" validate:"required"` + + // result information. + ResultInfo *ResultInfo `json:"result_info" validate:"required"` +} + + +// UnmarshalLoadBalancerPoolResp unmarshals an instance of LoadBalancerPoolResp from the specified map of raw messages. +func UnmarshalLoadBalancerPoolResp(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(LoadBalancerPoolResp) + err = core.UnmarshalPrimitive(m, "success", &obj.Success) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "errors", &obj.Errors) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "messages", &obj.Messages) + if err != nil { + return + } + err = core.UnmarshalModel(m, "result", &obj.Result, UnmarshalLoadBalancerPoolPack) + if err != nil { + return + } + err = core.UnmarshalModel(m, "result_info", &obj.ResultInfo, UnmarshalResultInfo) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ResultInfo : result information. +type ResultInfo struct { + // page number. + Page *int64 `json:"page" validate:"required"` + + // per page count. + PerPage *int64 `json:"per_page" validate:"required"` + + // count. + Count *int64 `json:"count" validate:"required"` + + // total count. + TotalCount *int64 `json:"total_count" validate:"required"` +} + + +// UnmarshalResultInfo unmarshals an instance of ResultInfo from the specified map of raw messages. +func UnmarshalResultInfo(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ResultInfo) + err = core.UnmarshalPrimitive(m, "page", &obj.Page) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "per_page", &obj.PerPage) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "count", &obj.Count) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 08f7b2e0d5..0c90472bef 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -127,13 +127,14 @@ github.com/IBM/ibm-cos-sdk-go-config/resourceconfigurationv1 # github.com/IBM/keyprotect-go-client v0.3.5-0.20200325142150-b63163832e26 github.com/IBM/keyprotect-go-client github.com/IBM/keyprotect-go-client/iam -# github.com/IBM/networking-go-sdk v0.8.0 +# github.com/IBM/networking-go-sdk v0.10.0 github.com/IBM/networking-go-sdk/common github.com/IBM/networking-go-sdk/directlinkv1 github.com/IBM/networking-go-sdk/dnsrecordsv1 github.com/IBM/networking-go-sdk/edgefunctionsapiv1 github.com/IBM/networking-go-sdk/globalloadbalancermonitorv1 github.com/IBM/networking-go-sdk/sslcertificateapiv1 +github.com/IBM/networking-go-sdk/globalloadbalancerpoolsv0 github.com/IBM/networking-go-sdk/transitgatewayapisv1 github.com/IBM/networking-go-sdk/zoneratelimitsv1 github.com/IBM/networking-go-sdk/zonessettingsv1 From 5ae61ace80c7e19ac5fd7c920ff0555d3171f883 Mon Sep 17 00:00:00 2001 From: Kumar Ganesan Date: Tue, 13 Oct 2020 10:34:14 +0530 Subject: [PATCH 2/2] CIS: GLB Pool resource changes --- ibm/config.go | 26 ++ ibm/data_source_ibm_cis_origin_pools.go | 187 +++++++++ ibm/data_source_ibm_cis_origin_pools_test.go | 36 ++ ibm/provider.go | 1 + ...ource_ibm_cis_global_load_balancer_test.go | 2 +- ibm/resource_ibm_cis_origin_pool.go | 389 +++++++++++------- ibm/resource_ibm_cis_origin_pool_test.go | 123 +++--- ibm/structures.go | 31 -- website/docs/d/cis_origin_pools.html.markdown | 47 +++ website/docs/r/cis_origin_pool.html.markdown | 56 +-- website/ibm.erb | 3 + 11 files changed, 645 insertions(+), 256 deletions(-) create mode 100644 ibm/data_source_ibm_cis_origin_pools.go create mode 100644 ibm/data_source_ibm_cis_origin_pools_test.go create mode 100644 website/docs/d/cis_origin_pools.html.markdown diff --git a/ibm/config.go b/ibm/config.go index 4516e31591..716e1cb48d 100644 --- a/ibm/config.go +++ b/ibm/config.go @@ -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" @@ -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) @@ -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 @@ -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 @@ -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 @@ -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, diff --git a/ibm/data_source_ibm_cis_origin_pools.go b/ibm/data_source_ibm_cis_origin_pools.go new file mode 100644 index 0000000000..157f56dc66 --- /dev/null +++ b/ibm/data_source_ibm_cis_origin_pools.go @@ -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() +} diff --git a/ibm/data_source_ibm_cis_origin_pools_test.go b/ibm/data_source_ibm_cis_origin_pools_test.go new file mode 100644 index 0000000000..4f8abaa0c6 --- /dev/null +++ b/ibm/data_source_ibm_cis_origin_pools_test.go @@ -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 + } + `) +} diff --git a/ibm/provider.go b/ibm/provider.go index c3fe04a3d4..52b1a0bec0 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_origin_pools": dataSourceIBMCISOriginPools(), "ibm_cis_healthchecks": dataSourceIBMCISHealthChecks(), "ibm_cis_domain": dataSourceIBMCISDomain(), "ibm_cis_firewall": dataIBMCISFirewallRecord(), diff --git a/ibm/resource_ibm_cis_global_load_balancer_test.go b/ibm/resource_ibm_cis_global_load_balancer_test.go index b7c6e201c2..a363c76b63 100644 --- a/ibm/resource_ibm_cis_global_load_balancer_test.go +++ b/ibm/resource_ibm_cis_global_load_balancer_test.go @@ -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 diff --git a/ibm/resource_ibm_cis_origin_pool.go b/ibm/resource_ibm_cis_origin_pool.go index ebc2ebd3c8..67098f3be8 100644 --- a/ibm/resource_ibm_cis_origin_pool.go +++ b/ibm/resource_ibm_cis_origin_pool.go @@ -2,29 +2,53 @@ package ibm import ( "log" - "reflect" - "strings" + "github.com/IBM/go-sdk-core/v3/core" + "github.com/IBM/networking-go-sdk/globalloadbalancerpoolsv0" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) - v1 "github.com/IBM-Cloud/bluemix-go/api/cis/cisv1" +const ( + cisGLBPoolID = "pool_id" + cisGLBPoolName = "name" + cisGLBPoolRegions = "check_regions" + cisGLBPoolDesc = "description" + cisGLBPoolEnabled = "enabled" + cisGLBPoolMinimumOrigins = "minimum_origins" + cisGLBPoolMonitor = "monitor" + cisGLBPoolNotificationEMail = "notification_email" + cisGLBPoolOrigins = "origins" + cisGLBPoolHealth = "health" + cisGLBPoolHealthy = "healthy" + cisGLBPoolCreatedOn = "created_on" + cisGLBPoolModifiedOn = "modified_on" + cisGLBPoolOriginsName = "name" + cisGLBPoolOriginsAddress = "address" + cisGLBPoolOriginsEnabled = "enabled" + cisGLBPoolOriginsHealthy = "healthy" + cisGLBPoolOriginsWeight = "weight" + cisGLBPoolOriginsDisabledAt = "disabled_at" + cisGLBPoolOriginsFailureReason = "failure_reason" ) func resourceIBMCISPool() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ - "cis_id": { + cisID: { Type: schema.TypeString, Description: "CIS instance crn", Required: true, }, - "name": { + cisGLBPoolID: { + Type: schema.TypeString, + Computed: true, + }, + cisGLBPoolName: { Type: schema.TypeString, Description: "name", Required: true, - //ValidateFunc: validation.StringLenBetween(1, 32), }, - "check_regions": { + cisGLBPoolRegions: { Type: schema.TypeSet, Required: true, Elem: &schema.Schema{ @@ -32,270 +56,333 @@ func resourceIBMCISPool() *schema.Resource { }, Description: "List of regions", }, - "description": { + cisGLBPoolDesc: { Type: schema.TypeString, Optional: true, Description: "Description of the CIS Origin Pool", }, - "enabled": { + cisGLBPoolEnabled: { Type: schema.TypeBool, Required: true, Description: "Boolean value set to true if cis origin pool needs to be enabled", }, - "minimum_origins": { + cisGLBPoolMinimumOrigins: { Type: schema.TypeInt, Optional: true, Default: 1, Description: "Minimum number of Origins", }, - "monitor": { - Type: schema.TypeString, - Optional: true, - Description: "Monitor value", + cisGLBPoolMonitor: { + Type: schema.TypeString, + Optional: true, + Description: "Monitor value", + DiffSuppressFunc: suppressDomainIDDiff, }, - "notification_email": { + cisGLBPoolNotificationEMail: { Type: schema.TypeString, Optional: true, Description: "Email address configured to recieve the notifications", }, - "origins": { + cisGLBPoolOrigins: { Type: schema.TypeSet, Required: true, Description: "Origins info", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "name": { + cisGLBPoolOriginsName: { Type: schema.TypeString, Required: true, }, - "address": { + cisGLBPoolOriginsAddress: { Type: schema.TypeString, Required: true, }, - "enabled": { + cisGLBPoolOriginsEnabled: { Type: schema.TypeBool, Required: true, }, - "weight": { - Type: schema.TypeInt, + cisGLBPoolOriginsWeight: { + Type: schema.TypeFloat, + Default: 1, Optional: true, }, - "healthy": { + cisGLBPoolOriginsHealthy: { Type: schema.TypeBool, Computed: true, }, + cisGLBPoolOriginsDisabledAt: { + Type: schema.TypeString, + Computed: true, + }, + cisGLBPoolOriginsFailureReason: { + Type: schema.TypeString, + Computed: true, + }, }, }, }, - "health": { + cisGLBPoolHealth: { Type: schema.TypeString, Computed: true, Description: "Health info", }, - "created_on": { + cisGLBPoolHealthy: { + Type: schema.TypeBool, + Computed: true, + Description: "Health status", + }, + cisGLBPoolCreatedOn: { Type: schema.TypeString, Computed: true, Description: "Creation date info", }, - "modified_on": { + cisGLBPoolModifiedOn: { Type: schema.TypeString, Computed: true, Description: "Modified date info", }, }, - Create: resourceCISpoolCreate, - Read: resourceCISpoolRead, - Update: resourceCISpoolUpdate, - Delete: resourceCISpoolDelete, + Create: resourceCISPoolCreate, + Read: resourceCISPoolRead, + Update: resourceCISPoolUpdate, + Delete: resourceCISPoolDelete, + Exists: resourceCISPoolExists, Importer: &schema.ResourceImporter{}, } } -func resourceCISpoolCreate(d *schema.ResourceData, meta interface{}) error { - cisClient, err := meta.(ClientSession).CisAPI() +func resourceCISPoolCreate(d *schema.ResourceData, meta interface{}) error { + var regions []string + cisClient, err := meta.(ClientSession).CisGLBPoolClientSession() if err != nil { return err } - cisId := d.Get("cis_id").(string) - name := d.Get("name").(string) - origins := d.Get("origins").(*schema.Set) - checkRegions := d.Get("check_regions").(*schema.Set).List() + crn := d.Get(cisID).(string) + cisClient.Crn = core.StringPtr(crn) + name := d.Get(cisGLBPoolName).(string) + origins := d.Get(cisGLBPoolOrigins).(*schema.Set).List() + checkRegions := d.Get(cisGLBPoolRegions).(*schema.Set).List() - poolNew := v1.PoolBody{} - poolNew.Name = name - poolNew.CheckRegions = expandStringList(checkRegions) - poolNew.Origins = expandOrigins(origins) + for _, region := range checkRegions { + regions = append(regions, region.(string)) + } - if notEmail, ok := d.GetOk("notification_email"); ok { - poolNew.NotEmail = notEmail.(string) + glbOrigins := []globalloadbalancerpoolsv0.LoadBalancerPoolReqOriginsItem{} + + for _, origin := range origins { + orig := origin.(map[string]interface{}) + glbOrigin := globalloadbalancerpoolsv0.LoadBalancerPoolReqOriginsItem{ + Name: core.StringPtr(orig[cisGLBPoolOriginsName].(string)), + Address: core.StringPtr(orig[cisGLBPoolOriginsAddress].(string)), + Enabled: core.BoolPtr(orig[cisGLBPoolOriginsEnabled].(bool)), + Weight: core.Float64Ptr(orig[cisGLBPoolOriginsWeight].(float64)), + } + glbOrigins = append(glbOrigins, glbOrigin) } - if monitor, ok := d.GetOk("monitor"); ok { - monitorId, _, _ := convertTftoCisTwoVar(monitor.(string)) - poolNew.Monitor = monitorId + + opt := cisClient.NewCreateLoadBalancerPoolOptions() + opt.SetName(name) + opt.SetCheckRegions(regions) + opt.SetOrigins(glbOrigins) + opt.SetEnabled(d.Get(cisGLBPoolEnabled).(bool)) + + if notifEmail, ok := d.GetOk(cisGLBPoolNotificationEMail); ok { + opt.SetNotificationEmail(notifEmail.(string)) } - if enabled, ok := d.GetOk("enabled"); ok { - poolNew.Enabled = enabled.(bool) + if monitor, ok := d.GetOk(cisGLBPoolMonitor); ok { + monitorID, _, _ := convertTftoCisTwoVar(monitor.(string)) + opt.SetMonitor(monitorID) } - if minOrigins, ok := d.GetOk("minimum_origins"); ok { - poolNew.MinOrigins = minOrigins.(int) + if minOrigins, ok := d.GetOk(cisGLBPoolMinimumOrigins); ok { + opt.SetMinimumOrigins(int64(minOrigins.(int))) } - if description, ok := d.GetOk("description"); ok { - poolNew.Description = description.(string) + if description, ok := d.GetOk(cisGLBPoolDesc); ok { + opt.SetDescription(description.(string)) } - var pool *v1.Pool - var poolObj v1.Pool - - pool, err = cisClient.Pools().CreatePool(cisId, poolNew) + result, resp, err := cisClient.CreateLoadBalancerPool(opt) if err != nil { - log.Printf("[WARN] CreatePools Failed %s\n", err) + log.Printf("[WARN] Create GLB Pools failed %s\n", resp) return err } - - poolObj = *pool - //Set unique TF Id from concatenated CIS Ids - d.SetId(convertCisToTfTwoVar(poolObj.Id, cisId)) - d.Set("name", poolObj.Name) - - return resourceCISpoolRead(d, meta) + d.SetId(convertCisToTfTwoVar(*result.Result.ID, crn)) + return resourceCISPoolRead(d, meta) } -func resourceCISpoolRead(d *schema.ResourceData, meta interface{}) error { - cisClient, err := meta.(ClientSession).CisAPI() +func resourceCISPoolRead(d *schema.ResourceData, meta interface{}) error { + cisClient, err := meta.(ClientSession).CisGLBPoolClientSession() if err != nil { return err } - poolId, cisId, err := convertTftoCisTwoVar(d.Id()) + poolID, crn, err := convertTftoCisTwoVar(d.Id()) if err != nil { return err } - var pool *v1.Pool - pool, err = cisClient.Pools().GetPool(cisId, poolId) + cisClient.Crn = core.StringPtr(crn) + opt := cisClient.NewGetLoadBalancerPoolOptions(poolID) + result, resp, err := cisClient.GetLoadBalancerPool(opt) if err != nil { - if checkCisPoolDeleted(d, meta, err, pool) { - d.SetId("") - return nil - } - log.Printf("[WARN] Error getting zone during PoolRead %v\n", err) + log.Printf("[WARN] Create GLB Pools failed %s\n", resp) return err } - poolObj := *pool - d.Set("cis_id", cisId) - d.Set("name", poolObj.Name) - d.Set("check_regions", poolObj.CheckRegions) - d.Set("origins", flattenOrigins(poolObj.Origins)) - d.Set("description", poolObj.Description) - d.Set("enabled", poolObj.Enabled) - d.Set("minimum_origins", poolObj.MinOrigins) - d.Set("monitor", convertCisToTfTwoVar(poolObj.Monitor, cisId)) - d.Set("notification_email", poolObj.NotEmail) - d.Set("health", poolObj.Health) - d.Set("created_on", poolObj.CreatedOn) - d.Set("modified_on", poolObj.ModifiedOn) - + poolObj := *result.Result + d.Set(cisID, crn) + d.Set(cisGLBPoolID, poolObj.ID) + d.Set(cisGLBPoolName, poolObj.Name) + d.Set(cisGLBPoolOrigins, flattenOrigins(poolObj.Origins)) + d.Set(cisGLBPoolRegions, poolObj.CheckRegions) + d.Set(cisGLBPoolDesc, poolObj.Description) + d.Set(cisGLBPoolEnabled, poolObj.Enabled) + d.Set(cisGLBPoolNotificationEMail, poolObj.NotificationEmail) + d.Set(cisGLBPoolHealthy, poolObj.Healthy) + d.Set(cisGLBPoolMinimumOrigins, poolObj.MinimumOrigins) + d.Set(cisGLBPoolCreatedOn, poolObj.CreatedOn) + d.Set(cisGLBPoolModifiedOn, poolObj.ModifiedOn) + if poolObj.Monitor != nil { + d.Set(cisGLBPoolMonitor, *poolObj.Monitor) + } return nil } -func resourceCISpoolUpdate(d *schema.ResourceData, meta interface{}) error { - cisClient, err := meta.(ClientSession).CisAPI() +func resourceCISPoolUpdate(d *schema.ResourceData, meta interface{}) error { + cisClient, err := meta.(ClientSession).CisGLBPoolClientSession() if err != nil { return err } - poolID, cisID, err := convertTftoCisTwoVar(d.Id()) + poolID, crn, err := convertTftoCisTwoVar(d.Id()) if err != nil { return err } - poolUpdate := v1.PoolBody{} - if d.HasChange("name") || d.HasChange("origins") || d.HasChange("check_regions") || d.HasChange("notification_email") || d.HasChange("monitor") || d.HasChange("enabled") || d.HasChange("minimum_origins") || d.HasChange("description") { - if name, ok := d.GetOk("name"); ok { - poolUpdate.Name = name.(string) + cisClient.Crn = core.StringPtr(crn) + if d.HasChange(cisGLBPoolName) || + d.HasChange(cisGLBPoolOrigins) || + d.HasChange(cisGLBPoolRegions) || + d.HasChange(cisGLBPoolNotificationEMail) || + d.HasChange(cisGLBPoolMonitor) || + d.HasChange(cisGLBPoolEnabled) || + d.HasChange(cisGLBPoolMinimumOrigins) || + d.HasChange(cisGLBPoolDesc) { + + opt := cisClient.NewEditLoadBalancerPoolOptions(poolID) + if monitor, ok := d.GetOk(cisGLBPoolMonitor); ok { + monitorID, _, _ := convertTftoCisTwoVar(monitor.(string)) + opt.SetMonitor(monitorID) } - if origin, ok := d.GetOk("origins"); ok { - origins := origin.(*schema.Set) - poolUpdate.Origins = expandOrigins(origins) + + if name, ok := d.GetOk(cisGLBPoolName); ok { + opt.SetName(name.(string)) } - if checkregions, ok := d.GetOk("check_regions"); ok { - checkRegions := checkregions.(*schema.Set).List() - poolUpdate.CheckRegions = expandStringList(checkRegions) + if origins, ok := d.GetOk(cisGLBPoolOrigins); ok { + glbOrigins := []globalloadbalancerpoolsv0.LoadBalancerPoolReqOriginsItem{} + + for _, origin := range origins.(*schema.Set).List() { + orig := origin.(map[string]interface{}) + glbOrigin := globalloadbalancerpoolsv0.LoadBalancerPoolReqOriginsItem{ + Name: core.StringPtr(orig[cisGLBPoolOriginsName].(string)), + Address: core.StringPtr(orig[cisGLBPoolOriginsAddress].(string)), + Enabled: core.BoolPtr(orig[cisGLBPoolOriginsEnabled].(bool)), + Weight: core.Float64Ptr(orig[cisGLBPoolOriginsWeight].(float64)), + } + glbOrigins = append(glbOrigins, glbOrigin) + } + opt.SetOrigins(glbOrigins) } - if notEmail, ok := d.GetOk("notification_email"); ok { - poolUpdate.NotEmail = notEmail.(string) + if checkregions, ok := d.GetOk(cisGLBPoolRegions); ok { + checkRegions := checkregions.(*schema.Set).List() + var regions []string + for _, region := range checkRegions { + regions = append(regions, region.(string)) + } + opt.SetCheckRegions(regions) } - if monitor, ok := d.GetOk("monitor"); ok { - monitorID, _, _ := convertTftoCisTwoVar(monitor.(string)) - poolUpdate.Monitor = monitorID + if notEmail, ok := d.GetOk(cisGLBPoolNotificationEMail); ok { + opt.SetNotificationEmail(notEmail.(string)) } - if enabled, ok := d.GetOk("enabled"); ok { - poolUpdate.Enabled = enabled.(bool) + + if enabled, ok := d.GetOk(cisGLBPoolEnabled); ok { + opt.SetEnabled(enabled.(bool)) } - if minOrigins, ok := d.GetOk("minimum_origins"); ok { - poolUpdate.MinOrigins = minOrigins.(int) + if minOrigins, ok := d.GetOk(cisGLBPoolMinimumOrigins); ok { + opt.SetMinimumOrigins(int64(minOrigins.(int))) } - if description, ok := d.GetOk("description"); ok { - poolUpdate.Description = description.(string) + if description, ok := d.GetOk(cisGLBPoolDesc); ok { + opt.SetDescription(description.(string)) } - _, err = cisClient.Pools().UpdatePool(cisID, poolID, poolUpdate) + _, resp, err := cisClient.EditLoadBalancerPool(opt) if err != nil { - log.Printf("[WARN] Error getting zone during PoolUpdate %v\n", err) + log.Printf("[WARN] Error getting zone during PoolUpdate %v\n", resp) return err } } - - return resourceCISpoolRead(d, meta) + return resourceCISPoolRead(d, meta) } -func resourceCISpoolDelete(d *schema.ResourceData, meta interface{}) error { - cisClient, err := meta.(ClientSession).CisAPI() +func resourceCISPoolDelete(d *schema.ResourceData, meta interface{}) error { + cisClient, err := meta.(ClientSession).CisGLBPoolClientSession() if err != nil { return err } - poolId, cisId, err := convertTftoCisTwoVar(d.Id()) - var pool *v1.Pool - emptyPool := new(v1.Pool) - pool, err = cisClient.Pools().GetPool(cisId, poolId) + poolID, crn, err := convertTftoCisTwoVar(d.Id()) if err != nil { - if checkCisPoolDeleted(d, meta, err, pool) { - d.SetId("") - return nil - } - log.Printf("[WARN] Error getting zone during PoolRead %v\n", err) return err } - - poolObj := *pool - if !reflect.DeepEqual(emptyPool, poolObj) { - err = cisClient.Pools().DeletePool(cisId, poolId) - if err != nil { - log.Printf("[WARN] DeletePool Failed %s\n", err) - return err - } + cisClient.Crn = core.StringPtr(crn) + opt := cisClient.NewDeleteLoadBalancerPoolOptions(poolID) + result, resp, err := cisClient.DeleteLoadBalancerPool(opt) + if err != nil { + log.Printf("[WARN] Delete GLB Pools failed %s\n", resp) + return err } - - d.SetId("") + log.Printf("Pool %s deleted successfully.", *result.Result.ID) return nil } -func checkCisPoolDeleted(d *schema.ResourceData, meta interface{}, errCheck error, pool *v1.Pool) 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 resourceCISPoolExists(d *schema.ResourceData, meta interface{}) (bool, error) { + cisClient, err := meta.(ClientSession).CisGLBPoolClientSession() + if err != nil { + return false, err } - _, cisId, _ := convertTftoCisTwoVar(d.Id()) - exists, errNew := rcInstanceExists(cisId, "ibm_cis", meta) - if errNew != nil { - log.Printf("[WARN] resourceCISpoolRead - Failure validating service exists %s\n", errNew) - return false + poolID, cisID, err := convertTftoCisTwoVar(d.Id()) + if err != nil { + return false, err } - if !exists { - log.Printf("[WARN] Removing pool from state because parent cis instance is in removed state") - return true + cisClient.Crn = core.StringPtr(cisID) + opt := cisClient.NewGetLoadBalancerPoolOptions(poolID) + result, response, err := cisClient.GetLoadBalancerPool(opt) + if err != nil { + if response != nil && response.StatusCode == 404 { + log.Printf("global load balancer pool does not exist.") + return false, nil + } + log.Printf("Error : %s", response) + return false, err + } + log.Printf("global load balancer pool exist : %s", *result.Result.ID) + return true, nil +} + +// Cloud Internet Services +func flattenOrigins(list []globalloadbalancerpoolsv0.LoadBalancerPoolPackOriginsItem) []map[string]interface{} { + origins := []map[string]interface{}{} + for _, origin := range list { + l := map[string]interface{}{ + cisGLBPoolOriginsName: origin.Name, + cisGLBPoolOriginsAddress: origin.Address, + cisGLBPoolOriginsEnabled: origin.Enabled, + cisGLBPoolOriginsHealthy: origin.Healthy, + cisGLBPoolOriginsWeight: origin.Weight, + } + if origin.DisabledAt != nil { + l[cisGLBPoolOriginsDisabledAt] = *origin.DisabledAt + } + if origin.FailureReason != nil { + l[cisGLBPoolOriginsFailureReason] = *origin.FailureReason + } + origins = append(origins, l) } - return false + return origins } diff --git a/ibm/resource_ibm_cis_origin_pool_test.go b/ibm/resource_ibm_cis_origin_pool_test.go index 4e30a5cdb7..d8574a0c45 100644 --- a/ibm/resource_ibm_cis_origin_pool_test.go +++ b/ibm/resource_ibm_cis_origin_pool_test.go @@ -5,13 +5,13 @@ import ( "log" "testing" + "github.com/IBM/go-sdk-core/v3/core" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccIBMCisPool_Basic(t *testing.T) { - //t.Parallel() var pool string rnd := acctest.RandString(10) name := "ibm_cis_origin_pool.origin_pool" @@ -20,14 +20,22 @@ func TestAccIBMCisPool_Basic(t *testing.T) { PreCheck: func() { testAccPreCheckCis(t) }, Providers: testAccProviders, // No requirement for CheckDestory of this resource as by reaching this test it must have already been deleted - // correctly during the resource destroy phase of test. The destroy of resource_ibm_cis used in testAccCheckCisPoolConfigCisDS_Basic + // correctly during the resource destroy phase of test. The destroy of resource_ibm_cis used in testAccCheckCisPoolConfigCisDSBasic // will fail if this resource is not correctly deleted. Steps: []resource.TestStep{ { - Config: testAccCheckCisPoolConfigCisDS_Basic(rnd, cisDomainStatic), + Config: testAccCheckCisPoolConfigCisDSBasic(rnd, cisDomainStatic), + Check: resource.ComposeTestCheckFunc( + testAccCheckCisPoolExists(name, &pool), + resource.TestCheckResourceAttr(name, "check_regions.#", "1"), + ), + }, + { + Config: testAccCheckCisPoolConfigCisDSUpdate(rnd, cisDomainStatic), Check: resource.ComposeTestCheckFunc( testAccCheckCisPoolExists(name, &pool), resource.TestCheckResourceAttr(name, "check_regions.#", "1"), + resource.TestCheckResourceAttr(name, "description", "tfacc-update-specified"), ), }, }, @@ -41,26 +49,23 @@ func TestAccIBMCisPool_import(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckCisPoolConfigCisDS_Basic(rnd, cisDomainStatic), + { + Config: testAccCheckCisPoolConfigCisDSBasic(rnd, cisDomainStatic), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(name, "check_regions.#", "1"), resource.TestCheckResourceAttr(name, "origins.#", "1"), ), }, - resource.TestStep{ + { ResourceName: name, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "wait_time_minutes"}, }, }, }) } func TestAccIBMCisPool_FullySpecified(t *testing.T) { - //t.Parallel() var pool string rnd := acctest.RandString(10) name := "ibm_cis_origin_pool.origin_pool" @@ -75,7 +80,7 @@ func TestAccIBMCisPool_FullySpecified(t *testing.T) { testAccCheckCisPoolExists(name, &pool), resource.TestCheckResourceAttr(name, "enabled", "false"), resource.TestCheckResourceAttr(name, "description", "tfacc-fully-specified"), - resource.TestCheckResourceAttr(name, "check_regions.#", "1"), + resource.TestCheckResourceAttr(name, "check_regions.#", "2"), resource.TestCheckResourceAttr(name, "minimum_origins", "2"), resource.TestCheckResourceAttr(name, "notification_email", "admin@outlook.com"), resource.TestCheckResourceAttr(name, "origins.#", "2"), @@ -98,7 +103,7 @@ func TestAccIBMCisPool_CreateAfterManualDestroy(t *testing.T) { CheckDestroy: testAccCheckCisPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckCisPoolConfigCisDS_Basic(testName, cisDomainStatic), + Config: testAccCheckCisPoolConfigCisDSBasic(testName, cisDomainStatic), Check: resource.ComposeTestCheckFunc( testAccCheckCisPoolExists(name, &poolOne), testAccCisPoolManuallyDelete(&poolOne), @@ -106,7 +111,7 @@ func TestAccIBMCisPool_CreateAfterManualDestroy(t *testing.T) { ExpectNonEmptyPlan: true, }, { - Config: testAccCheckCisPoolConfigCisDS_Basic(testName, cisDomainStatic), + Config: testAccCheckCisPoolConfigCisDSBasic(testName, cisDomainStatic), Check: resource.ComposeTestCheckFunc( testAccCheckCisPoolExists(name, &poolTwo), func(state *terraform.State) error { @@ -135,7 +140,7 @@ func TestAccIBMCisPool_CreateAfterCisRIManualDestroy(t *testing.T) { CheckDestroy: testAccCheckCisPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckCisPoolConfigCisRI_Basic(testName, cisDomainTest), + Config: testAccCheckCisPoolConfigCisRIBasic(testName, cisDomainTest), Check: resource.ComposeTestCheckFunc( testAccCheckCisPoolExists(name, &poolOne), testAccCisPoolManuallyDelete(&poolOne), @@ -147,9 +152,9 @@ func TestAccIBMCisPool_CreateAfterCisRIManualDestroy(t *testing.T) { for _, r := range state.RootModule().Resources { if r.Type == "ibm_cis_domain" { log.Printf("[WARN] 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] Removing Cis Instance") _ = testAccCisInstanceManuallyDeleteUnwrapped(state, cisPtr) } @@ -161,7 +166,7 @@ func TestAccIBMCisPool_CreateAfterCisRIManualDestroy(t *testing.T) { ExpectNonEmptyPlan: true, }, { - Config: testAccCheckCisPoolConfigCisRI_Basic(testName, cisDomainTest), + Config: testAccCheckCisPoolConfigCisRIBasic(testName, cisDomainTest), Check: resource.ComposeTestCheckFunc( testAccCheckCisPoolExists(name, &poolTwo), func(state *terraform.State) error { @@ -178,7 +183,7 @@ func TestAccIBMCisPool_CreateAfterCisRIManualDestroy(t *testing.T) { } func testAccCheckCisPoolDestroy(s *terraform.State) error { - cisClient, err := testAccProvider.Meta().(ClientSession).CisAPI() + cisClient, err := testAccProvider.Meta().(ClientSession).CisGLBPoolClientSession() if err != nil { return err } @@ -186,8 +191,10 @@ func testAccCheckCisPoolDestroy(s *terraform.State) error { if rs.Type != "ibm_cis_origin_pool" { continue } - poolId, cisId, _ := convertTftoCisTwoVar(rs.Primary.ID) - _, err = cisClient.Pools().GetPool(cisId, poolId) + poolID, cisID, _ := convertTftoCisTwoVar(rs.Primary.ID) + cisClient.Crn = core.StringPtr(cisID) + opt := cisClient.NewGetLoadBalancerPoolOptions(poolID) + _, _, err := cisClient.GetLoadBalancerPool(opt) if err == nil { return fmt.Errorf("Load balancer pool still exists") } @@ -196,7 +203,7 @@ func testAccCheckCisPoolDestroy(s *terraform.State) error { return nil } -func testAccCheckCisPoolExists(n string, tfPoolId *string) resource.TestCheckFunc { +func testAccCheckCisPoolExists(n string, tfPoolID *string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -207,47 +214,51 @@ func testAccCheckCisPoolExists(n string, tfPoolId *string) resource.TestCheckFun return fmt.Errorf("No Load Balancer ID is set") } - cisClient, err := testAccProvider.Meta().(ClientSession).CisAPI() + cisClient, err := testAccProvider.Meta().(ClientSession).CisGLBPoolClientSession() if err != nil { return err } - poolId, cisId, _ := convertTftoCisTwoVar(rs.Primary.ID) - foundPoolPtr, err := cisClient.Pools().GetPool(rs.Primary.Attributes["cis_id"], poolId) + poolID, cisID, _ := convertTftoCisTwoVar(rs.Primary.ID) + cisClient.Crn = core.StringPtr(cisID) + opt := cisClient.NewGetLoadBalancerPoolOptions(poolID) + result, resp, err := cisClient.GetLoadBalancerPool(opt) if err != nil { - return err + return fmt.Errorf("Error getting glb pool: %v", resp) } - foundPool := *foundPoolPtr - if foundPool.Id != poolId { + foundPool := result.Result + if *foundPool.ID != poolID { return fmt.Errorf("Record not found") } - tfPool := convertCisToTfTwoVar(foundPool.Id, cisId) - *tfPoolId = tfPool + tfPool := convertCisToTfTwoVar(*foundPool.ID, cisID) + *tfPoolID = tfPool return nil } } -func testAccCisPoolManuallyDelete(tfPoolId *string) resource.TestCheckFunc { +func testAccCisPoolManuallyDelete(tfPoolID *string) resource.TestCheckFunc { return func(s *terraform.State) error { log.Printf("[WARN] Manually removing pool") - cisClient, err := testAccProvider.Meta().(ClientSession).CisAPI() + cisClient, err := testAccProvider.Meta().(ClientSession).CisGLBPoolClientSession() if err != nil { return err } - tfPool := *tfPoolId - poolId, cisId, _ := convertTftoCisTwoVar(tfPool) - err = cisClient.Pools().DeletePool(cisId, poolId) + tfPool := *tfPoolID + poolID, cisID, _ := convertTftoCisTwoVar(tfPool) + cisClient.Crn = core.StringPtr(cisID) + opt := cisClient.NewDeleteLoadBalancerPoolOptions(poolID) + _, resp, err := cisClient.DeleteLoadBalancerPool(opt) if err != nil { - return fmt.Errorf("Error deleting IBMCISPool Record: %s", err) + return fmt.Errorf("[WARN] Delete GLB Pools failed : %v", resp) } return nil } } -func testAccCheckCisPoolConfigCisDS_Basic(resourceId string, cisDomainStatic string) string { - return testAccCheckIBMCisDomainDataSourceConfigBasic1() + fmt.Sprintf(` +func testAccCheckCisPoolConfigCisDSBasic(resourceID string, cisDomainStatic string) string { + return testAccCheckCisHealthcheckConfigCisDSBasic(resourceID, cisDomainStatic) + fmt.Sprintf(` resource "ibm_cis_origin_pool" "origin_pool" { cis_id = data.ibm_cis.cis.id name = "my-tf-pool-basic-%[1]s" @@ -260,12 +271,32 @@ func testAccCheckCisPoolConfigCisDS_Basic(resourceId string, cisDomainStatic str weight = 1 } enabled = false + monitor = ibm_cis_healthcheck.health_check.id + } + `, resourceID) +} + +func testAccCheckCisPoolConfigCisDSUpdate(resourceID string, cisDomainStatic string) string { + return testAccCheckCisHealthcheckConfigCisDSBasic(resourceID, cisDomainStatic) + fmt.Sprintf(` + resource "ibm_cis_origin_pool" "origin_pool" { + cis_id = data.ibm_cis.cis.id + name = "my-tf-pool-update-%[1]s" + check_regions = ["ENAM"] + description = "tfacc-update-specified" + origins { + name = "example-2" + address = "www.google2.com" + enabled = false + weight = 0.5 + } + enabled = true + monitor = ibm_cis_healthcheck.health_check.monitor_id } - `, resourceId) + `, resourceID) } -func testAccCheckCisPoolConfigCisRI_Basic(resourceId string, cisDomain string) string { - return testAccCheckCisDomainConfigCisRIbasic(resourceId, cisDomain) + fmt.Sprintf(` +func testAccCheckCisPoolConfigCisRIBasic(resourceID string, cisDomain string) string { + return testAccCheckCisDomainConfigCisRIbasic(resourceID, cisDomain) + fmt.Sprintf(` resource "ibm_cis_origin_pool" "origin_pool" { cis_id = ibm_cis.cis.id name = "my-tf-pool-basic-%[1]s" @@ -279,11 +310,11 @@ func testAccCheckCisPoolConfigCisRI_Basic(resourceId string, cisDomain string) s } enabled = false } - `, resourceId) + `, resourceID) } -func testAccCheckCisPoolConfigFullySpecified(resourceId string, cisDomainStatic string) string { - return testAccCheckCisHealthcheckConfigCisDSBasic(resourceId, cisDomainStatic) + fmt.Sprintf(` +func testAccCheckCisPoolConfigFullySpecified(resourceID string, cisDomainStatic string) string { + return testAccCheckCisHealthcheckConfigCisDSBasic(resourceID, cisDomainStatic) + fmt.Sprintf(` resource "ibm_cis_origin_pool" "origin_pool" { cis_id = data.ibm_cis.cis.id name = "my-tf-pool-basic-%[1]s" @@ -298,11 +329,11 @@ func testAccCheckCisPoolConfigFullySpecified(resourceId string, cisDomainStatic address = "150.0.0.2" enabled = true } - check_regions = ["WEU"] + check_regions = ["WEU", "ENAM"] description = "tfacc-fully-specified" enabled = false minimum_origins = 2 - monitor = ibm_cis_healthcheck.health_check.id + monitor = ibm_cis_healthcheck.health_check.monitor_id } - `, resourceId) + `, resourceID) } diff --git a/ibm/structures.go b/ibm/structures.go index 40f95a141c..25167d356e 100644 --- a/ibm/structures.go +++ b/ibm/structures.go @@ -11,7 +11,6 @@ import ( "strconv" "strings" - "github.com/IBM-Cloud/bluemix-go/api/cis/cisv1" "github.com/IBM-Cloud/bluemix-go/api/container/containerv1" "github.com/IBM-Cloud/bluemix-go/api/container/containerv2" "github.com/IBM-Cloud/bluemix-go/api/iampap/iampapv1" @@ -1136,21 +1135,6 @@ func flattenServiceIds(services []string, meta interface{}) ([]string, error) { return serviceids, nil } -// Cloud Internet Services -func expandOrigins(originsList *schema.Set) (origins []cisv1.Origin) { - for _, iface := range originsList.List() { - orig := iface.(map[string]interface{}) - origin := cisv1.Origin{ - Name: orig["name"].(string), - Address: orig["address"].(string), - Enabled: orig["enabled"].(bool), - Weight: orig["weight"].(int), - } - origins = append(origins, origin) - } - return -} - func expandUsers(userList *schema.Set) (users []icdv4.User) { for _, iface := range userList.List() { userEl := iface.(map[string]interface{}) @@ -1283,21 +1267,6 @@ func flattenWhitelist(whitelist icdv4.Whitelist) []map[string]interface{} { return entries } -// Cloud Internet Services -func flattenOrigins(list []cisv1.Origin) []map[string]interface{} { - origins := make([]map[string]interface{}, len(list), len(list)) - for i, origin := range list { - l := map[string]interface{}{ - "name": origin.Name, - "address": origin.Address, - "enabled": origin.Enabled, - "weight": origin.Weight, - } - origins[i] = l - } - return origins -} - func expandStringMap(inVal interface{}) map[string]string { outVal := make(map[string]string) if inVal == nil { diff --git a/website/docs/d/cis_origin_pools.html.markdown b/website/docs/d/cis_origin_pools.html.markdown new file mode 100644 index 0000000000..2329b1b87c --- /dev/null +++ b/website/docs/d/cis_origin_pools.html.markdown @@ -0,0 +1,47 @@ +--- +layout: "ibm" +page_title: "IBM: ibm_cis_origin_pools" +sidebar_current: "docs-ibm-datasource-cis-origin-pools" +description: |- + Provides a IBM Cloud Internet Services Global Load Balancer Origin Pool resource. +--- + +# ibm_cis_origin_pool + +Provides a IBM Cloud Internet Services origin pool resource. This provides a pool of origins that can be used by a IBM CIS Global Load Balancer. This resource is associated with an IBM Cloud Internet Services instance and optionally a CIS Healthcheck monitor resource. + +## Example Usage + +```hcl +data "ibm_cis_origin_pools" "test" { + cis_id = var.cis_crn +} +``` + +## Argument Reference + +The following arguments are supported: + +- `cis_id` - (Required,string) The ID of the CIS service instance + +## Attributes Reference + +The following attributes are exported: + +- `id` - ID for this load balancer pool. +- `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. +- `healthy` - The status of the origin pool. +- `name` - A short name (tag) for the pool. Only alphanumeric characters, hyphens, and underscores are allowed. +- `origins` - The list of origins within this pool. Traffic directed at this pool is balanced across all currently healthy origins, provided the pool itself is healthy. It's a complex value. See description below. + - `name` - A human-identifiable name for the origin. + - `address` - The IP address (IPv4 or IPv6) of the origin, or the publicly addressable hostname. Hostnames entered here should resolve directly to the origin, and not be a hostname proxied by CIS. + - `enabled` - Whether to enable (the default) this origin within the Pool. Disabled origins will not receive traffic and are excluded from health checks. The origin will only be disabled for the current pool. + - `weight` - The origin pool weight. + - `healthy` - The status of origins health. + - `disabled_at` - The disabled date and time. + - `failure_reason` - The reason of failure. +- `description` - Free text description. +- `enabled` - Whether to enable (the default) this pool. Disabled pools will not receive traffic and are excluded from health checks. Disabling a pool will cause any load balancers using it to failover to the next pool (if any). +- `monitor` - The ID of the Monitor to use for health checking origins within this pool. +- `notification_email` - The email address to send health status notifications to. This can be an individual mailbox or a mailing list. diff --git a/website/docs/r/cis_origin_pool.html.markdown b/website/docs/r/cis_origin_pool.html.markdown index bec14c792f..5f68b1ea40 100644 --- a/website/docs/r/cis_origin_pool.html.markdown +++ b/website/docs/r/cis_origin_pool.html.markdown @@ -1,15 +1,14 @@ --- layout: "ibm" page_title: "IBM: ibm_cis_origin_pool" -sidebar_current: "docs-ibm-cis-origin-pool" +sidebar_current: "docs-ibm-resource-cis-origin-pool" description: |- Provides a IBM Cloud Internet Services Origin Pool resource. --- # ibm_cis_origin_pool -Provides a IBM Cloud Internet Services origin pool resource. This provides a pool of origins that can be used by a IBM CIS Global Load Balancer. This resource is associated with an IBM Cloud Internet Services instance and optionally a CIS Healthcheck monitor resource. - +Provides a IBM Cloud Internet Services origin pool resource. This provides a pool of origins that can be used by a IBM CIS Global Load Balancer. This resource is associated with an IBM Cloud Internet Services instance and optionally a CIS Healthcheck monitor resource. ## Example Usage @@ -39,43 +38,46 @@ resource "ibm_cis_origin_pool" "example" { The following arguments are supported: -* `cis_id` - (Required,string) The ID of the CIS service instance -* `name` - (Required,string) A short name (tag) for the pool. Only alphanumeric characters, hyphens, and underscores are allowed. -* `origins` - (Required,set) The list of origins within this pool. Traffic directed at this pool is balanced across all currently healthy origins, provided the pool itself is healthy. It's a complex value. See description below. - * `name` - (Required,string) A human-identifiable name for the origin. - * `address` - (Required,string) The IP address (IPv4 or IPv6) of the origin, or the publicly addressable hostname. Hostnames entered here should resolve directly to the origin, and not be a hostname proxied by CIS. - * `enabled` - (Optional,bool) Whether to enable (the default) this origin within the Pool. Disabled origins will not receive traffic and are excluded from health checks. The origin will only be disabled for the current pool. -* `check_regions` - (Required,set) A list of regions (specified by region code) from which to run health checks. Empty means every region (the default), but requires an Enterprise plan. Region codes can be found on our partner Cloudflare's website [here](https://support.cloudflare.com/hc/en-us/articles/115000540888-Load-Balancing-Geographic-Regions). -* `description` - (Optional,string) Free text description. -* `enabled` - (Required,bool) Whether to enable (the default) this pool. Disabled pools will not receive traffic and are excluded from health checks. Disabling a pool will cause any load balancers using it to failover to the next pool (if any). -* `minimum_origins` - (Optional,int) The minimum number of origins that must be healthy for this pool to serve traffic. If the number of healthy origins falls below this number, the pool will be marked unhealthy and we will failover to the next available pool. Default: 1. -* `monitor` - (Optional,string) The ID of the Monitor to use for health checking origins within this pool. -* `notification_email` - (Optional,string) The email address to send health status notifications to. This can be an individual mailbox or a mailing list. - +- `cis_id` - (Required,string) The ID of the CIS service instance +- `name` - (Required,string) A short name (tag) for the pool. Only alphanumeric characters, hyphens, and underscores are allowed. +- `origins` - (Required,set) The list of origins within this pool. Traffic directed at this pool is balanced across all currently healthy origins, provided the pool itself is healthy. It's a complex value. See description below. + - `name` - (Required,string) A human-identifiable name for the origin. + - `address` - (Required,string) The IP address (IPv4 or IPv6) of the origin, or the publicly addressable hostname. Hostnames entered here should resolve directly to the origin, and not be a hostname proxied by CIS. + - `enabled` - (Optional,bool) Whether to enable (the default) this origin within the Pool. Disabled origins will not receive traffic and are excluded from health checks. The origin will only be disabled for the current pool. + - `weight` - (Optional, float) The origin pool weight. +- `check_regions` - (Required,set) A list of regions (specified by region code) from which to run health checks. Empty means every region (the default), but requires an Enterprise plan. Region codes can be found on our partner Cloudflare's website [here](https://support.cloudflare.com/hc/en-us/articles/115000540888-Load-Balancing-Geographic-Regions). +- `description` - (Optional,string) Free text description. +- `enabled` - (Required,bool) Whether to enable (the default) this pool. Disabled pools will not receive traffic and are excluded from health checks. Disabling a pool will cause any load balancers using it to failover to the next pool (if any). +- `minimum_origins` - (Optional,int) The minimum number of origins that must be healthy for this pool to serve traffic. If the number of healthy origins falls below this number, the pool will be marked unhealthy and we will failover to the next available pool. Default: 1. +- `monitor` - (Optional,string) The ID of the Monitor to use for health checking origins within this pool. +- `notification_email` - (Optional,string) The email address to send health status notifications to. This can be an individual mailbox or a mailing list. ## Attributes Reference The following attributes are exported: -* `id` - ID for this load balancer pool. -* `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. -* `health`- THe status of the origin pool. -* `origins`- The list of origins within this pool. - * `healthy` - Indicates if pool is healthy or not +- `id` - ID for this load balancer pool. +- `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. +- `health`- The status of the origin pool. +- `healthy` - The status of the origin pool. +- `origins`- The list of origins within this pool. + - `healthy` - Indicates if pool is healthy or not + - `disabled_at` - The disabled date and time. + - `failure_reason` - The reason of failure. ## Import -The `ibm_cis_origin_pool` resource can be imported using the `id`. The ID is formed from the `Origin Pool Id` and the `CRN` (Cloud Resource Name) concatentated usinga `:` character. +The `ibm_cis_origin_pool` resource can be imported using the `id`. The ID is formed from the `Origin Pool Id` and the `CRN` (Cloud Resource Name) concatentated usinga `:` character. -The CRN will be located on the **Overview** page of the Internet Services instance under the **Domain** heading. +The CRN will be located on the **Overview** page of the Internet Services instance under the **Domain** heading. -* **CRN** is a 120 digit character string of the form: `crn:v1:bluemix:public:internet-svcs:global:a/4ea1882a2d3401ed1e459979941966ea:31fa970d-51d0-4b05-893e-251cba75a7b3::` - -* **Origin Pool ID** is a 32 digit character string of the form: `000f57b5c42bcff3c02d155c2d58aa97`. The id of an existing pool is not available via the UI. It can be retrieved programmatically via the CIS API or via the CLI using the CIS command to list the defined GLBs: `bx cis glb-pools` +- **CRN** is a 120 digit character string of the form: `crn:v1:bluemix:public:internet-svcs:global:a/4ea1882a2d3401ed1e459979941966ea:31fa970d-51d0-4b05-893e-251cba75a7b3::` +- **Origin Pool ID** is a 32 digit character string of the form: `000f57b5c42bcff3c02d155c2d58aa97`. The id of an existing pool is not available via the UI. It can be retrieved programmatically via the CIS API or via the CLI using the CIS command to list the defined GLBs: `ibmcloud cis glb-pools` ``` $ terraform import ibm_cis_origin_pool.myorg : $ terraform import origin_pool.myorg 000f57b5c42bcff3c02d155c2d58aa97: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 740e498d6d..4a384b19e1 100644 --- a/website/ibm.erb +++ b/website/ibm.erb @@ -74,6 +74,9 @@ > cis_healthchecks + > + cis_origin_pools + > cis