Skip to content

Commit

Permalink
Allow zero sized topology elements when autoscaling is enabled (#472)
Browse files Browse the repository at this point in the history
* Allow zero sized topology elements when autoscaling is enabled

* Fix acceptance test
  • Loading branch information
tobio authored Apr 26, 2022
1 parent 37a0129 commit c46a6dd
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 14 deletions.
36 changes: 25 additions & 11 deletions ec/acc/deployment_autoscaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,44 @@ func TestAccDeployment_autoscaling(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resName, "elasticsearch.#", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.autoscale", "true"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.#", "3"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.#", "5"),
resource.TestCheckResourceAttrSet(resName, "elasticsearch.0.topology.0.instance_configuration_id"),

resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.id", "hot_content"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.size", "1g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.id", "cold"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.size", "0g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.size_resource", "memory"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.zone_count", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.autoscaling.#", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.autoscaling.0.max_size", "8g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.autoscaling.0.max_size", "58g"),

resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.1.id", "ml"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.1.size", "1g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.1.id", "frozen"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.1.size", "0g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.1.size_resource", "memory"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.1.zone_count", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.1.autoscaling.#", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.1.autoscaling.0.max_size", "4g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.1.autoscaling.0.min_size", "1g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.1.autoscaling.0.max_size", "120g"),

resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.2.id", "warm"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.2.size", "2g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.2.id", "hot_content"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.2.size", "1g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.2.size_resource", "memory"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.2.zone_count", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.2.autoscaling.#", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.2.autoscaling.0.max_size", "15g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.2.autoscaling.0.max_size", "8g"),

resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.3.id", "ml"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.3.size", "1g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.3.size_resource", "memory"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.3.zone_count", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.3.autoscaling.#", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.3.autoscaling.0.max_size", "4g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.3.autoscaling.0.min_size", "1g"),

resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.4.id", "warm"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.4.size", "2g"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.4.size_resource", "memory"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.4.zone_count", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.4.autoscaling.#", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.4.autoscaling.0.max_size", "15g"),

resource.TestCheckResourceAttr(resName, "kibana.#", "0"),
resource.TestCheckResourceAttr(resName, "apm.#", "0"),
Expand Down
14 changes: 13 additions & 1 deletion ec/acc/testdata/deployment_autoscaling_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ resource "ec_deployment" "autoscaling" {
elasticsearch {
autoscale = "true"

topology {
id = "cold"
size = "0g"
zone_count = 1
}

topology {
id = "frozen"
size = "0g"
zone_count = 1
}

topology {
id = "hot_content"
size = "1g"
Expand All @@ -38,4 +50,4 @@ resource "ec_deployment" "autoscaling" {
}
}
}
}
}
14 changes: 13 additions & 1 deletion ec/acc/testdata/deployment_autoscaling_2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ resource "ec_deployment" "autoscaling" {
elasticsearch {
autoscale = "false"

topology {
id = "cold"
size = "0g"
zone_count = 1
}

topology {
id = "frozen"
size = "0g"
zone_count = 1
}

topology {
id = "hot_content"
size = "1g"
Expand All @@ -38,4 +50,4 @@ resource "ec_deployment" "autoscaling" {
}
}
}
}
}
9 changes: 8 additions & 1 deletion ec/ecresource/deploymentresource/elasticsearch_flatteners.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,18 @@ func flattenEsResources(in []*models.ElasticsearchResourceInfo, name string, rem
return result, nil
}

func isPotentiallySizedTopology(topology *models.ElasticsearchClusterTopologyElement, isAutoscaling bool) bool {
currentlySized := topology.Size != nil && topology.Size.Value != nil && *topology.Size.Value > 0
canBeSized := isAutoscaling && topology.AutoscalingMax != nil && topology.AutoscalingMax.Value != nil && *topology.AutoscalingMax.Value > 0

return currentlySized || canBeSized
}

func flattenEsTopology(plan *models.ElasticsearchClusterPlan) ([]interface{}, error) {
result := make([]interface{}, 0, len(plan.ClusterTopology))
for _, topology := range plan.ClusterTopology {
var m = make(map[string]interface{})
if topology.Size == nil || topology.Size.Value == nil || *topology.Size.Value == 0 {
if !isPotentiallySizedTopology(topology, plan.AutoscalingEnabled != nil && *plan.AutoscalingEnabled) {
continue
}

Expand Down
64 changes: 64 additions & 0 deletions ec/ecresource/deploymentresource/elasticsearch_flatteners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,70 @@ func Test_flattenEsTopology(t *testing.T) {
"node_type_master": "true",
}},
},
{
name: "includes unsized autoscaling topologies",
args: args{plan: &models.ElasticsearchClusterPlan{
AutoscalingEnabled: ec.Bool(true),
ClusterTopology: []*models.ElasticsearchClusterTopologyElement{
{
ID: "hot_content",
ZoneCount: 1,
InstanceConfigurationID: "aws.data.highio.i3",
Size: &models.TopologySize{
Value: ec.Int32(4096), Resource: ec.String("memory"),
},
NodeType: &models.ElasticsearchNodeType{
Data: ec.Bool(true),
Ingest: ec.Bool(true),
Master: ec.Bool(true),
},
},
{
ID: "ml",
ZoneCount: 1,
InstanceConfigurationID: "aws.ml.m5",
Size: &models.TopologySize{
Value: ec.Int32(0), Resource: ec.String("memory"),
},
AutoscalingMax: &models.TopologySize{
Value: ec.Int32(8192), Resource: ec.String("memory"),
},
AutoscalingMin: &models.TopologySize{
Value: ec.Int32(0), Resource: ec.String("memory"),
},
},
},
}},
want: []interface{}{
map[string]interface{}{
"config": func() []interface{} { return nil }(),
"id": "hot_content",
"instance_configuration_id": "aws.data.highio.i3",
"size": "4g",
"size_resource": "memory",
"zone_count": int32(1),
"node_type_data": "true",
"node_type_ingest": "true",
"node_type_master": "true",
},
map[string]interface{}{
"config": func() []interface{} { return nil }(),
"id": "ml",
"instance_configuration_id": "aws.ml.m5",
"size": "0g",
"size_resource": "memory",
"zone_count": int32(1),
"autoscaling": []interface{}{
map[string]interface{}{
"max_size": "8g",
"max_size_resource": "memory",
"min_size": "0g",
"min_size_resource": "memory",
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit c46a6dd

Please sign in to comment.