Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec_deployment: Add config to stateless resources #49

Merged
merged 7 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions ec/acc/deployment_appsearch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// 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"
"io/ioutil"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDeployment_appsearch(t *testing.T) {
resName := "ec_deployment.appsearch"
randomName := prefix + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
const startCfg = "testdata/deployment_appsearch.tf"
const topologyConfig = "testdata/deployment_appsearch_topology_config.tf"
const topConfig = "testdata/deployment_appsearch_top_config.tf"
cfg := testAccDeploymentResourceAppsearch(t, startCfg, randomName, region, deploymentVersionAppsearch)
topologyConfigCfg := testAccDeploymentResourceBasic(t, topologyConfig, randomName, region, deploymentVersionAppsearch)
topConfigCfg := testAccDeploymentResourceBasic(t, topConfig, randomName, region, deploymentVersionAppsearch)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactory,
CheckDestroy: testAccDeploymentDestroy,
Steps: []resource.TestStep{
{
Config: cfg,
Check: checkAppSearchDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "appsearch.0.config.#", "0"),
resource.TestCheckResourceAttr(resName, "appsearch.0.topology.0.config.#", "0"),
),
},
// Ensure that no diff is generated.
{Config: cfg, PlanOnly: true},
{
Config: topologyConfigCfg,
Check: checkAppSearchDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "appsearch.0.config.#", "0"),
resource.TestCheckResourceAttr(resName, "appsearch.0.topology.0.config.#", "1"),
resource.TestCheckResourceAttr(resName, "appsearch.0.topology.0.config.0.user_settings_yaml", "app_search.auth.source: standard"),
),
},
// Ensure that no diff is generated.
{Config: topologyConfigCfg, PlanOnly: true},
{
Config: topConfigCfg,
Check: checkAppSearchDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "appsearch.0.config.#", "1"),
resource.TestCheckResourceAttr(resName, "appsearch.0.config.0.user_settings_yaml", "app_search.auth.source: standard"),
resource.TestCheckResourceAttr(resName, "appsearch.0.topology.0.config.#", "0"),
),
},
// Ensure that no diff is generated.
{Config: topConfigCfg, PlanOnly: true},
{
Config: cfg,
Check: checkAppSearchDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "appsearch.0.config.#", "0"),
resource.TestCheckResourceAttr(resName, "appsearch.0.topology.0.config.#", "0"),
),
},
// Ensure that no diff is generated.
{Config: cfg, PlanOnly: true},
},
})
}

func testAccDeploymentResourceAppsearch(t *testing.T, fileName, name, region, version string) string {
b, err := ioutil.ReadFile(fileName)
if err != nil {
t.Fatal(err)
}
return fmt.Sprintf(string(b),
name, region, version,
)
}

