Skip to content

Commit

Permalink
Use the lowest version from a running resource, not just the lowest (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tobio authored Apr 18, 2023
1 parent df131ca commit d2a0f34
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 12 deletions.
23 changes: 22 additions & 1 deletion ec/acc/deployment_post_node_role_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func TestAccDeployment_post_node_roles(t *testing.T) {
resName := "ec_deployment.post_nr_upgrade"
randomName := prefix + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
startCfg := "testdata/deployment_post_node_roles_upgrade_1.tf"
upgradeVersionCfg := "testdata/deployment_post_node_roles_upgrade_2.tf"
withoutEnterpriseSearch := "testdata/deployment_post_node_roles_upgrade_2.tf"
upgradeVersionCfg := "testdata/deployment_post_node_roles_upgrade_3.tf"

cfgF := func(cfg string) string {
return fixtureAccDeploymentResourceBasic(
Expand All @@ -55,6 +56,26 @@ func TestAccDeployment_post_node_roles(t *testing.T) {
resource.TestCheckNoResourceAttr(resName, "elastic.hot.node_type_master"),
resource.TestCheckNoResourceAttr(resName, "elastic.hot.node_type_ml"),

resource.TestCheckResourceAttrSet(resName, "enterprise_search.size"),
resource.TestCheckResourceAttrSet(resName, "kibana.size"),

resource.TestCheckNoResourceAttr(resName, "apm"),
),
},
{
Config: cfgF(withoutEnterpriseSearch),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(resName, "elasticsearch.hot.instance_configuration_id"),
resource.TestCheckResourceAttr(resName, "elasticsearch.hot.size", "1g"),
resource.TestCheckResourceAttrSet(resName, "elasticsearch.hot.node_roles.#"),
resource.TestCheckResourceAttr(resName, "elasticsearch.hot.size_resource", "memory"),
resource.TestCheckResourceAttr(resName, "elasticsearch.hot.zone_count", "1"),

resource.TestCheckNoResourceAttr(resName, "elastic.hot.node_type_data"),
resource.TestCheckNoResourceAttr(resName, "elastic.hot.node_type_ingest"),
resource.TestCheckNoResourceAttr(resName, "elastic.hot.node_type_master"),
resource.TestCheckNoResourceAttr(resName, "elastic.hot.node_type_ml"),

resource.TestCheckNoResourceAttr(resName, "kibana"),
resource.TestCheckNoResourceAttr(resName, "apm"),
resource.TestCheckNoResourceAttr(resName, "enterprise_search"),
Expand Down
5 changes: 4 additions & 1 deletion ec/acc/testdata/deployment_post_node_roles_upgrade_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ resource "ec_deployment" "post_nr_upgrade" {
autoscaling = {}
}
}
}

kibana = {}
enterprise_search = {}
}
4 changes: 2 additions & 2 deletions ec/acc/testdata/deployment_post_node_roles_upgrade_2.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data "ec_stack" "post_node_roles_upgrade" {
version_regex = "7.??.?"
version_regex = "7.12.?"
region = "%s"
}

Expand All @@ -16,4 +16,4 @@ resource "ec_deployment" "post_nr_upgrade" {
autoscaling = {}
}
}
}
}
19 changes: 19 additions & 0 deletions ec/acc/testdata/deployment_post_node_roles_upgrade_3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
data "ec_stack" "post_node_roles_upgrade" {
version_regex = "7.17.?"
region = "%s"
}

resource "ec_deployment" "post_nr_upgrade" {
name = "%s"
region = "%s"
version = data.ec_stack.post_node_roles_upgrade.version
deployment_template_id = "%s"

elasticsearch = {
hot = {
size = "1g"
zone_count = 1
autoscaling = {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,36 +258,36 @@ func getLowestVersion(res *models.DeploymentResources) (string, error) {
}

for _, r := range res.Kibana {
if !util.IsCurrentKibanaPlanEmpty(r) {
if !util.IsCurrentKibanaPlanEmpty(r) && !kibanav2.IsKibanaStopped(r) {
v := r.Info.PlanInfo.Current.Plan.Kibana.Version
if err := swapLowerVersion(&version, v); err != nil && !kibanav2.IsKibanaStopped(r) {
if err := swapLowerVersion(&version, v); err != nil {
return version.String(), fmt.Errorf("kibana version '%s' is not semver compliant: %w", v, err)
}
}
}

for _, r := range res.Apm {
if !util.IsCurrentApmPlanEmpty(r) {
if !util.IsCurrentApmPlanEmpty(r) && !apmv2.IsApmStopped(r) {
v := r.Info.PlanInfo.Current.Plan.Apm.Version
if err := swapLowerVersion(&version, v); err != nil && !apmv2.IsApmStopped(r) {
if err := swapLowerVersion(&version, v); err != nil {
return version.String(), fmt.Errorf("apm version '%s' is not semver compliant: %w", v, err)
}
}
}

for _, r := range res.IntegrationsServer {
if !util.IsCurrentIntegrationsServerPlanEmpty(r) {
if !util.IsCurrentIntegrationsServerPlanEmpty(r) && !integrationsserverv2.IsIntegrationsServerStopped(r) {
v := r.Info.PlanInfo.Current.Plan.IntegrationsServer.Version
if err := swapLowerVersion(&version, v); err != nil && !integrationsserverv2.IsIntegrationsServerStopped(r) {
if err := swapLowerVersion(&version, v); err != nil {
return version.String(), fmt.Errorf("integrations_server version '%s' is not semver compliant: %w", v, err)
}
}
}

for _, r := range res.EnterpriseSearch {
if !util.IsCurrentEssPlanEmpty(r) {
if !util.IsCurrentEssPlanEmpty(r) && !enterprisesearchv2.IsEnterpriseSearchStopped(r) {
v := r.Info.PlanInfo.Current.Plan.EnterpriseSearch.Version
if err := swapLowerVersion(&version, v); err != nil && !enterprisesearchv2.IsEnterpriseSearchStopped(r) {
if err := swapLowerVersion(&version, v); err != nil {
return version.String(), fmt.Errorf("enterprise search version '%s' is not semver compliant: %w", v, err)
}
}
Expand Down

0 comments on commit d2a0f34

Please sign in to comment.