From 63915ea78bcc2a54555810b452d0bf7629f7284a Mon Sep 17 00:00:00 2001 From: Toby Brain Date: Mon, 17 Apr 2023 21:27:10 +1000 Subject: [PATCH] Use the lowest version from a running resource, not just the lowest --- .../deployment_post_node_role_upgrade_test.go | 23 ++++++++++++++++++- .../deployment_post_node_roles_upgrade_1.tf | 5 +++- .../deployment_post_node_roles_upgrade_2.tf | 4 ++-- .../deployment_post_node_roles_upgrade_3.tf | 19 +++++++++++++++ .../deployment/v2/deployment_read.go | 16 ++++++------- 5 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 ec/acc/testdata/deployment_post_node_roles_upgrade_3.tf diff --git a/ec/acc/deployment_post_node_role_upgrade_test.go b/ec/acc/deployment_post_node_role_upgrade_test.go index a1baf55fa..7329801c6 100644 --- a/ec/acc/deployment_post_node_role_upgrade_test.go +++ b/ec/acc/deployment_post_node_role_upgrade_test.go @@ -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( @@ -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"), diff --git a/ec/acc/testdata/deployment_post_node_roles_upgrade_1.tf b/ec/acc/testdata/deployment_post_node_roles_upgrade_1.tf index 68fe0810d..115388a88 100644 --- a/ec/acc/testdata/deployment_post_node_roles_upgrade_1.tf +++ b/ec/acc/testdata/deployment_post_node_roles_upgrade_1.tf @@ -16,4 +16,7 @@ resource "ec_deployment" "post_nr_upgrade" { autoscaling = {} } } -} \ No newline at end of file + + kibana = {} + enterprise_search = {} +} diff --git a/ec/acc/testdata/deployment_post_node_roles_upgrade_2.tf b/ec/acc/testdata/deployment_post_node_roles_upgrade_2.tf index a28f001f2..b78b97b30 100644 --- a/ec/acc/testdata/deployment_post_node_roles_upgrade_2.tf +++ b/ec/acc/testdata/deployment_post_node_roles_upgrade_2.tf @@ -1,5 +1,5 @@ data "ec_stack" "post_node_roles_upgrade" { - version_regex = "7.??.?" + version_regex = "7.12.?" region = "%s" } @@ -16,4 +16,4 @@ resource "ec_deployment" "post_nr_upgrade" { autoscaling = {} } } -} \ No newline at end of file +} diff --git a/ec/acc/testdata/deployment_post_node_roles_upgrade_3.tf b/ec/acc/testdata/deployment_post_node_roles_upgrade_3.tf new file mode 100644 index 000000000..62e0e081f --- /dev/null +++ b/ec/acc/testdata/deployment_post_node_roles_upgrade_3.tf @@ -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 = {} + } + } +} diff --git a/ec/ecresource/deploymentresource/deployment/v2/deployment_read.go b/ec/ecresource/deploymentresource/deployment/v2/deployment_read.go index 2c0040928..b49fcd4ae 100644 --- a/ec/ecresource/deploymentresource/deployment/v2/deployment_read.go +++ b/ec/ecresource/deploymentresource/deployment/v2/deployment_read.go @@ -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) } }