-
Notifications
You must be signed in to change notification settings - Fork 86
Adding css_loadbalancer_v1 resource #3138
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
Open
vineet-pruthi
wants to merge
2
commits into
devel
Choose a base branch
from
css_loadbalancer_resource
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| --- | ||
| subcategory: "Cloud Search Service (CSS)" | ||
| layout: "opentelekomcloud" | ||
| page_title: "OpenTelekomCloud: opentelekomcloud_css_loadbalancer_v1" | ||
| sidebar_current: "docs-opentelekomcloud-resource-css-loadbalancer-v1" | ||
| description: |- | ||
| Manages a CSS load balancing resource within OpenTelekomCloud. | ||
| --- | ||
|
|
||
| Up-to-date reference of API arguments for CSS load balancing you can get at | ||
| [documentation portal](https://docs.otc.t-systems.com/cloud-search-service/api-ref/apis/load_balancing) | ||
|
|
||
| # opentelekomcloud_css_loadbalancer_v1 | ||
|
|
||
| Manages a CSS configuration of loadbalancer. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```hcl | ||
| resource "opentelekomcloud_css_loadbalancer_v1" "css_lb" { | ||
| cluster_id = "terraform-test-cluster" | ||
| elb_id = var.elb_id | ||
| agency = "css_upgrade_agency" | ||
|
|
||
| listener { | ||
| protocol = "HTTPS" | ||
| protocol_port = 443 | ||
| server_cert_id = var.server_cert_id | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Argument Reference | ||
|
|
||
| The following arguments are supported: | ||
|
|
||
| * `cluster_id` - (Required) ID of the CSS cluster. | ||
|
|
||
| * `agency` - (Required) The agency used by CSS to access ELB. | ||
|
|
||
| * `elb_id` - (Required) ELBv3 ID. | ||
|
|
||
| * `listener` - (Optional) configure load balancing listeners for a cluster. Structure is documented below. | ||
|
|
||
| The `listener` block supports: | ||
|
|
||
| * `protocol` - (Required) Protocol type. HTTP and HTTPS are supported. | ||
|
|
||
| * `protocol_port` - (Required) Port. | ||
|
|
||
| * `server_cert_id` - (Optional) Server certificate ID. This parameter is mandatory when protocol is set to HTTPS. | ||
|
|
||
| * `ca_cert_id` - (Optional) CA certificate ID. This parameter is mandatory when protocol is set to HTTPS and bidirectional authentication is used. | ||
|
|
||
| * `type` - (Optional) Type: searchTool indicates that the load balancer is enabled or disabled for Elasticsearch/OpenSearch. viewTool indicates that the load balancer is enabled or disabled for Kibana/OpenSearch Dashboards. The default value is searchTool. | ||
163 changes: 163 additions & 0 deletions
163
opentelekomcloud/acceptance/css/resource_opentelekomcloud_css_loadbalancer_v1_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| package acceptance | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/load_balancer" | ||
| "github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common" | ||
| "github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env" | ||
| "github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg" | ||
| ) | ||
|
|
||
| // getCssLoadBalancerFunc loads the CSS load balancer config from the remote API | ||
| func getCssLoadBalancerFunc(conf *cfg.Config, state *terraform.ResourceState) (interface{}, error) { | ||
| client, err := conf.CssV1Client(env.OS_REGION_NAME) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error creating CSS v1 client: %s", err) | ||
| } | ||
|
|
||
| clusterID := os.Getenv("OS_CSS_CLUSTER_ID") | ||
| if clusterID == "" { | ||
| return nil, fmt.Errorf("environment variable OS_CSS_CLUSTER_ID is not set") | ||
| } | ||
|
|
||
| return load_balancer.Get(client, clusterID) | ||
| } | ||
|
|
||
| // TestAccCssLoadBalancerConfiguration_basic performs acceptance testing for CSS load balancer configuration | ||
| func TestAccCssLoadBalancerConfiguration_basic(t *testing.T) { | ||
| clusterID := os.Getenv("OS_CSS_CLUSTER_ID") | ||
| if clusterID == "" { | ||
| t.Skip("OS_CSS_CLUSTER_ID env var is not set") | ||
| } | ||
|
|
||
| var obj load_balancer.LoadBalancerResp | ||
| rName := "opentelekomcloud_css_loadbalancer_v1.css_lb" | ||
| rc := common.InitResourceCheck( | ||
| rName, | ||
| &obj, | ||
| getCssLoadBalancerFunc, | ||
| ) | ||
|
|
||
| resource.ParallelTest(t, resource.TestCase{ | ||
| PreCheck: func() { common.TestAccPreCheck(t) }, | ||
| ProviderFactories: common.TestAccProviderFactories, | ||
| CheckDestroy: checkCssLoadBalancerDisable, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: testCssLoadBalancerV1_basic(clusterID), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| rc.CheckResourceExists(), | ||
| resource.TestCheckResourceAttr(rName, "cluster_id", clusterID), | ||
| resource.TestCheckResourceAttr(rName, "agency", "css_upgrade_agency"), | ||
| ), | ||
| }, | ||
| { | ||
| Config: testCssLoadBalancerV1_update(clusterID), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| rc.CheckResourceExists(), | ||
| resource.TestCheckResourceAttr(rName, "cluster_id", clusterID), | ||
| resource.TestCheckResourceAttr(rName, "agency", "css_upgrade_agency"), | ||
| ), | ||
| }, | ||
| { | ||
| Config: testCssLoadBalancerV1_update2(clusterID), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| rc.CheckResourceExists(), | ||
| resource.TestCheckResourceAttr(rName, "cluster_id", clusterID), | ||
| resource.TestCheckResourceAttr(rName, "agency", "css_upgrade_agency"), | ||
| ), | ||
| }, | ||
| { | ||
| ResourceName: rName, | ||
| ImportState: true, | ||
| ImportStateVerify: true, | ||
| // Optionally provide ImportStateIdFunc if import ID differs from default | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| // testCssLoadBalancerV1_basic returns Terraform config string for the basic configuration | ||
| func testCssLoadBalancerV1_basic(clusterID string) string { | ||
| return fmt.Sprintf(` | ||
| variable "elb_id" {} | ||
| variable "server_cert_id" {} | ||
|
|
||
| resource "opentelekomcloud_css_loadbalancer_v1" "css_lb" { | ||
| cluster_id = "%s" | ||
| elb_id = var.elb_id | ||
| agency = "css_upgrade_agency" | ||
|
|
||
| listener { | ||
| protocol = "HTTPS" | ||
| protocol_port = 443 | ||
| server_cert_id = var.server_cert_id | ||
| } | ||
| } | ||
| `, clusterID) | ||
| } | ||
|
|
||
| // testCssLoadBalancerV1_update returns updated Terraform config (without listener block) | ||
| func testCssLoadBalancerV1_update(clusterID string) string { | ||
| return fmt.Sprintf(` | ||
| variable "elb_id" {} | ||
|
|
||
| resource "opentelekomcloud_css_loadbalancer_v1" "css_lb" { | ||
| cluster_id = "%s" | ||
| elb_id = var.elb_id | ||
| agency = "css_upgrade_agency" | ||
| } | ||
| `, clusterID) | ||
| } | ||
|
|
||
| // testCssLoadBalancerV1_update2 returns updated Terraform config (re-adding listener block) | ||
| func testCssLoadBalancerV1_update2(clusterID string) string { | ||
| return fmt.Sprintf(` | ||
| variable "elb_id" {} | ||
| variable "server_cert_id" {} | ||
|
|
||
| resource "opentelekomcloud_css_loadbalancer_v1" "css_lb" { | ||
| cluster_id = "%s" | ||
| elb_id = var.elb_id | ||
| agency = "css_upgrade_agency" | ||
|
|
||
| listener { | ||
| protocol = "HTTPS" | ||
| protocol_port = 443 | ||
| server_cert_id = var.server_cert_id | ||
| } | ||
| } | ||
| `, clusterID) | ||
| } | ||
|
|
||
| // checkCssLoadBalancerDisable verifies that the load balancer was disabled or removed | ||
| func checkCssLoadBalancerDisable(s *terraform.State) error { | ||
| config := common.TestAccProvider.Meta().(*cfg.Config) | ||
|
|
||
| client, err := config.CssV1Client(env.OS_REGION_NAME) | ||
| if err != nil { | ||
| return fmt.Errorf("error creating CSS v1 client: %s", err) | ||
| } | ||
|
|
||
| clusterID := os.Getenv("OS_CSS_CLUSTER_ID") | ||
| if clusterID == "" { | ||
| return fmt.Errorf("environment variable OS_CSS_CLUSTER_ID is not set") | ||
| } | ||
|
|
||
| details, err := load_balancer.Get(client, clusterID) | ||
| if err != nil { | ||
| // Assuming a 404 or not found means it's destroyed | ||
| return nil | ||
| } | ||
|
|
||
| if details.Enabled { | ||
| return fmt.Errorf("load_balancer is still enabled for cluster %s", clusterID) | ||
| } | ||
|
|
||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add more attributes which is computed, like:
and add import feature