func checkAppSearchDeploymentResource(resName, randomDeploymentName string, checks ...resource.TestCheckFunc) resource.TestCheckFunc {
return resource.ComposeAggregateTestCheckFunc(
testAccCheckDeploymentExists(resName),
resource.TestCheckResourceAttr(resName, "name", randomDeploymentName),
resource.TestCheckResourceAttr(resName, "region", region),
resource.TestCheckResourceAttr(resName, "appsearch.#", "1"),
resource.TestCheckResourceAttr(resName, "appsearch.0.version", deploymentVersionAppsearch),
resource.TestCheckResourceAttr(resName, "appsearch.0.region", region),
resource.TestCheckResourceAttr(resName, "appsearch.0.topology.0.memory_per_node", "2g"),
resource.TestCheckResourceAttrSet(resName, "appsearch.0.http_endpoint"),
resource.TestCheckResourceAttrSet(resName, "appsearch.0.https_endpoint"),
resource.TestCheckResourceAttr(resName, "elasticsearch.#", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.version", deploymentVersionAppsearch),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.region", region),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.memory_per_node", "1g"),
resource.TestCheckResourceAttrSet(resName, "elasticsearch.0.http_endpoint"),
resource.TestCheckResourceAttrSet(resName, "elasticsearch.0.https_endpoint"),
resource.TestCheckResourceAttr(resName, "kibana.#", "1"),
resource.TestCheckResourceAttr(resName, "kibana.0.version", deploymentVersionAppsearch),
resource.TestCheckResourceAttr(resName, "kibana.0.region", region),
resource.TestCheckResourceAttr(resName, "kibana.0.topology.0.memory_per_node", "1g"),
resource.TestCheckResourceAttrSet(resName, "kibana.0.http_endpoint"),
resource.TestCheckResourceAttrSet(resName, "kibana.0.https_endpoint"),
resource.ComposeAggregateTestCheckFunc(checks...),
)
}
31 changes: 18 additions & 13 deletions ec/acc/deployment_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func TestAccDeployment_basic(t *testing.T) {
resName := "ec_deployment.basic"
randomName := prefix + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
startCfg := "testdata/deployment_basic.tf"
firstChange := "testdata/deployment_basic_topology_config.tf"
secondChange := "testdata/deployment_basic_top_config.tf"
topologyConfig := "testdata/deployment_basic_topology_config.tf"
topConfig := "testdata/deployment_basic_top_config.tf"
cfg := testAccDeploymentResourceBasic(t, startCfg, randomName, region, deploymentVersion)
firstChangeCfg := testAccDeploymentResourceBasic(t, firstChange, randomName, region, deploymentVersion)
secondChangeCfg := testAccDeploymentResourceBasic(t, secondChange, randomName, region, deploymentVersion)
topologyConfigCfg := testAccDeploymentResourceBasic(t, topologyConfig, randomName, region, deploymentVersion)
topConfigCfg := testAccDeploymentResourceBasic(t, topConfig, randomName, region, deploymentVersion)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -51,28 +51,36 @@ func TestAccDeployment_basic(t *testing.T) {
// Ensure that no diff is generated.
{Config: cfg, PlanOnly: true},
{
Config: firstChangeCfg,
Config: topologyConfigCfg,
Check: checkBasicDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "apm.0.config.0.debug_enabled", "false"),
resource.TestCheckResourceAttr(resName, "apm.0.topology.0.config.0.debug_enabled", "true"),
resource.TestCheckResourceAttr(resName, "kibana.0.config.#", "0"),
resource.TestCheckResourceAttr(resName, "kibana.0.topology.0.config.#", "1"),
resource.TestCheckResourceAttr(resName, "kibana.0.topology.0.config.0.user_settings_yaml", "csp.warnLegacyBrowsers: true"),
),
},
// Ensure that no diff is generated.
{Config: firstChangeCfg, PlanOnly: true},
{Config: topologyConfigCfg, PlanOnly: true},
{
Config: secondChangeCfg,
Config: topConfigCfg,
Check: checkBasicDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "apm.0.config.0.debug_enabled", "true"),
resource.TestCheckResourceAttr(resName, "apm.0.topology.0.config.0.debug_enabled", "false"),
resource.TestCheckResourceAttr(resName, "kibana.0.config.#", "1"),
resource.TestCheckResourceAttr(resName, "kibana.0.config.0.user_settings_yaml", "csp.warnLegacyBrowsers: true"),
resource.TestCheckResourceAttr(resName, "kibana.0.topology.0.config.#", "0"),
),
},
// Ensure that no diff is generated.
{Config: secondChangeCfg, PlanOnly: true},
{Config: topConfigCfg, PlanOnly: true},
{
Config: cfg,
Check: checkBasicDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "apm.0.config.0.debug_enabled", "false"),
resource.TestCheckResourceAttr(resName, "apm.0.topology.0.config.0.debug_enabled", "false"),
resource.TestCheckResourceAttr(resName, "kibana.0.config.#", "0"),
resource.TestCheckResourceAttr(resName, "kibana.0.topology.0.config.#", "0"),
),
},
// Ensure that no diff is generated.
Expand All @@ -93,9 +101,6 @@ func testAccDeploymentResourceBasic(t *testing.T, fileName, name, region, versio
}

