-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically add and remove dedicated masters.
If no master tier is configured, it is automatically added/removed: - Added if the number of nodes is >= the dedicated master threshold - Removed if the number of nodes is < the dedicated master threshold
- Loading branch information
Showing
10 changed files
with
686 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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,75 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you 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 acc | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccDeployment_add_dedicated_master(t *testing.T) { | ||
resName := "ec_deployment.basic" | ||
randomName := prefix + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
randomAlias := "alias" + acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) | ||
|
||
cfg5nodes := buildConfiguration(t, "testdata/deployment_dedicated_master_5_nodes.tf", randomAlias, randomName, getRegion(), defaultTemplate) | ||
cfg6nodes := buildConfiguration(t, "testdata/deployment_dedicated_master_6_nodes.tf", randomAlias, randomName, getRegion(), defaultTemplate) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProviderFactory, | ||
CheckDestroy: testAccDeploymentDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: cfg6nodes, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
// Master tier should be enabled | ||
resource.TestCheckResourceAttr(resName, "elasticsearch.master.size", "4g"), | ||
resource.TestCheckResourceAttr(resName, "elasticsearch.master.zone_count", "3"), | ||
), | ||
}, | ||
{ | ||
Config: cfg5nodes, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
// Master tier should be disabled | ||
resource.TestCheckResourceAttr(resName, "elasticsearch.master.size", "0g"), | ||
resource.TestCheckResourceAttr(resName, "elasticsearch.master.zone_count", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func buildConfiguration(t *testing.T, fileName, alias, name, region, depTpl string) string { | ||
t.Helper() | ||
requiresAPIConn(t) | ||
|
||
deploymentTpl := setDefaultTemplate(region, depTpl) | ||
|
||
b, err := os.ReadFile(fileName) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return fmt.Sprintf(string(b), | ||
region, alias, name, region, deploymentTpl, | ||
) | ||
} |
This file contains 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,28 @@ | ||
data "ec_stack" "latest" { | ||
version_regex = "latest" | ||
region = "%s" | ||
} | ||
|
||
resource "ec_deployment" "basic" { | ||
alias = "%s" | ||
name = "%s" | ||
region = "%s" | ||
version = data.ec_stack.latest.version | ||
deployment_template_id = "%s" | ||
|
||
elasticsearch = { | ||
hot = { | ||
size = "2g" | ||
zone_count = 2 | ||
autoscaling = {} | ||
} | ||
|
||
warm = { | ||
size = "2g" | ||
zone_count = 3 | ||
autoscaling = {} | ||
} | ||
} | ||
|
||
kibana = {} | ||
} |
This file contains 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,28 @@ | ||
data "ec_stack" "latest" { | ||
version_regex = "latest" | ||
region = "%s" | ||
} | ||
|
||
resource "ec_deployment" "basic" { | ||
alias = "%s" | ||
name = "%s" | ||
region = "%s" | ||
version = data.ec_stack.latest.version | ||
deployment_template_id = "%s" | ||
|
||
elasticsearch = { | ||
hot = { | ||
size = "2g" | ||
zone_count = 3 | ||
autoscaling = {} | ||
} | ||
|
||
warm = { | ||
size = "2g" | ||
zone_count = 3 | ||
autoscaling = {} | ||
} | ||
} | ||
|
||
kibana = {} | ||
} |
This file contains 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
This file contains 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
This file contains 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,58 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you 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 deploymentresource | ||
|
||
import ( | ||
"context" | ||
"github.com/elastic/cloud-sdk-go/pkg/api/deploymentapi/deptemplateapi" | ||
deploymentv2 "github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/deployment/v2" | ||
"github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/planmodifiers" | ||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
) | ||
|
||
var _ resource.ResourceWithModifyPlan = &Resource{} | ||
|
||
func (r Resource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { | ||
if req.Plan.Raw.IsNull() { | ||
// Resource is being destroyed | ||
return | ||
} | ||
|
||
var plan deploymentv2.DeploymentTF | ||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
template, err := deptemplateapi.Get(deptemplateapi.GetParams{ | ||
API: r.client, | ||
TemplateID: plan.DeploymentTemplateId.ValueString(), | ||
Region: plan.Region.ValueString(), | ||
HideInstanceConfigurations: false, | ||
ShowMaxZones: true, | ||
}) | ||
if err != nil { | ||
resp.Diagnostics.AddError("Failed to get deployment-template", err.Error()) | ||
return | ||
} | ||
|
||
planmodifiers.UpdateDedicatedMasterTier(ctx, req, resp, *template) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
} |
Oops, something went wrong.