Skip to content

Commit

Permalink
Support deployments without autoscaling fields defined in the deploym…
Browse files Browse the repository at this point in the history
…ents data source (#667)

* Support deployments without autoscaling fields defined in the deployments data source

* Changelog
  • Loading branch information
tobio authored Jun 27, 2023
1 parent 4bf804d commit e9df5df
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/667.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug-fix
datasource/deployments: Fix bug causing a provider crash when no autoscaling fields are defined in the matching deployment
```
72 changes: 67 additions & 5 deletions ec/acc/datasource_deployment_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func TestAccDatasourceDeployment_basic(t *testing.T) {
secondRandomName := prefix + "-" + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
randomAlias := "alias" + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
depCfg := "testdata/datasource_deployment_basic.tf"
cfg := fixtureAccDeploymentDatasourceBasicAlias(t, depCfg, randomAlias, randomName, secondRandomName, getRegion(), computeOpTemplate)
cfgWithAutoscaling := fixtureAccDeploymentDatasourceBasicAlias(t, depCfg, randomAlias, randomName, secondRandomName, getRegion(), computeOpTemplate, "true")
cfgWithoutAutoscaling := fixtureAccDeploymentDatasourceBasicAlias(t, depCfg, randomAlias, randomName, secondRandomName, getRegion(), computeOpTemplate, "false")
var namePrefix = secondRandomName[:22]

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -43,7 +44,7 @@ func TestAccDatasourceDeployment_basic(t *testing.T) {
CheckDestroy: testAccDeploymentDestroy,
Steps: []resource.TestStep{
{
Config: cfg,
Config: cfgWithoutAutoscaling,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(datasourceName, "alias", resourceName, "alias"),
Expand Down Expand Up @@ -104,7 +105,68 @@ func TestAccDatasourceDeployment_basic(t *testing.T) {
),
},
{
Config: cfg,
Config: cfgWithAutoscaling,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(datasourceName, "alias", resourceName, "alias"),
resource.TestCheckResourceAttrPair(datasourceName, "region", resourceName, "region"),
resource.TestCheckResourceAttrPair(datasourceName, "deployment_template_id", resourceName, "deployment_template_id"),
resource.TestCheckResourceAttrPair(datasourceName, "traffic_filter.#", resourceName, "traffic_filter.#"),

// Elasticsearch
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch.0.ref_id", resourceName, "elasticsearch.ref_id"),
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch.0.cloud_id", resourceName, "elasticsearch.cloud_id"),
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch.0.resource_id", resourceName, "elasticsearch.resource_id"),
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch.0.http_endpoint_id", resourceName, "elasticsearch.http_endpoint_id"),
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch.0.https_endpoint_id", resourceName, "elasticsearch.https_endpoint_id"),
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch.0.topology.0.instance_configuration_id", resourceName, "elasticsearch.hot.instance_configuration_id"),
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch.0.topology.0.size", resourceName, "elasticsearch.hot.size"),
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch.0.topology.0.size_resource", resourceName, "elasticsearch.hot.size_resource"),
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch.0.topology.0.zone_count", resourceName, "elasticsearch.hot.zone_count"),
resource.TestCheckResourceAttrPair(datasourceName, "elasticsearch.0.topology.0.node_roles.*", resourceName, "elasticsearch.hot.node_roles.*"),

// Kibana
resource.TestCheckResourceAttrPair(datasourceName, "kibana.0.elasticsearch_cluster_ref_id", resourceName, "kibana.elasticsearch_cluster_ref_id"),
resource.TestCheckResourceAttrPair(datasourceName, "kibana.0.ref_id", resourceName, "kibana.ref_id"),
resource.TestCheckResourceAttrPair(datasourceName, "kibana.0.cloud_id", resourceName, "kibana.cloud_id"),
resource.TestCheckResourceAttrPair(datasourceName, "kibana.0.resource_id", resourceName, "kibana.resource_id"),
resource.TestCheckResourceAttrPair(datasourceName, "kibana.0.http_endpoint_id", resourceName, "kibana.http_endpoint_id"),
resource.TestCheckResourceAttrPair(datasourceName, "kibana.0.https_endpoint_id", resourceName, "kibana.https_endpoint_id"),
resource.TestCheckResourceAttrPair(datasourceName, "kibana.0.topology.0.instance_configuration_id", resourceName, "kibana.instance_configuration_id"),
resource.TestCheckResourceAttrPair(datasourceName, "kibana.0.topology.0.size", resourceName, "kibana.size"),
resource.TestCheckResourceAttrPair(datasourceName, "kibana.0.topology.0.size_resource", resourceName, "kibana.size_resource"),
resource.TestCheckResourceAttrPair(datasourceName, "kibana.0.topology.0.zone_count", resourceName, "kibana.zone_count"),

// APM
resource.TestCheckResourceAttrPair(datasourceName, "apm.0.elasticsearch_cluster_ref_id", resourceName, "apm.elasticsearch_cluster_ref_id"),
resource.TestCheckResourceAttrPair(datasourceName, "apm.0.ref_id", resourceName, "apm.ref_id"),
resource.TestCheckResourceAttrPair(datasourceName, "apm.0.cloud_id", resourceName, "apm.cloud_id"),
resource.TestCheckResourceAttrPair(datasourceName, "apm.0.resource_id", resourceName, "apm.resource_id"),
resource.TestCheckResourceAttrPair(datasourceName, "apm.0.http_endpoint_id", resourceName, "apm.http_endpoint_id"),
resource.TestCheckResourceAttrPair(datasourceName, "apm.0.https_endpoint_id", resourceName, "apm.https_endpoint_id"),
resource.TestCheckResourceAttrPair(datasourceName, "apm.0.topology.0.instance_configuration_id", resourceName, "apm.instance_configuration_id"),
resource.TestCheckResourceAttrPair(datasourceName, "apm.0.topology.0.size", resourceName, "apm.size"),
resource.TestCheckResourceAttrPair(datasourceName, "apm.0.topology.0.size_resource", resourceName, "apm.size_resource"),
resource.TestCheckResourceAttrPair(datasourceName, "apm.0.topology.0.zone_count", resourceName, "apm.zone_count"),

// Enterprise Search
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.elasticsearch_cluster_ref_id", resourceName, "enterprise_search.elasticsearch_cluster_ref_id"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.ref_id", resourceName, "enterprise_search.ref_id"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.cloud_id", resourceName, "enterprise_search.cloud_id"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.resource_id", resourceName, "enterprise_search.resource_id"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.http_endpoint_id", resourceName, "enterprise_search.http_endpoint_id"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.https_endpoint_id", resourceName, "enterprise_search.https_endpoint_id"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.topology.0.instance_configuration_id", resourceName, "enterprise_search.instance_configuration_id"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.topology.0.size", resourceName, "enterprise_search.size"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.topology.0.size_resource", resourceName, "enterprise_search.size_resource"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.topology.0.zone_count", resourceName, "enterprise_search.zone_count"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.topology.0.node_type_appserver", resourceName, "enterprise_search.node_type_appserver"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.topology.0.node_type_connector", resourceName, "enterprise_search.node_type_connector"),
resource.TestCheckResourceAttrPair(datasourceName, "enterprise_search.0.topology.0.node_type_worker", resourceName, "enterprise_search.node_type_worker"),
),
},
{
Config: cfgWithAutoscaling,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(depsDatasourceName, "name_prefix", namePrefix),
resource.TestCheckResourceAttrPair(depsDatasourceName, "deployment_template_id", resourceName, "deployment_template_id"),
Expand All @@ -130,7 +192,7 @@ func TestAccDatasourceDeployment_basic(t *testing.T) {
})
}

func fixtureAccDeploymentDatasourceBasicAlias(t *testing.T, fileName, alias, name, secondName, region, depTpl string) string {
func fixtureAccDeploymentDatasourceBasicAlias(t *testing.T, fileName, alias, name, secondName, region, depTpl, autoscaling string) string {
t.Helper()

deploymentTpl := setDefaultTemplate(region, depTpl)
Expand All @@ -139,6 +201,6 @@ func fixtureAccDeploymentDatasourceBasicAlias(t *testing.T, fileName, alias, nam
t.Fatal(err)
}
return fmt.Sprintf(string(b),
region, name, region, deploymentTpl, alias, secondName, region, deploymentTpl, secondName, region, deploymentTpl,
region, name, region, deploymentTpl, autoscaling, alias, secondName, region, deploymentTpl, secondName, region, deploymentTpl,
)
}
3 changes: 2 additions & 1 deletion ec/acc/testdata/datasource_deployment_basic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ resource "ec_deployment" "basic_observability" {
deployment_template_id = "%s"

elasticsearch = {
autoscale = "%s"
hot = {
size = "1g"
zone_count = 1
Expand Down Expand Up @@ -85,4 +86,4 @@ data "ec_deployments" "query" {
depends_on = [
ec_deployment.basic_datasource,
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func flattenElasticsearchTopology(ctx context.Context, plan *models.Elasticsearc
var result = make([]elasticsearchTopologyModelV0, 0, len(plan.ClusterTopology))
for _, topology := range plan.ClusterTopology {
model := elasticsearchTopologyModelV0{
NodeRoles: types.SetNull(types.StringType),
NodeRoles: types.SetNull(types.StringType),
Autoscaling: types.ListNull(elasticsearchAutoscalingElemType()),
}

if isElasticsearchSizePopulated(topology) && *topology.Size.Value == 0 {
Expand Down

0 comments on commit e9df5df

Please sign in to comment.