func checkBasicDeploymentResource(resName, randomDeploymentName string, checks ...resource.TestCheckFunc) resource.TestCheckFunc {
var apmConfigSecretToken = resource.TestCheckResourceAttrSet(resName, "apm.0.config.0.secret_token")
var apmTopologyConfigSecretToken = resource.TestCheckResourceAttrSet(resName, "apm.0.topology.0.config.0.secret_token")

return resource.ComposeAggregateTestCheckFunc(
testAccCheckDeploymentExists(resName),
resource.TestCheckResourceAttr(resName, "name", randomDeploymentName),
Expand All @@ -104,8 +109,8 @@ func checkBasicDeploymentResource(resName, randomDeploymentName string, checks .
resource.TestCheckResourceAttr(resName, "apm.0.version", deploymentVersion),
resource.TestCheckResourceAttr(resName, "apm.0.region", region),
resource.TestCheckResourceAttr(resName, "apm.0.topology.0.memory_per_node", "0.5g"),
apmConfigSecretToken,
apmTopologyConfigSecretToken,
resource.TestCheckResourceAttrSet(resName, "apm.0.config.0.secret_token"),
resource.TestCheckResourceAttrSet(resName, "apm.0.topology.0.config.0.secret_token"),
resource.TestCheckResourceAttrSet(resName, "apm.0.http_endpoint"),
resource.TestCheckResourceAttrSet(resName, "apm.0.https_endpoint"),
resource.TestCheckResourceAttr(resName, "elasticsearch.#", "1"),
Expand Down
122 changes: 122 additions & 0 deletions ec/acc/deployment_enterprise_search_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// 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"
"io/ioutil"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDeployment_enterpriseSearch(t *testing.T) {
resName := "ec_deployment.enterprise_search"
randomName := prefix + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
const startCfg = "testdata/deployment_enterprise_search.tf"
const topologyConfig = "testdata/deployment_enterprise_search_topology_config.tf"
const topConfig = "testdata/deployment_enterprise_search_top_config.tf"
cfg := testAccDeploymentResourceEnterpriseSearch(t, startCfg, randomName, region, deploymentVersion)
topologyConfigCfg := testAccDeploymentResourceEnterpriseSearch(t, topologyConfig, randomName, region, deploymentVersion)
topConfigCfg := testAccDeploymentResourceEnterpriseSearch(t, topConfig, randomName, region, deploymentVersion)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactory,
CheckDestroy: testAccDeploymentDestroy,
Steps: []resource.TestStep{
{
Config: cfg,
Check: checkEnterpriseSearchDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "enterprise_search.0.config.#", "0"),
resource.TestCheckResourceAttr(resName, "enterprise_search.0.topology.0.config.#", "0"),
),
},
// Ensure that no diff is generated.
{Config: cfg, PlanOnly: true},
{
Config: topologyConfigCfg,
Check: checkEnterpriseSearchDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "enterprise_search.0.config.#", "0"),
resource.TestCheckResourceAttr(resName, "enterprise_search.0.topology.0.config.#", "1"),
resource.TestCheckResourceAttr(resName, "enterprise_search.0.topology.0.config.0.user_settings_yaml", "ent_search.auth.source: standard"),
),
},
// Ensure that no diff is generated.
{Config: topologyConfigCfg, PlanOnly: true},
{
Config: topConfigCfg,
Check: checkEnterpriseSearchDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "enterprise_search.0.config.#", "1"),
resource.TestCheckResourceAttr(resName, "enterprise_search.0.config.0.user_settings_yaml", "ent_search.auth.source: standard"),
resource.TestCheckResourceAttr(resName, "enterprise_search.0.topology.0.config.#", "0"),
),
},
// Ensure that no diff is generated.
{Config: topConfigCfg, PlanOnly: true},
{
Config: cfg,
Check: checkEnterpriseSearchDeploymentResource(resName, randomName,
resource.TestCheckResourceAttr(resName, "enterprise_search.0.config.#", "0"),
resource.TestCheckResourceAttr(resName, "enterprise_search.0.topology.0.config.#", "0"),
),
},
// Ensure that no diff is generated.
{Config: cfg, PlanOnly: true},
// TODO: Import case when import is ready.
},
})
}

func testAccDeploymentResourceEnterpriseSearch(t *testing.T, fileName, name, region, version string) string {
b, err := ioutil.ReadFile(fileName)
if err != nil {
t.Fatal(err)
}
return fmt.Sprintf(string(b),
name, region, version,
)
}

func checkEnterpriseSearchDeploymentResource(resName, randomDeploymentName string, checks ...resource.TestCheckFunc) resource.TestCheckFunc {
return resource.ComposeAggregateTestCheckFunc(
testAccCheckDeploymentExists(resName),
resource.TestCheckResourceAttr(resName, "name", randomDeploymentName),
resource.TestCheckResourceAttr(resName, "region", region),
resource.TestCheckResourceAttr(resName, "enterprise_search.#", "1"),
resource.TestCheckResourceAttr(resName, "enterprise_search.0.version", deploymentVersion),
resource.TestCheckResourceAttr(resName, "enterprise_search.0.region", region),
resource.TestCheckResourceAttr(resName, "enterprise_search.0.topology.0.memory_per_node", "2g"),
resource.TestCheckResourceAttrSet(resName, "enterprise_search.0.http_endpoint"),
resource.TestCheckResourceAttrSet(resName, "enterprise_search.0.https_endpoint"),
resource.TestCheckResourceAttr(resName, "elasticsearch.#", "1"),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.version", deploymentVersion),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.region", region),
resource.TestCheckResourceAttr(resName, "elasticsearch.0.topology.0.memory_per_node", "1g"),
resource.TestCheckResourceAttrSet(resName, "elasticsearch.0.http_endpoint"),
resource.TestCheckResourceAttrSet(resName, "elasticsearch.0.https_endpoint"),
resource.TestCheckResourceAttr(resName, "kibana.#", "1"),
resource.TestCheckResourceAttr(resName, "kibana.0.version", deploymentVersion),
resource.TestCheckResourceAttr(resName, "kibana.0.region", region),
resource.TestCheckResourceAttr(resName, "kibana.0.topology.0.memory_per_node", "1g"),
resource.TestCheckResourceAttrSet(resName, "kibana.0.http_endpoint"),
resource.TestCheckResourceAttrSet(resName, "kibana.0.https_endpoint"),
resource.ComposeAggregateTestCheckFunc(checks...),
)
}
Loading