From 63167b2738e65511fc5efb00740e62ff81581f7c Mon Sep 17 00:00:00 2001 From: Marc Lopez Date: Thu, 20 Aug 2020 15:05:48 +0300 Subject: [PATCH 1/7] Add AppSearch config settings Signed-off-by: Marc Lopez --- .../appsearchstate/appsearch_expanders.go | 50 ++++++++ .../appsearch_expanders_test.go | 119 +++++++++++++----- .../appsearchstate/appsearch_flatteners.go | 58 +++++++++ .../appsearch_flatteners_test.go | 82 ++++++------ .../deploymentresource/schema_appsearch.go | 49 +++++++- 5 files changed, 288 insertions(+), 70 deletions(-) diff --git a/ec/ecresource/deploymentresource/appsearchstate/appsearch_expanders.go b/ec/ecresource/deploymentresource/appsearchstate/appsearch_expanders.go index c63db33c0..a26274fa1 100644 --- a/ec/ecresource/deploymentresource/appsearchstate/appsearch_expanders.go +++ b/ec/ecresource/deploymentresource/appsearchstate/appsearch_expanders.go @@ -18,6 +18,8 @@ package appsearchstate import ( + "reflect" + "github.com/elastic/cloud-sdk-go/pkg/models" "github.com/elastic/cloud-sdk-go/pkg/util/ec" "github.com/terraform-providers/terraform-provider-ec/ec/ecresource/deploymentresource/deploymentstate" @@ -72,6 +74,14 @@ func expandResource(raw interface{}) (*models.AppSearchPayload, error) { } } + if cfg, ok := es["config"]; ok { + if c := expandConfig(cfg); c != nil { + version := res.Plan.Appsearch.Version + res.Plan.Appsearch = c + res.Plan.Appsearch.Version = version + } + } + if rawTopology, ok := es["topology"]; ok { topology, err := expandTopology(rawTopology) if err != nil { @@ -108,6 +118,10 @@ func expandTopology(raw interface{}) ([]*models.AppSearchTopologyElement, error) elem.ZoneCount = int32(zones.(int)) } + if c, ok := topology["config"]; ok { + elem.Appsearch = expandConfig(c) + } + res = append(res, &elem) } @@ -126,3 +140,39 @@ func parseNodeType(topology map[string]interface{}) models.AppSearchNodeTypes { return result } + +func expandConfig(raw interface{}) *models.AppSearchConfiguration { + var res = &models.AppSearchConfiguration{} + for _, rawCfg := range raw.([]interface{}) { + var cfg = rawCfg.(map[string]interface{}) + if key, ok := cfg["secret_session_key"]; ok { + if res.SystemSettings == nil { + res.SystemSettings = &models.AppSearchSystemSettings{} + } + res.SystemSettings.SecretSessionKey = key.(string) + } + + if settings, ok := cfg["user_settings_json"]; ok && settings != nil { + if s, ok := settings.(string); ok && s != "" { + res.UserSettingsJSON = settings + } + } + if settings, ok := cfg["user_settings_override_json"]; ok && settings != nil { + if s, ok := settings.(string); ok && s != "" { + res.UserSettingsOverrideJSON = settings + } + } + if settings, ok := cfg["user_settings_yaml"]; ok { + res.UserSettingsYaml = settings.(string) + } + if settings, ok := cfg["user_settings_override_yaml"]; ok { + res.UserSettingsOverrideYaml = settings.(string) + } + } + + if !reflect.DeepEqual(res, &models.AppSearchConfiguration{}) { + return res + } + + return nil +} diff --git a/ec/ecresource/deploymentresource/appsearchstate/appsearch_expanders_test.go b/ec/ecresource/deploymentresource/appsearchstate/appsearch_expanders_test.go index a60d32f71..ebc26234e 100644 --- a/ec/ecresource/deploymentresource/appsearchstate/appsearch_expanders_test.go +++ b/ec/ecresource/deploymentresource/appsearchstate/appsearch_expanders_test.go @@ -49,15 +49,28 @@ func TestExpandResources(t *testing.T) { "version": "7.7.0", "region": "some-region", "elasticsearch_cluster_ref_id": "somerefid", - "topology": []interface{}{ - map[string]interface{}{ - "instance_configuration_id": "aws.appsearch.m5", - "memory_per_node": "2g", - "zone_count": 1, - "node_type_appserver": true, - "node_type_worker": false, - }, - }, + "topology": []interface{}{map[string]interface{}{ + "instance_configuration_id": "aws.appsearch.m5", + "memory_per_node": "2g", + "zone_count": 1, + "node_type_appserver": true, + "node_type_worker": false, + }}, + }, + map[string]interface{}{ + "display_name": "somename", + "ref_id": "secondary-appsearch", + "elasticsearch_cluster_ref_id": "somerefid", + "resource_id": mock.ValidClusterID, + "version": "7.6.0", + "region": "some-region", + "topology": []interface{}{map[string]interface{}{ + "instance_configuration_id": "aws.appsearch.m5", + "memory_per_node": "4g", + "zone_count": 1, + "node_type_appserver": false, + "node_type_worker": true, + }}, }, map[string]interface{}{ "display_name": "somename", @@ -66,8 +79,17 @@ func TestExpandResources(t *testing.T) { "resource_id": mock.ValidClusterID, "version": "7.6.0", "region": "some-region", + "config": []interface{}{map[string]interface{}{ + "secret_session_key": "somekey", + }}, "topology": []interface{}{ map[string]interface{}{ + "config": []interface{}{map[string]interface{}{ + "user_settings_yaml": "some.setting: value", + "user_settings_override_yaml": "some.setting: override", + "user_settings_json": `{"some.setting": "value"}`, + "user_settings_override_json": `{"some.setting": "override"}`, + }}, "instance_configuration_id": "aws.appsearch.m5", "memory_per_node": "4g", "zone_count": 1, @@ -87,20 +109,18 @@ func TestExpandResources(t *testing.T) { Appsearch: &models.AppSearchConfiguration{ Version: "7.7.0", }, - ClusterTopology: []*models.AppSearchTopologyElement{ - { - ZoneCount: 1, - InstanceConfigurationID: "aws.appsearch.m5", - Size: &models.TopologySize{ - Resource: ec.String("memory"), - Value: ec.Int32(2048), - }, - NodeType: &models.AppSearchNodeTypes{ - Appserver: ec.Bool(true), - Worker: ec.Bool(false), - }, + ClusterTopology: []*models.AppSearchTopologyElement{{ + ZoneCount: 1, + InstanceConfigurationID: "aws.appsearch.m5", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(2048), }, - }, + NodeType: &models.AppSearchNodeTypes{ + Appserver: ec.Bool(true), + Worker: ec.Bool(false), + }, + }}, }, }, { @@ -113,20 +133,51 @@ func TestExpandResources(t *testing.T) { Appsearch: &models.AppSearchConfiguration{ Version: "7.6.0", }, - ClusterTopology: []*models.AppSearchTopologyElement{ - { - ZoneCount: 1, - InstanceConfigurationID: "aws.appsearch.m5", - Size: &models.TopologySize{ - Resource: ec.String("memory"), - Value: ec.Int32(4096), - }, - NodeType: &models.AppSearchNodeTypes{ - Appserver: ec.Bool(false), - Worker: ec.Bool(true), - }, + ClusterTopology: []*models.AppSearchTopologyElement{{ + ZoneCount: 1, + InstanceConfigurationID: "aws.appsearch.m5", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(4096), + }, + NodeType: &models.AppSearchNodeTypes{ + Appserver: ec.Bool(false), + Worker: ec.Bool(true), + }, + }}, + }, + }, + { + ElasticsearchClusterRefID: ec.String("somerefid"), + DisplayName: "somename", + Region: ec.String("some-region"), + RefID: ec.String("secondary-appsearch"), + Settings: &models.AppSearchSettings{}, + Plan: &models.AppSearchPlan{ + Appsearch: &models.AppSearchConfiguration{ + Version: "7.6.0", + SystemSettings: &models.AppSearchSystemSettings{ + SecretSessionKey: "somekey", }, }, + ClusterTopology: []*models.AppSearchTopologyElement{{ + ZoneCount: 1, + InstanceConfigurationID: "aws.appsearch.m5", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(4096), + }, + NodeType: &models.AppSearchNodeTypes{ + Appserver: ec.Bool(false), + Worker: ec.Bool(true), + }, + Appsearch: &models.AppSearchConfiguration{ + UserSettingsYaml: "some.setting: value", + UserSettingsOverrideYaml: "some.setting: override", + UserSettingsJSON: `{"some.setting": "value"}`, + UserSettingsOverrideJSON: `{"some.setting": "override"}`, + }, + }}, }, }, }, diff --git a/ec/ecresource/deploymentresource/appsearchstate/appsearch_flatteners.go b/ec/ecresource/deploymentresource/appsearchstate/appsearch_flatteners.go index b2c8d622f..314e691bd 100644 --- a/ec/ecresource/deploymentresource/appsearchstate/appsearch_flatteners.go +++ b/ec/ecresource/deploymentresource/appsearchstate/appsearch_flatteners.go @@ -64,6 +64,10 @@ func FlattenResources(in []*models.AppSearchResourceInfo, name string) []interfa m[k] = v } + if c := flattenConfig(plan.Appsearch); len(c) > 0 { + m["config"] = c + } + result = append(result, m) } @@ -98,12 +102,66 @@ func flattenTopology(plan *models.AppSearchPlan) []interface{} { m["zone_count"] = topology.ZoneCount + if c := flattenConfig(topology.Appsearch); len(c) > 0 { + m["config"] = c + } + result = append(result, m) } return result } +func flattenConfig(cfg *models.AppSearchConfiguration) []interface{} { + var m = make(map[string]interface{}) + if cfg == nil { + return nil + } + + if cfg.UserSettingsYaml != "" { + m["user_settings_yaml"] = cfg.UserSettingsYaml + } + + if cfg.UserSettingsOverrideYaml != "" { + m["user_settings_override_yaml"] = cfg.UserSettingsOverrideYaml + } + + if cfg.UserSettingsJSON != nil { + m["user_settings_json"] = cfg.UserSettingsJSON + } + + if cfg.UserSettingsOverrideJSON != nil { + m["user_settings_override_json"] = cfg.UserSettingsOverrideJSON + } + + for k, v := range flattenSystemConfig(cfg.SystemSettings) { + m[k] = v + } + + if len(m) == 0 { + return nil + } + + return []interface{}{m} +} + +func flattenSystemConfig(cfg *models.AppSearchSystemSettings) map[string]interface{} { + var m = make(map[string]interface{}) + if cfg == nil { + return nil + } + + if cfg.SecretSessionKey != "" { + m["secret_session_key"] = cfg.SecretSessionKey + } + + if len(m) == 0 { + return nil + } + + return m +} + func isCurrentPlanEmpty(res *models.AppSearchResourceInfo) bool { var emptyPlanInfo = res.Info == nil || res.Info.PlanInfo == nil || res.Info.PlanInfo.Current == nil return emptyPlanInfo || res.Info.PlanInfo.Current.Plan == nil diff --git a/ec/ecresource/deploymentresource/appsearchstate/appsearch_flatteners_test.go b/ec/ecresource/deploymentresource/appsearchstate/appsearch_flatteners_test.go index 56fac0b30..57d74f5df 100644 --- a/ec/ecresource/deploymentresource/appsearchstate/appsearch_flatteners_test.go +++ b/ec/ecresource/deploymentresource/appsearchstate/appsearch_flatteners_test.go @@ -43,27 +43,25 @@ func TestFlattenResource(t *testing.T) { }, { name: "empty current plan returns empty list", - args: args{in: []*models.AppSearchResourceInfo{ - { - Info: &models.AppSearchInfo{ - PlanInfo: &models.AppSearchPlansInfo{ - Pending: &models.AppSearchPlanInfo{}, - }, + args: args{in: []*models.AppSearchResourceInfo{{ + Info: &models.AppSearchInfo{ + PlanInfo: &models.AppSearchPlansInfo{ + Pending: &models.AppSearchPlanInfo{}, }, }, - }}, + }}}, want: []interface{}{}, }, { - name: "parses the apm resource", + name: "parses the appsearch resource", args: args{in: []*models.AppSearchResourceInfo{ { Region: ec.String("some-region"), - RefID: ec.String("main-apm"), + RefID: ec.String("main-appsearch"), ElasticsearchClusterRefID: ec.String("main-elasticsearch"), Info: &models.AppSearchInfo{ ID: &mock.ValidClusterID, - Name: ec.String("some-apm-name"), + Name: ec.String("some-appsearch-name"), Region: "some-region", Metadata: &models.ClusterMetadataInfo{ Endpoint: "appsearchresource.cloud.elastic.co", @@ -76,22 +74,29 @@ func TestFlattenResource(t *testing.T) { Current: &models.AppSearchPlanInfo{ Plan: &models.AppSearchPlan{ Appsearch: &models.AppSearchConfiguration{ - Version: "7.7.0", + Version: "7.6.2", + UserSettingsYaml: "some.setting: some value", + UserSettingsOverrideYaml: "some.setting: some override", + UserSettingsJSON: `{"some.setting": "some other value"}`, + UserSettingsOverrideJSON: `{"some.setting": "some other override"}`, }, - ClusterTopology: []*models.AppSearchTopologyElement{ - { - ZoneCount: 1, - InstanceConfigurationID: "aws.apm.r4", - Size: &models.TopologySize{ - Resource: ec.String("memory"), - Value: ec.Int32(1024), - }, - NodeType: &models.AppSearchNodeTypes{ - Appserver: ec.Bool(true), - Worker: ec.Bool(false), + ClusterTopology: []*models.AppSearchTopologyElement{{ + Appsearch: &models.AppSearchConfiguration{ + SystemSettings: &models.AppSearchSystemSettings{ + SecretSessionKey: "somekey secret key", }, }, - }, + ZoneCount: 1, + InstanceConfigurationID: "aws.appsearch.r4", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(1024), + }, + NodeType: &models.AppSearchNodeTypes{ + Appserver: ec.Bool(true), + Worker: ec.Bool(false), + }, + }}, }, }, }, @@ -101,22 +106,29 @@ func TestFlattenResource(t *testing.T) { want: []interface{}{ map[string]interface{}{ "elasticsearch_cluster_ref_id": "main-elasticsearch", - "display_name": "some-apm-name", - "ref_id": "main-apm", + "display_name": "some-appsearch-name", + "ref_id": "main-appsearch", "resource_id": mock.ValidClusterID, - "version": "7.7.0", + "version": "7.6.2", "region": "some-region", "http_endpoint": "http://appsearchresource.cloud.elastic.co:9200", "https_endpoint": "https://appsearchresource.cloud.elastic.co:9243", - "topology": []interface{}{ - map[string]interface{}{ - "instance_configuration_id": "aws.apm.r4", - "memory_per_node": "1g", - "zone_count": int32(1), - "node_type_appserver": true, - "node_type_worker": false, - }, - }, + "config": []interface{}{map[string]interface{}{ + "user_settings_json": "{\"some.setting\": \"some other value\"}", + "user_settings_override_json": "{\"some.setting\": \"some other override\"}", + "user_settings_override_yaml": "some.setting: some override", + "user_settings_yaml": "some.setting: some value", + }}, + "topology": []interface{}{map[string]interface{}{ + "instance_configuration_id": "aws.appsearch.r4", + "memory_per_node": "1g", + "zone_count": int32(1), + "node_type_appserver": true, + "node_type_worker": false, + "config": []interface{}{map[string]interface{}{ + "secret_session_key": "somekey secret key", + }}, + }}, }, }, }, diff --git a/ec/ecresource/deploymentresource/schema_appsearch.go b/ec/ecresource/deploymentresource/schema_appsearch.go index 82d208bab..196fa1a26 100644 --- a/ec/ecresource/deploymentresource/schema_appsearch.go +++ b/ec/ecresource/deploymentresource/schema_appsearch.go @@ -17,7 +17,9 @@ package deploymentresource -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) // NewSchema returns the schema for an "ec_deployment" resource. func newAppSearchResource() *schema.Resource { @@ -59,6 +61,8 @@ func newAppSearchResource() *schema.Resource { }, "topology": appsearchTopologySchema(), + "config": appSearchConfig(), + // TODO: Implement settings field. // "settings": interface{} }, @@ -71,6 +75,8 @@ func appsearchTopologySchema() *schema.Schema { Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "config": appSearchConfig(), + "instance_configuration_id": { Type: schema.TypeString, Required: true, @@ -102,3 +108,44 @@ func appsearchTopologySchema() *schema.Schema { }, } } + +func appSearchConfig() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + DiffSuppressFunc: suppressMissingOptionalConfigurationBlock, + Description: `Optionally define the AppSearch configuration options for the AppSearch Server`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "secret_session_key": { + Type: schema.TypeString, + Description: `Optionally override the secret session key within AppSearch - defaults to the previously existing secretSession`, + Computed: true, + }, + + // User settings + "user_settings_json": { + Type: schema.TypeString, + Description: `An arbitrary JSON object allowing (non-admin) cluster owners to set their parameters (only one of this and 'user_settings_yaml' is allowed), provided they are on the whitelist ('user_settings_whitelist') and not on the blacklist ('user_settings_blacklist'). (This field together with 'user_settings_override*' and 'system_settings' defines the total set of resource settings)`, + Optional: true, + }, + "user_settings_override_json": { + Type: schema.TypeString, + Description: `An arbitrary JSON object allowing ECE admins owners to set clusters' parameters (only one of this and 'user_settings_override_yaml' is allowed), ie in addition to the documented 'system_settings'. (This field together with 'system_settings' and 'user_settings*' defines the total set of resource settings)`, + Optional: true, + }, + "user_settings_yaml": { + Type: schema.TypeString, + Description: `An arbitrary YAML object allowing ECE admins owners to set clusters' parameters (only one of this and 'user_settings_override_json' is allowed), ie in addition to the documented 'system_settings'. (This field together with 'system_settings' and 'user_settings*' defines the total set of resource settings)`, + Optional: true, + }, + "user_settings_override_yaml": { + Type: schema.TypeString, + Description: `An arbitrary YAML object allowing (non-admin) cluster owners to set their parameters (only one of this and 'user_settings_json' is allowed), provided they are on the whitelist ('user_settings_whitelist') and not on the blacklist ('user_settings_blacklist'). (These field together with 'user_settings_override*' and 'system_settings' defines the total set of resource settings)`, + Optional: true, + }, + }, + }, + } +} From 81f9fc033e74df4b40338de321c9da1e03893b2c Mon Sep 17 00:00:00 2001 From: Marc Lopez Date: Thu, 20 Aug 2020 15:06:28 +0300 Subject: [PATCH 2/7] Add Enterprise Search config settings Signed-off-by: Marc Lopez --- .../enterprise_search_expanders.go | 58 ++++++- .../enterprise_search_expanders_test.go | 142 ++++++++++++------ .../enterprise_search_flatteners.go | 58 +++++++ .../enterprise_search_flatteners_test.go | 58 ++++--- .../schema_enteprise_search.go | 45 ++++++ 5 files changed, 290 insertions(+), 71 deletions(-) diff --git a/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_expanders.go b/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_expanders.go index c18185d2f..80baf334b 100644 --- a/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_expanders.go +++ b/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_expanders.go @@ -18,19 +18,21 @@ package enterprisesearchstate import ( + "reflect" + "github.com/elastic/cloud-sdk-go/pkg/models" "github.com/elastic/cloud-sdk-go/pkg/util/ec" "github.com/terraform-providers/terraform-provider-ec/ec/ecresource/deploymentresource/deploymentstate" ) // ExpandResources expands appsearch resources into their models. -func ExpandResources(apss []interface{}) ([]*models.EnterpriseSearchPayload, error) { - if len(apss) == 0 { +func ExpandResources(ess []interface{}) ([]*models.EnterpriseSearchPayload, error) { + if len(ess) == 0 { return nil, nil } - result := make([]*models.EnterpriseSearchPayload, 0, len(apss)) - for _, raw := range apss { + result := make([]*models.EnterpriseSearchPayload, 0, len(ess)) + for _, raw := range ess { resResource, err := expandResource(raw) if err != nil { return nil, err @@ -72,6 +74,14 @@ func expandResource(raw interface{}) (*models.EnterpriseSearchPayload, error) { } } + if cfg, ok := es["config"]; ok { + if c := expandConfig(cfg); c != nil { + version := res.Plan.EnterpriseSearch.Version + res.Plan.EnterpriseSearch = c + res.Plan.EnterpriseSearch.Version = version + } + } + if rawTopology, ok := es["topology"]; ok { topology, err := expandTopology(rawTopology) if err != nil { @@ -108,6 +118,10 @@ func expandTopology(raw interface{}) ([]*models.EnterpriseSearchTopologyElement, elem.ZoneCount = int32(zones.(int)) } + if c, ok := topology["config"]; ok { + elem.EnterpriseSearch = expandConfig(c) + } + res = append(res, &elem) } @@ -130,3 +144,39 @@ func parseNodeType(topology map[string]interface{}) models.EnterpriseSearchNodeT return result } + +func expandConfig(raw interface{}) *models.EnterpriseSearchConfiguration { + var res = &models.EnterpriseSearchConfiguration{} + for _, rawCfg := range raw.([]interface{}) { + var cfg = rawCfg.(map[string]interface{}) + if key, ok := cfg["secret_session_key"]; ok { + if res.SystemSettings == nil { + res.SystemSettings = &models.EnterpriseSearchSystemSettings{} + } + res.SystemSettings.SecretSessionKey = key.(string) + } + + if settings, ok := cfg["user_settings_json"]; ok && settings != nil { + if s, ok := settings.(string); ok && s != "" { + res.UserSettingsJSON = settings + } + } + if settings, ok := cfg["user_settings_override_json"]; ok && settings != nil { + if s, ok := settings.(string); ok && s != "" { + res.UserSettingsOverrideJSON = settings + } + } + if settings, ok := cfg["user_settings_yaml"]; ok { + res.UserSettingsYaml = settings.(string) + } + if settings, ok := cfg["user_settings_override_yaml"]; ok { + res.UserSettingsOverrideYaml = settings.(string) + } + } + + if !reflect.DeepEqual(res, &models.EnterpriseSearchConfiguration{}) { + return res + } + + return nil +} diff --git a/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_expanders_test.go b/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_expanders_test.go index 125b51333..b693f3a17 100644 --- a/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_expanders_test.go +++ b/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_expanders_test.go @@ -49,16 +49,14 @@ func TestExpandResources(t *testing.T) { "version": "7.7.0", "region": "some-region", "elasticsearch_cluster_ref_id": "somerefid", - "topology": []interface{}{ - map[string]interface{}{ - "instance_configuration_id": "aws.enterprisesearch.m5", - "memory_per_node": "2g", - "zone_count": 1, - "node_type_appserver": true, - "node_type_connector": true, - "node_type_worker": false, - }, - }, + "topology": []interface{}{map[string]interface{}{ + "instance_configuration_id": "aws.enterprisesearch.m5", + "memory_per_node": "2g", + "zone_count": 1, + "node_type_appserver": true, + "node_type_connector": true, + "node_type_worker": false, + }}, }, map[string]interface{}{ "display_name": "somename", @@ -67,15 +65,39 @@ func TestExpandResources(t *testing.T) { "resource_id": mock.ValidClusterID, "version": "7.6.0", "region": "some-region", - "topology": []interface{}{ - map[string]interface{}{ - "instance_configuration_id": "aws.enterprisesearch.m5", - "memory_per_node": "4g", - "zone_count": 1, - "node_type_appserver": false, - "node_type_connector": true, - "node_type_worker": true, + "topology": []interface{}{map[string]interface{}{ + "instance_configuration_id": "aws.enterprisesearch.m5", + "memory_per_node": "4g", + "zone_count": 1, + "node_type_appserver": false, + "node_type_connector": true, + "node_type_worker": true, + }}, + }, + map[string]interface{}{ + "display_name": "somename", + "ref_id": "secondary-enterprise_search", + "elasticsearch_cluster_ref_id": "somerefid", + "resource_id": mock.ValidClusterID, + "version": "7.7.0", + "region": "some-region", + "config": []interface{}{map[string]interface{}{ + "secret_session_key": "somekey", + }}, + "topology": []interface{}{map[string]interface{}{ + "config": []interface{}{map[string]interface{}{ + "user_settings_yaml": "some.setting: value", + "user_settings_override_yaml": "some.setting: override", + "user_settings_json": `{"some.setting": "value"}`, + "user_settings_override_json": `{"some.setting": "override"}`, }}, + "instance_configuration_id": "aws.enterprisesearch.m5", + "memory_per_node": "4g", + "zone_count": 1, + "node_type_appserver": false, + "node_type_connector": true, + "node_type_worker": true, + }}, }, }, }, @@ -89,21 +111,19 @@ func TestExpandResources(t *testing.T) { EnterpriseSearch: &models.EnterpriseSearchConfiguration{ Version: "7.7.0", }, - ClusterTopology: []*models.EnterpriseSearchTopologyElement{ - { - ZoneCount: 1, - InstanceConfigurationID: "aws.enterprisesearch.m5", - Size: &models.TopologySize{ - Resource: ec.String("memory"), - Value: ec.Int32(2048), - }, - NodeType: &models.EnterpriseSearchNodeTypes{ - Appserver: ec.Bool(true), - Connector: ec.Bool(true), - Worker: ec.Bool(false), - }, + ClusterTopology: []*models.EnterpriseSearchTopologyElement{{ + ZoneCount: 1, + InstanceConfigurationID: "aws.enterprisesearch.m5", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(2048), }, - }, + NodeType: &models.EnterpriseSearchNodeTypes{ + Appserver: ec.Bool(true), + Connector: ec.Bool(true), + Worker: ec.Bool(false), + }, + }}, }, }, { @@ -116,21 +136,53 @@ func TestExpandResources(t *testing.T) { EnterpriseSearch: &models.EnterpriseSearchConfiguration{ Version: "7.6.0", }, - ClusterTopology: []*models.EnterpriseSearchTopologyElement{ - { - ZoneCount: 1, - InstanceConfigurationID: "aws.enterprisesearch.m5", - Size: &models.TopologySize{ - Resource: ec.String("memory"), - Value: ec.Int32(4096), - }, - NodeType: &models.EnterpriseSearchNodeTypes{ - Appserver: ec.Bool(false), - Connector: ec.Bool(true), - Worker: ec.Bool(true), - }, + ClusterTopology: []*models.EnterpriseSearchTopologyElement{{ + ZoneCount: 1, + InstanceConfigurationID: "aws.enterprisesearch.m5", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(4096), + }, + NodeType: &models.EnterpriseSearchNodeTypes{ + Appserver: ec.Bool(false), + Connector: ec.Bool(true), + Worker: ec.Bool(true), + }, + }}, + }, + }, + { + ElasticsearchClusterRefID: ec.String("somerefid"), + DisplayName: "somename", + Region: ec.String("some-region"), + RefID: ec.String("secondary-enterprise_search"), + Settings: &models.EnterpriseSearchSettings{}, + Plan: &models.EnterpriseSearchPlan{ + EnterpriseSearch: &models.EnterpriseSearchConfiguration{ + Version: "7.7.0", + SystemSettings: &models.EnterpriseSearchSystemSettings{ + SecretSessionKey: "somekey", }, }, + ClusterTopology: []*models.EnterpriseSearchTopologyElement{{ + EnterpriseSearch: &models.EnterpriseSearchConfiguration{ + UserSettingsYaml: "some.setting: value", + UserSettingsOverrideYaml: "some.setting: override", + UserSettingsJSON: `{"some.setting": "value"}`, + UserSettingsOverrideJSON: `{"some.setting": "override"}`, + }, + ZoneCount: 1, + InstanceConfigurationID: "aws.enterprisesearch.m5", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(4096), + }, + NodeType: &models.EnterpriseSearchNodeTypes{ + Appserver: ec.Bool(false), + Connector: ec.Bool(true), + Worker: ec.Bool(true), + }, + }}, }, }, }, diff --git a/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_flatteners.go b/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_flatteners.go index 0da694bbe..79ca97c32 100644 --- a/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_flatteners.go +++ b/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_flatteners.go @@ -66,6 +66,10 @@ func FlattenResources(in []*models.EnterpriseSearchResourceInfo, name string) [] } } + if c := flattenConfig(plan.EnterpriseSearch); len(c) > 0 { + m["config"] = c + } + result = append(result, m) } @@ -104,12 +108,66 @@ func flattenTopology(plan *models.EnterpriseSearchPlan) []interface{} { m["zone_count"] = topology.ZoneCount + if c := flattenConfig(topology.EnterpriseSearch); len(c) > 0 { + m["config"] = c + } + result = append(result, m) } return result } +func flattenConfig(cfg *models.EnterpriseSearchConfiguration) []interface{} { + var m = make(map[string]interface{}) + if cfg == nil { + return nil + } + + if cfg.UserSettingsYaml != "" { + m["user_settings_yaml"] = cfg.UserSettingsYaml + } + + if cfg.UserSettingsOverrideYaml != "" { + m["user_settings_override_yaml"] = cfg.UserSettingsOverrideYaml + } + + if cfg.UserSettingsJSON != nil { + m["user_settings_json"] = cfg.UserSettingsJSON + } + + if cfg.UserSettingsOverrideJSON != nil { + m["user_settings_override_json"] = cfg.UserSettingsOverrideJSON + } + + for k, v := range flattenSystemConfig(cfg.SystemSettings) { + m[k] = v + } + + if len(m) == 0 { + return nil + } + + return []interface{}{m} +} + +func flattenSystemConfig(cfg *models.EnterpriseSearchSystemSettings) map[string]interface{} { + var m = make(map[string]interface{}) + if cfg == nil { + return nil + } + + if cfg.SecretSessionKey != "" { + m["secret_session_key"] = cfg.SecretSessionKey + } + + if len(m) == 0 { + return nil + } + + return m +} + func isCurrentPlanEmpty(res *models.EnterpriseSearchResourceInfo) bool { var emptyPlanInfo = res.Info == nil || res.Info.PlanInfo == nil || res.Info.PlanInfo.Current == nil return emptyPlanInfo || res.Info.PlanInfo.Current.Plan == nil diff --git a/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_flatteners_test.go b/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_flatteners_test.go index 1619df999..aeb61850b 100644 --- a/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_flatteners_test.go +++ b/ec/ecresource/deploymentresource/enterprisesearchstate/enterprise_search_flatteners_test.go @@ -76,22 +76,29 @@ func TestFlattenResource(t *testing.T) { Current: &models.EnterpriseSearchPlanInfo{ Plan: &models.EnterpriseSearchPlan{ EnterpriseSearch: &models.EnterpriseSearchConfiguration{ - Version: "7.7.0", + Version: "7.7.0", + UserSettingsYaml: "some.setting: some value", + UserSettingsOverrideYaml: "some.setting: some override", + UserSettingsJSON: `{"some.setting": "some other value"}`, + UserSettingsOverrideJSON: `{"some.setting": "some other override"}`, }, - ClusterTopology: []*models.EnterpriseSearchTopologyElement{ - { - ZoneCount: 1, - InstanceConfigurationID: "aws.enterprisesearch.r4", - Size: &models.TopologySize{ - Resource: ec.String("memory"), - Value: ec.Int32(1024), - }, - NodeType: &models.EnterpriseSearchNodeTypes{ - Appserver: ec.Bool(true), - Worker: ec.Bool(false), + ClusterTopology: []*models.EnterpriseSearchTopologyElement{{ + EnterpriseSearch: &models.EnterpriseSearchConfiguration{ + SystemSettings: &models.EnterpriseSearchSystemSettings{ + SecretSessionKey: "somekey secret key", }, }, - }, + ZoneCount: 1, + InstanceConfigurationID: "aws.enterprisesearch.r4", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(1024), + }, + NodeType: &models.EnterpriseSearchNodeTypes{ + Appserver: ec.Bool(true), + Worker: ec.Bool(false), + }, + }}, }, }, }, @@ -108,15 +115,22 @@ func TestFlattenResource(t *testing.T) { "region": "some-region", "http_endpoint": "http://enterprisesearchresource.cloud.elastic.co:9200", "https_endpoint": "https://enterprisesearchresource.cloud.elastic.co:9243", - "topology": []interface{}{ - map[string]interface{}{ - "instance_configuration_id": "aws.enterprisesearch.r4", - "memory_per_node": "1g", - "zone_count": int32(1), - "node_type_appserver": true, - "node_type_worker": false, - }, - }, + "config": []interface{}{map[string]interface{}{ + "user_settings_json": "{\"some.setting\": \"some other value\"}", + "user_settings_override_json": "{\"some.setting\": \"some other override\"}", + "user_settings_override_yaml": "some.setting: some override", + "user_settings_yaml": "some.setting: some value", + }}, + "topology": []interface{}{map[string]interface{}{ + "instance_configuration_id": "aws.enterprisesearch.r4", + "memory_per_node": "1g", + "zone_count": int32(1), + "node_type_appserver": true, + "node_type_worker": false, + "config": []interface{}{map[string]interface{}{ + "secret_session_key": "somekey secret key", + }}, + }}, }, }, }, diff --git a/ec/ecresource/deploymentresource/schema_enteprise_search.go b/ec/ecresource/deploymentresource/schema_enteprise_search.go index 6d4da538d..41ef44ece 100644 --- a/ec/ecresource/deploymentresource/schema_enteprise_search.go +++ b/ec/ecresource/deploymentresource/schema_enteprise_search.go @@ -59,6 +59,8 @@ func newEnterpriseSearchResource() *schema.Resource { }, "topology": enterpriseSearchTopologySchema(), + "config": enterpriseSearchConfig(), + // TODO: Implement settings field. // "settings": interface{} }, @@ -71,6 +73,8 @@ func enterpriseSearchTopologySchema() *schema.Schema { Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "config": enterpriseSearchConfig(), + "instance_configuration_id": { Type: schema.TypeString, Required: true, @@ -107,3 +111,44 @@ func enterpriseSearchTopologySchema() *schema.Schema { }, } } + +func enterpriseSearchConfig() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + DiffSuppressFunc: suppressMissingOptionalConfigurationBlock, + Description: `Optionally define the Enterprise Search configuration options for the Enterprise Search Server`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "secret_session_key": { + Type: schema.TypeString, + Description: `Optionally override the secret session key within Enterprise Search - defaults to the previously existing secretSession`, + Computed: true, + }, + + // User settings + "user_settings_json": { + Type: schema.TypeString, + Description: `An arbitrary JSON object allowing (non-admin) cluster owners to set their parameters (only one of this and 'user_settings_yaml' is allowed), provided they are on the whitelist ('user_settings_whitelist') and not on the blacklist ('user_settings_blacklist'). (This field together with 'user_settings_override*' and 'system_settings' defines the total set of resource settings)`, + Optional: true, + }, + "user_settings_override_json": { + Type: schema.TypeString, + Description: `An arbitrary JSON object allowing ECE admins owners to set clusters' parameters (only one of this and 'user_settings_override_yaml' is allowed), ie in addition to the documented 'system_settings'. (This field together with 'system_settings' and 'user_settings*' defines the total set of resource settings)`, + Optional: true, + }, + "user_settings_yaml": { + Type: schema.TypeString, + Description: `An arbitrary YAML object allowing ECE admins owners to set clusters' parameters (only one of this and 'user_settings_override_json' is allowed), ie in addition to the documented 'system_settings'. (This field together with 'system_settings' and 'user_settings*' defines the total set of resource settings)`, + Optional: true, + }, + "user_settings_override_yaml": { + Type: schema.TypeString, + Description: `An arbitrary YAML object allowing (non-admin) cluster owners to set their parameters (only one of this and 'user_settings_json' is allowed), provided they are on the whitelist ('user_settings_whitelist') and not on the blacklist ('user_settings_blacklist'). (These field together with 'user_settings_override*' and 'system_settings' defines the total set of resource settings)`, + Optional: true, + }, + }, + }, + } +} From 76c7e9fa37c9649454389548b81bba2ce7f15346 Mon Sep 17 00:00:00 2001 From: Marc Lopez Date: Thu, 20 Aug 2020 15:06:53 +0300 Subject: [PATCH 3/7] Add Kibana config settings Signed-off-by: Marc Lopez --- .../kibanastate/kibana_expanders.go | 43 +++++++++ .../kibanastate/kibana_expanders_test.go | 90 ++++++++++++++----- .../kibanastate/kibana_flatteners.go | 37 ++++++++ .../kibanastate/kibana_flatteners_test.go | 71 +++++++++++++++ .../deploymentresource/schema_kibana.go | 39 ++++++++ 5 files changed, 260 insertions(+), 20 deletions(-) diff --git a/ec/ecresource/deploymentresource/kibanastate/kibana_expanders.go b/ec/ecresource/deploymentresource/kibanastate/kibana_expanders.go index efa206804..28e93353e 100644 --- a/ec/ecresource/deploymentresource/kibanastate/kibana_expanders.go +++ b/ec/ecresource/deploymentresource/kibanastate/kibana_expanders.go @@ -18,6 +18,8 @@ package kibanastate import ( + "reflect" + "github.com/elastic/cloud-sdk-go/pkg/models" "github.com/elastic/cloud-sdk-go/pkg/util/ec" "github.com/terraform-providers/terraform-provider-ec/ec/ecresource/deploymentresource/deploymentstate" @@ -72,6 +74,14 @@ func expandResource(raw interface{}) (*models.KibanaPayload, error) { } } + if cfg, ok := es["config"]; ok { + if c := expandConfig(cfg); c != nil { + version := res.Plan.Kibana.Version + res.Plan.Kibana = c + res.Plan.Kibana.Version = version + } + } + if rawTopology, ok := es["topology"]; ok { topology, err := expandTopology(rawTopology) if err != nil { @@ -110,8 +120,41 @@ func expandTopology(raw interface{}) ([]*models.KibanaClusterTopologyElement, er elem.NodeCountPerZone = int32(nodecount.(int)) } + if c, ok := topology["config"]; ok { + elem.Kibana = expandConfig(c) + } + res = append(res, &elem) } return res, nil } + +func expandConfig(raw interface{}) *models.KibanaConfiguration { + var res = &models.KibanaConfiguration{} + for _, rawCfg := range raw.([]interface{}) { + var cfg = rawCfg.(map[string]interface{}) + if settings, ok := cfg["user_settings_json"]; ok && settings != nil { + if s, ok := settings.(string); ok && s != "" { + res.UserSettingsJSON = settings + } + } + if settings, ok := cfg["user_settings_override_json"]; ok && settings != nil { + if s, ok := settings.(string); ok && s != "" { + res.UserSettingsOverrideJSON = settings + } + } + if settings, ok := cfg["user_settings_yaml"]; ok { + res.UserSettingsYaml = settings.(string) + } + if settings, ok := cfg["user_settings_override_yaml"]; ok { + res.UserSettingsOverrideYaml = settings.(string) + } + } + + if !reflect.DeepEqual(res, &models.KibanaConfiguration{}) { + return res + } + + return nil +} diff --git a/ec/ecresource/deploymentresource/kibanastate/kibana_expanders_test.go b/ec/ecresource/deploymentresource/kibanastate/kibana_expanders_test.go index 955c5b8fc..9484edc01 100644 --- a/ec/ecresource/deploymentresource/kibanastate/kibana_expanders_test.go +++ b/ec/ecresource/deploymentresource/kibanastate/kibana_expanders_test.go @@ -49,13 +49,11 @@ func TestExpandResources(t *testing.T) { "version": "7.7.0", "region": "some-region", "elasticsearch_cluster_ref_id": "somerefid", - "topology": []interface{}{ - map[string]interface{}{ - "instance_configuration_id": "aws.kibana.r4", - "memory_per_node": "2g", - "zone_count": 1, - }, - }, + "topology": []interface{}{map[string]interface{}{ + "instance_configuration_id": "aws.kibana.r4", + "memory_per_node": "2g", + "zone_count": 1, + }}, }, map[string]interface{}{ "display_name": "somename", @@ -64,12 +62,36 @@ func TestExpandResources(t *testing.T) { "resource_id": mock.ValidClusterID, "version": "7.6.0", "region": "some-region", - "topology": []interface{}{ - map[string]interface{}{ - "instance_configuration_id": "aws.kibana.r4", - "memory_per_node": "4g", - "zone_count": 1, + "topology": []interface{}{map[string]interface{}{ + "instance_configuration_id": "aws.kibana.r4", + "memory_per_node": "4g", + "zone_count": 1, + }}, + }, + map[string]interface{}{ + "display_name": "somename", + "ref_id": "secondary-kibana", + "elasticsearch_cluster_ref_id": "somerefid", + "resource_id": mock.ValidClusterID, + "version": "7.8.0", + "region": "some-region", + "config": []interface{}{map[string]interface{}{ + "user_settings_yaml": "some.setting: value", + "user_settings_override_yaml": "some.setting: override", + "user_settings_json": `{"some.setting": "value"}`, + "user_settings_override_json": `{"some.setting": "override"}`, + }}, + "topology": []interface{}{map[string]interface{}{ + "config": []interface{}{map[string]interface{}{ + "user_settings_yaml": "some.setting: value", + "user_settings_override_yaml": "some.setting: override", + "user_settings_json": `{"some.setting": "value"}`, + "user_settings_override_json": `{"some.setting": "override"}`, }}, + "instance_configuration_id": "aws.kibana.r4", + "memory_per_node": "4g", + "zone_count": 1, + }}, }, }, }, @@ -105,16 +127,44 @@ func TestExpandResources(t *testing.T) { Kibana: &models.KibanaConfiguration{ Version: "7.6.0", }, - ClusterTopology: []*models.KibanaClusterTopologyElement{ - { - ZoneCount: 1, - InstanceConfigurationID: "aws.kibana.r4", - Size: &models.TopologySize{ - Resource: ec.String("memory"), - Value: ec.Int32(4096), - }, + ClusterTopology: []*models.KibanaClusterTopologyElement{{ + ZoneCount: 1, + InstanceConfigurationID: "aws.kibana.r4", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(4096), }, + }}, + }, + }, + { + ElasticsearchClusterRefID: ec.String("somerefid"), + DisplayName: "somename", + Region: ec.String("some-region"), + RefID: ec.String("secondary-kibana"), + Settings: &models.KibanaClusterSettings{}, + Plan: &models.KibanaClusterPlan{ + Kibana: &models.KibanaConfiguration{ + Version: "7.8.0", + UserSettingsYaml: "some.setting: value", + UserSettingsOverrideYaml: "some.setting: override", + UserSettingsJSON: "{\"some.setting\": \"value\"}", + UserSettingsOverrideJSON: "{\"some.setting\": \"override\"}", }, + ClusterTopology: []*models.KibanaClusterTopologyElement{{ + Kibana: &models.KibanaConfiguration{ + UserSettingsYaml: "some.setting: value", + UserSettingsOverrideYaml: "some.setting: override", + UserSettingsJSON: "{\"some.setting\": \"value\"}", + UserSettingsOverrideJSON: "{\"some.setting\": \"override\"}", + }, + ZoneCount: 1, + InstanceConfigurationID: "aws.kibana.r4", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(4096), + }, + }}, }, }, }, diff --git a/ec/ecresource/deploymentresource/kibanastate/kibana_flatteners.go b/ec/ecresource/deploymentresource/kibanastate/kibana_flatteners.go index f6c7ad20a..fed2599cb 100644 --- a/ec/ecresource/deploymentresource/kibanastate/kibana_flatteners.go +++ b/ec/ecresource/deploymentresource/kibanastate/kibana_flatteners.go @@ -64,6 +64,10 @@ func FlattenResources(in []*models.KibanaResourceInfo, name string) []interface{ m[k] = v } + if c := flattenConfig(plan.Kibana); len(c) > 0 { + m["config"] = c + } + result = append(result, m) } @@ -97,12 +101,45 @@ func flattenKibanaTopology(plan *models.KibanaClusterPlan) []interface{} { m["zone_count"] = topology.ZoneCount + if c := flattenConfig(topology.Kibana); len(c) > 0 { + m["config"] = c + } + result = append(result, m) } return result } +func flattenConfig(cfg *models.KibanaConfiguration) []interface{} { + var m = make(map[string]interface{}) + if cfg == nil { + return nil + } + + if cfg.UserSettingsYaml != "" { + m["user_settings_yaml"] = cfg.UserSettingsYaml + } + + if cfg.UserSettingsOverrideYaml != "" { + m["user_settings_override_yaml"] = cfg.UserSettingsOverrideYaml + } + + if cfg.UserSettingsJSON != nil { + m["user_settings_json"] = cfg.UserSettingsJSON + } + + if cfg.UserSettingsOverrideJSON != nil { + m["user_settings_override_json"] = cfg.UserSettingsOverrideJSON + } + + if len(m) == 0 { + return nil + } + + return []interface{}{m} +} + func isCurrentPlanEmpty(res *models.KibanaResourceInfo) bool { var emptyPlanInfo = res.Info == nil || res.Info.PlanInfo == nil || res.Info.PlanInfo.Current == nil return emptyPlanInfo || res.Info.PlanInfo.Current.Plan == nil diff --git a/ec/ecresource/deploymentresource/kibanastate/kibana_flatteners_test.go b/ec/ecresource/deploymentresource/kibanastate/kibana_flatteners_test.go index 43480a521..b8d116dfc 100644 --- a/ec/ecresource/deploymentresource/kibanastate/kibana_flatteners_test.go +++ b/ec/ecresource/deploymentresource/kibanastate/kibana_flatteners_test.go @@ -93,6 +93,50 @@ func TestFlattenResources(t *testing.T) { }, }, }, + { + Region: ec.String("some-region"), + RefID: ec.String("main-kibana"), + ElasticsearchClusterRefID: ec.String("main-elasticsearch"), + Info: &models.KibanaClusterInfo{ + ClusterID: &mock.ValidClusterID, + ClusterName: ec.String("some-kibana-name"), + Region: "some-region", + Metadata: &models.ClusterMetadataInfo{ + Endpoint: "kibanaresource.cloud.elastic.co", + Ports: &models.ClusterMetadataPortInfo{ + HTTP: ec.Int32(9200), + HTTPS: ec.Int32(9243), + }, + }, + PlanInfo: &models.KibanaClusterPlansInfo{ + Current: &models.KibanaClusterPlanInfo{ + Plan: &models.KibanaClusterPlan{ + Kibana: &models.KibanaConfiguration{ + Version: "7.7.0", + UserSettingsYaml: "some.setting: value", + UserSettingsOverrideYaml: "some.setting: override", + UserSettingsJSON: "{\"some.setting\": \"value\"}", + UserSettingsOverrideJSON: "{\"some.setting\": \"override\"}", + }, + ClusterTopology: []*models.KibanaClusterTopologyElement{{ + Kibana: &models.KibanaConfiguration{ + UserSettingsYaml: "some.setting: value", + UserSettingsOverrideYaml: "some.setting: override", + UserSettingsJSON: "{\"some.setting\": \"value\"}", + UserSettingsOverrideJSON: "{\"some.setting\": \"override\"}", + }, + ZoneCount: 1, + InstanceConfigurationID: "aws.kibana.r4", + Size: &models.TopologySize{ + Resource: ec.String("memory"), + Value: ec.Int32(1024), + }, + }}, + }, + }, + }, + }, + }, }}, want: []interface{}{ map[string]interface{}{ @@ -112,6 +156,33 @@ func TestFlattenResources(t *testing.T) { }, }, }, + map[string]interface{}{ + "elasticsearch_cluster_ref_id": "main-elasticsearch", + "display_name": "some-kibana-name", + "ref_id": "main-kibana", + "resource_id": mock.ValidClusterID, + "version": "7.7.0", + "region": "some-region", + "http_endpoint": "http://kibanaresource.cloud.elastic.co:9200", + "https_endpoint": "https://kibanaresource.cloud.elastic.co:9243", + "config": []interface{}{map[string]interface{}{ + "user_settings_yaml": "some.setting: value", + "user_settings_override_yaml": "some.setting: override", + "user_settings_json": `{"some.setting": "value"}`, + "user_settings_override_json": `{"some.setting": "override"}`, + }}, + "topology": []interface{}{map[string]interface{}{ + "config": []interface{}{map[string]interface{}{ + "user_settings_yaml": "some.setting: value", + "user_settings_override_yaml": "some.setting: override", + "user_settings_json": `{"some.setting": "value"}`, + "user_settings_override_json": `{"some.setting": "override"}`, + }}, + "instance_configuration_id": "aws.kibana.r4", + "memory_per_node": "1g", + "zone_count": int32(1), + }}, + }, }, }, } diff --git a/ec/ecresource/deploymentresource/schema_kibana.go b/ec/ecresource/deploymentresource/schema_kibana.go index 0f8496685..fbf506017 100644 --- a/ec/ecresource/deploymentresource/schema_kibana.go +++ b/ec/ecresource/deploymentresource/schema_kibana.go @@ -59,6 +59,8 @@ func newKibanaResource() *schema.Resource { }, "topology": kibanaTopologySchema(), + "config": kibanaConfig(), + // TODO: Implement settings field. // "settings": interface{} }, @@ -71,6 +73,8 @@ func kibanaTopologySchema() *schema.Schema { Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "config": kibanaConfig(), + "instance_configuration_id": { Type: schema.TypeString, Required: true, @@ -93,3 +97,38 @@ func kibanaTopologySchema() *schema.Schema { }, } } + +func kibanaConfig() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + DiffSuppressFunc: suppressMissingOptionalConfigurationBlock, + Description: `Optionally define the Kibana configuration options for the Kibana Server`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + // User settings + "user_settings_json": { + Type: schema.TypeString, + Description: `An arbitrary JSON object allowing (non-admin) cluster owners to set their parameters (only one of this and 'user_settings_yaml' is allowed), provided they are on the whitelist ('user_settings_whitelist') and not on the blacklist ('user_settings_blacklist'). (This field together with 'user_settings_override*' and 'system_settings' defines the total set of resource settings)`, + Optional: true, + }, + "user_settings_override_json": { + Type: schema.TypeString, + Description: `An arbitrary JSON object allowing ECE admins owners to set clusters' parameters (only one of this and 'user_settings_override_yaml' is allowed), ie in addition to the documented 'system_settings'. (This field together with 'system_settings' and 'user_settings*' defines the total set of resource settings)`, + Optional: true, + }, + "user_settings_yaml": { + Type: schema.TypeString, + Description: `An arbitrary YAML object allowing ECE admins owners to set clusters' parameters (only one of this and 'user_settings_override_json' is allowed), ie in addition to the documented 'system_settings'. (This field together with 'system_settings' and 'user_settings*' defines the total set of resource settings)`, + Optional: true, + }, + "user_settings_override_yaml": { + Type: schema.TypeString, + Description: `An arbitrary YAML object allowing (non-admin) cluster owners to set their parameters (only one of this and 'user_settings_json' is allowed), provided they are on the whitelist ('user_settings_whitelist') and not on the blacklist ('user_settings_blacklist'). (These field together with 'user_settings_override*' and 'system_settings' defines the total set of resource settings)`, + Optional: true, + }, + }, + }, + } +} From 86c064483433d6d2c141c2b58b941e5dc9a83503 Mon Sep 17 00:00:00 2001 From: Marc Lopez Date: Thu, 20 Aug 2020 15:07:22 +0300 Subject: [PATCH 4/7] Update APM config settings Signed-off-by: Marc Lopez --- .../apmstate/apm_expanders.go | 25 ++------- .../apmstate/apm_expanders_test.go | 22 ++------ .../apmstate/apm_flatteners.go | 20 ------- .../apmstate/apm_flatteners_test.go | 56 ++++--------------- .../deploymentresource/schema_apm.go | 26 --------- 5 files changed, 22 insertions(+), 127 deletions(-) diff --git a/ec/ecresource/deploymentresource/apmstate/apm_expanders.go b/ec/ecresource/deploymentresource/apmstate/apm_expanders.go index ef4790e3d..a06d69a72 100644 --- a/ec/ecresource/deploymentresource/apmstate/apm_expanders.go +++ b/ec/ecresource/deploymentresource/apmstate/apm_expanders.go @@ -25,6 +25,10 @@ import ( "github.com/terraform-providers/terraform-provider-ec/ec/ecresource/deploymentresource/deploymentstate" ) +var emptyApmConfig = &models.ApmConfiguration{ + SystemSettings: &models.ApmSystemSettings{}, +} + // ExpandResources expands apm resources into their models. func ExpandResources(apms []interface{}) ([]*models.ApmPayload, error) { if len(apms) == 0 { @@ -132,30 +136,11 @@ func expandConfig(raw interface{}) *models.ApmConfiguration { } for _, rawCfg := range raw.([]interface{}) { var cfg = rawCfg.(map[string]interface{}) - if dockerImage, ok := cfg["docker_image"]; ok { - res.DockerImage = dockerImage.(string) - } if debugEnabled, ok := cfg["debug_enabled"]; ok { res.SystemSettings.DebugEnabled = ec.Bool(debugEnabled.(bool)) } - if pass, ok := cfg["elasticsearch_password"]; ok { - res.SystemSettings.ElasticsearchPassword = pass.(string) - } - - if u, ok := cfg["elasticsearch_url"]; ok { - res.SystemSettings.ElasticsearchURL = u.(string) - } - - if user, ok := cfg["elasticsearch_username"]; ok { - res.SystemSettings.ElasticsearchUsername = user.(string) - } - - if u, ok := cfg["kibana_url"]; ok { - res.SystemSettings.KibanaURL = u.(string) - } - if token, ok := cfg["secret_token"]; ok { res.SystemSettings.SecretToken = token.(string) } @@ -178,7 +163,7 @@ func expandConfig(raw interface{}) *models.ApmConfiguration { } } - if !reflect.DeepEqual(res, new(models.ApmConfiguration)) { + if !reflect.DeepEqual(res, emptyApmConfig) { return res } diff --git a/ec/ecresource/deploymentresource/apmstate/apm_expanders_test.go b/ec/ecresource/deploymentresource/apmstate/apm_expanders_test.go index f3b89e194..3b58d069f 100644 --- a/ec/ecresource/deploymentresource/apmstate/apm_expanders_test.go +++ b/ec/ecresource/deploymentresource/apmstate/apm_expanders_test.go @@ -80,22 +80,16 @@ func TestExpandResources(t *testing.T) { "memory_per_node": "4g", "zone_count": 1, "config": []interface{}{map[string]interface{}{ - "docker_image": "some-other-image", "user_settings_yaml": "some.setting: value", "user_settings_override_yaml": "some.setting: value2", "user_settings_json": "{\"some.setting\": \"value\"}", "user_settings_override_json": "{\"some.setting\": \"value2\"}", - "debug_enabled": true, - "elasticsearch_password": "somepass", - "elasticsearch_username": "someuser", - "elasticsearch_url": "someURL", - "kibana_url": "someKibanaURL", - "secret_token": "very_secret", + "debug_enabled": true, + "secret_token": "very_secret", }}, }}, "config": []interface{}{map[string]interface{}{ - "docker_image": "some-docker-image:version", "debug_enabled": true, }}, }, @@ -149,26 +143,20 @@ func TestExpandResources(t *testing.T) { Settings: &models.ApmSettings{}, Plan: &models.ApmPlan{ Apm: &models.ApmConfiguration{ - Version: "7.8.0", - DockerImage: "some-docker-image:version", + Version: "7.8.0", SystemSettings: &models.ApmSystemSettings{ DebugEnabled: ec.Bool(true), }, }, ClusterTopology: []*models.ApmTopologyElement{{ Apm: &models.ApmConfiguration{ - DockerImage: "some-other-image", UserSettingsYaml: `some.setting: value`, UserSettingsOverrideYaml: `some.setting: value2`, UserSettingsJSON: `{"some.setting": "value"}`, UserSettingsOverrideJSON: `{"some.setting": "value2"}`, SystemSettings: &models.ApmSystemSettings{ - DebugEnabled: ec.Bool(true), - ElasticsearchPassword: "somepass", - ElasticsearchURL: "someURL", - ElasticsearchUsername: "someuser", - KibanaURL: "someKibanaURL", - SecretToken: "very_secret", + DebugEnabled: ec.Bool(true), + SecretToken: "very_secret", }, }, ZoneCount: 1, diff --git a/ec/ecresource/deploymentresource/apmstate/apm_flatteners.go b/ec/ecresource/deploymentresource/apmstate/apm_flatteners.go index e6f9cb09f..c2076a202 100644 --- a/ec/ecresource/deploymentresource/apmstate/apm_flatteners.go +++ b/ec/ecresource/deploymentresource/apmstate/apm_flatteners.go @@ -108,10 +108,6 @@ func flattenConfig(cfg *models.ApmConfiguration) []interface{} { return nil } - if cfg.DockerImage != "" { - m["docker_image"] = cfg.DockerImage - } - if cfg.UserSettingsYaml != "" { m["user_settings_yaml"] = cfg.UserSettingsYaml } @@ -149,22 +145,6 @@ func flattenSystemConfig(cfg *models.ApmSystemSettings) map[string]interface{} { m["debug_enabled"] = *cfg.DebugEnabled } - if cfg.ElasticsearchPassword != "" { - m["elasticsearch_password"] = cfg.ElasticsearchPassword - } - - if cfg.ElasticsearchURL != "" { - m["elasticsearch_url"] = cfg.ElasticsearchURL - } - - if cfg.ElasticsearchUsername != "" { - m["elasticsearch_username"] = cfg.ElasticsearchUsername - } - - if cfg.KibanaURL != "" { - m["kibana_url"] = cfg.KibanaURL - } - if cfg.SecretToken != "" { m["secret_token"] = cfg.SecretToken } diff --git a/ec/ecresource/deploymentresource/apmstate/apm_flatteners_test.go b/ec/ecresource/deploymentresource/apmstate/apm_flatteners_test.go index 16d1be65a..7a49d44c4 100644 --- a/ec/ecresource/deploymentresource/apmstate/apm_flatteners_test.go +++ b/ec/ecresource/deploymentresource/apmstate/apm_flatteners_test.go @@ -134,7 +134,6 @@ func TestFlattenResource(t *testing.T) { Plan: &models.ApmPlan{ Apm: &models.ApmConfiguration{ Version: "7.8.0", - DockerImage: "some-docker-image", UserSettingsYaml: `some.setting: value`, UserSettingsOverrideYaml: `some.setting: value2`, UserSettingsJSON: `{"some.setting": "value"}`, @@ -171,7 +170,6 @@ func TestFlattenResource(t *testing.T) { "zone_count": int32(1), }}, "config": []interface{}{map[string]interface{}{ - "docker_image": "some-docker-image", "user_settings_yaml": "some.setting: value", "user_settings_override_yaml": "some.setting: value2", "user_settings_json": "{\"some.setting\": \"value\"}", @@ -201,18 +199,13 @@ func TestFlattenResource(t *testing.T) { Plan: &models.ApmPlan{ Apm: &models.ApmConfiguration{ Version: "7.8.0", - DockerImage: "some-docker-image", UserSettingsYaml: `some.setting: value`, UserSettingsOverrideYaml: `some.setting: value2`, UserSettingsJSON: `{"some.setting": "value"}`, UserSettingsOverrideJSON: `{"some.setting": "value2"}`, SystemSettings: &models.ApmSystemSettings{ - DebugEnabled: ec.Bool(true), - ElasticsearchPassword: "somepass", - ElasticsearchURL: "someURL", - ElasticsearchUsername: "someuser", - KibanaURL: "someKibanaURL", - SecretToken: "very_secret", + DebugEnabled: ec.Bool(true), + SecretToken: "very_secret", }, }, ClusterTopology: []*models.ApmTopologyElement{ @@ -245,18 +238,13 @@ func TestFlattenResource(t *testing.T) { "zone_count": int32(1), }}, "config": []interface{}{map[string]interface{}{ - "docker_image": "some-docker-image", "user_settings_yaml": "some.setting: value", "user_settings_override_yaml": "some.setting: value2", "user_settings_json": "{\"some.setting\": \"value\"}", "user_settings_override_json": "{\"some.setting\": \"value2\"}", - "debug_enabled": true, - "elasticsearch_password": "somepass", - "elasticsearch_username": "someuser", - "elasticsearch_url": "someURL", - "kibana_url": "someKibanaURL", - "secret_token": "very_secret", + "debug_enabled": true, + "secret_token": "very_secret", }}, }}, }, @@ -282,34 +270,24 @@ func TestFlattenResource(t *testing.T) { Plan: &models.ApmPlan{ Apm: &models.ApmConfiguration{ Version: "7.8.0", - DockerImage: "some-docker-image", UserSettingsYaml: `some.setting: value`, UserSettingsOverrideYaml: `some.setting: value2`, UserSettingsJSON: `{"some.setting": "value"}`, UserSettingsOverrideJSON: `{"some.setting": "value2"}`, SystemSettings: &models.ApmSystemSettings{ - DebugEnabled: ec.Bool(true), - ElasticsearchPassword: "somepass", - ElasticsearchURL: "someURL", - ElasticsearchUsername: "someuser", - KibanaURL: "someKibanaURL", - SecretToken: "very_secret", + DebugEnabled: ec.Bool(true), + SecretToken: "very_secret", }, }, ClusterTopology: []*models.ApmTopologyElement{{ Apm: &models.ApmConfiguration{ - DockerImage: "some-other-image", UserSettingsYaml: `some.setting: value`, UserSettingsOverrideYaml: `some.setting: value2`, UserSettingsJSON: `{"some.setting": "value"}`, UserSettingsOverrideJSON: `{"some.setting": "value2"}`, SystemSettings: &models.ApmSystemSettings{ - DebugEnabled: ec.Bool(true), - ElasticsearchPassword: "somepass", - ElasticsearchURL: "someURL", - ElasticsearchUsername: "someuser", - KibanaURL: "someKibanaURL", - SecretToken: "very_secret", + DebugEnabled: ec.Bool(true), + SecretToken: "very_secret", }, }, ZoneCount: 1, @@ -339,33 +317,23 @@ func TestFlattenResource(t *testing.T) { "memory_per_node": "1g", "zone_count": int32(1), "config": []interface{}{map[string]interface{}{ - "docker_image": "some-other-image", "user_settings_yaml": "some.setting: value", "user_settings_override_yaml": "some.setting: value2", "user_settings_json": "{\"some.setting\": \"value\"}", "user_settings_override_json": "{\"some.setting\": \"value2\"}", - "debug_enabled": true, - "elasticsearch_password": "somepass", - "elasticsearch_username": "someuser", - "elasticsearch_url": "someURL", - "kibana_url": "someKibanaURL", - "secret_token": "very_secret", + "debug_enabled": true, + "secret_token": "very_secret", }}, }}, "config": []interface{}{map[string]interface{}{ - "docker_image": "some-docker-image", "user_settings_yaml": "some.setting: value", "user_settings_override_yaml": "some.setting: value2", "user_settings_json": "{\"some.setting\": \"value\"}", "user_settings_override_json": "{\"some.setting\": \"value2\"}", - "debug_enabled": true, - "elasticsearch_password": "somepass", - "elasticsearch_username": "someuser", - "elasticsearch_url": "someURL", - "kibana_url": "someKibanaURL", - "secret_token": "very_secret", + "debug_enabled": true, + "secret_token": "very_secret", }}, }}, }, diff --git a/ec/ecresource/deploymentresource/schema_apm.go b/ec/ecresource/deploymentresource/schema_apm.go index 360b8bf54..531875815 100644 --- a/ec/ecresource/deploymentresource/schema_apm.go +++ b/ec/ecresource/deploymentresource/schema_apm.go @@ -109,12 +109,6 @@ func apmConfig() *schema.Schema { Description: `Optionally define the Apm configuration options for the APM Server`, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "docker_image": { - Type: schema.TypeString, - Description: `A docker URI that allows overriding of the default docker image specified for this version`, - Optional: true, - }, - // APM System Settings "debug_enabled": { Type: schema.TypeBool, @@ -122,26 +116,6 @@ func apmConfig() *schema.Schema { Optional: true, Default: false, }, - "elasticsearch_password": { - Type: schema.TypeString, - Description: `Optionally override the account within APM - defaults to a system account that always exists (if specified, the username must also be specified)`, - Optional: true, - }, - "elasticsearch_url": { - Type: schema.TypeString, - Description: `Optionally override the URL to which to send data (for advanced users only, if unspecified the system selects an internal URL)`, - Optional: true, - }, - "elasticsearch_username": { - Type: schema.TypeString, - Description: `Optionally override the account within APM - defaults to a system account that always exists (if specified, the password must also be specified)`, - Optional: true, - }, - "kibana_url": { - Type: schema.TypeString, - Description: `Optionally override the URL to which to send data (for advanced users only, if unspecified the system selects an internal URL)`, - Optional: true, - }, "secret_token": { Type: schema.TypeString, Description: `Optionally override the secret token within APM - defaults to the previously existing secretToken`, From 4d099ac3c303c47e8b70f75d225a2dc1f80f68d2 Mon Sep 17 00:00:00 2001 From: Marc Lopez Date: Thu, 20 Aug 2020 15:07:34 +0300 Subject: [PATCH 5/7] Fix typo Signed-off-by: Marc Lopez --- ec/ecresource/deploymentresource/flatteners.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ec/ecresource/deploymentresource/flatteners.go b/ec/ecresource/deploymentresource/flatteners.go index 92ad23b82..72aa079ee 100644 --- a/ec/ecresource/deploymentresource/flatteners.go +++ b/ec/ecresource/deploymentresource/flatteners.go @@ -113,7 +113,7 @@ func getDeploymentTemplateID(res *models.DeploymentResources) (string, error) { // parseCredentials parses the Create or Update response Resources populating // credential settings in the Terraform state if the keys are found, currently -// poulates the following credentials in plain text: +// populates the following credentials in plain text: // * Elasticsearch username and Password func parseCredentials(d *schema.ResourceData, resources []*models.DeploymentResource) error { var merr = multierror.NewPrefixed("failed parsing credentials") From ca60dedf08f061f5bb5ee4eb2da1cb0ce834145f Mon Sep 17 00:00:00 2001 From: Marc Lopez Date: Thu, 20 Aug 2020 15:07:53 +0300 Subject: [PATCH 6/7] Update all acceptance tests to include config Signed-off-by: Marc Lopez --- ec/acc/deployment_appsearch_test.go | 121 +++++++++++++++ ec/acc/deployment_basic_test.go | 31 ++-- ec/acc/deployment_enterprise_search_test.go | 122 +++++++++++++++ ec/acc/deployment_test.go | 139 ------------------ ec/acc/testdata/deployment_appsearch.tf | 10 +- .../deployment_appsearch_top_config.tf | 30 ++++ .../deployment_appsearch_topology_config.tf | 30 ++++ ec/acc/testdata/deployment_basic.tf | 10 +- .../testdata/deployment_basic_top_config.tf | 13 +- .../deployment_basic_topology_config.tf | 13 +- .../testdata/deployment_enterprise_search.tf | 10 +- ...deployment_enterprise_search_top_config.tf | 30 ++++ ...yment_enterprise_search_topology_config.tf | 30 ++++ 13 files changed, 412 insertions(+), 177 deletions(-) create mode 100644 ec/acc/deployment_appsearch_test.go create mode 100644 ec/acc/deployment_enterprise_search_test.go delete mode 100644 ec/acc/deployment_test.go create mode 100644 ec/acc/testdata/deployment_appsearch_top_config.tf create mode 100644 ec/acc/testdata/deployment_appsearch_topology_config.tf create mode 100644 ec/acc/testdata/deployment_enterprise_search_top_config.tf create mode 100644 ec/acc/testdata/deployment_enterprise_search_topology_config.tf diff --git a/ec/acc/deployment_appsearch_test.go b/ec/acc/deployment_appsearch_test.go new file mode 100644 index 000000000..0b258b88d --- /dev/null +++ b/ec/acc/deployment_appsearch_test.go @@ -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...), + ) +} diff --git a/ec/acc/deployment_basic_test.go b/ec/acc/deployment_basic_test.go index 5f628f5b6..06a223129 100644 --- a/ec/acc/deployment_basic_test.go +++ b/ec/acc/deployment_basic_test.go @@ -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) }, @@ -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. @@ -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), @@ -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"), diff --git a/ec/acc/deployment_enterprise_search_test.go b/ec/acc/deployment_enterprise_search_test.go new file mode 100644 index 000000000..5e02eea48 --- /dev/null +++ b/ec/acc/deployment_enterprise_search_test.go @@ -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...), + ) +} diff --git a/ec/acc/deployment_test.go b/ec/acc/deployment_test.go deleted file mode 100644 index 23101ee5e..000000000 --- a/ec/acc/deployment_test.go +++ /dev/null @@ -1,139 +0,0 @@ -// 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) - cfg := testAccDeploymentResourceAppsearch(t, randomName, region, deploymentVersionAppsearch) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProviderFactories: testAccProviderFactory, - CheckDestroy: testAccDeploymentDestroy, - Steps: []resource.TestStep{ - { - Config: cfg, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckDeploymentExists(resName), - resource.TestCheckResourceAttr(resName, "name", randomName), - 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"), - ), - }, - // Ensure that no diff is generated. - { - Config: cfg, - PlanOnly: true, - }, - // TODO: Import case when import is ready. - }, - }) -} - -func TestAccDeployment_enterpriseSearch(t *testing.T) { - resName := "ec_deployment.enterprise_search" - randomName := prefix + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) - cfg := testAccDeploymentResourceEnterpriseSearch(t, randomName, region, deploymentVersion) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProviderFactories: testAccProviderFactory, - CheckDestroy: testAccDeploymentDestroy, - Steps: []resource.TestStep{ - { - Config: cfg, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckDeploymentExists(resName), - resource.TestCheckResourceAttr(resName, "name", randomName), - 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"), - ), - }, - // Ensure that no diff is generated. - { - Config: cfg, - PlanOnly: true, - }, - // TODO: Import case when import is ready. - }, - }) -} - -func testAccDeploymentResourceAppsearch(t *testing.T, name, region, version string) string { - b, err := ioutil.ReadFile("testdata/deployment_appsearch.tf") - if err != nil { - t.Fatal(err) - } - return fmt.Sprintf(string(b), - name, region, version, - ) -} - -func testAccDeploymentResourceEnterpriseSearch(t *testing.T, name, region, version string) string { - b, err := ioutil.ReadFile("testdata/deployment_enterprise_search.tf") - if err != nil { - t.Fatal(err) - } - return fmt.Sprintf(string(b), - name, region, version, - ) -} diff --git a/ec/acc/testdata/deployment_appsearch.tf b/ec/acc/testdata/deployment_appsearch.tf index 6da274cdd..bc98a29fb 100644 --- a/ec/acc/testdata/deployment_appsearch.tf +++ b/ec/acc/testdata/deployment_appsearch.tf @@ -1,15 +1,15 @@ resource "ec_deployment" "appsearch" { - name = "%s" - region = "%s" - version = "%s" - + name = "%s" + region = "%s" + version = "%s" + # TODO: Make this template ID dependent on the region. deployment_template_id = "aws-appsearch-dedicated-v2" elasticsearch { topology { instance_configuration_id = "aws.data.highcpu.m5d" - memory_per_node = "1g" + memory_per_node = "1g" } } diff --git a/ec/acc/testdata/deployment_appsearch_top_config.tf b/ec/acc/testdata/deployment_appsearch_top_config.tf new file mode 100644 index 000000000..c5e062747 --- /dev/null +++ b/ec/acc/testdata/deployment_appsearch_top_config.tf @@ -0,0 +1,30 @@ +resource "ec_deployment" "appsearch" { + name = "%s" + region = "%s" + version = "%s" + + # TODO: Make this template ID dependent on the region. + deployment_template_id = "aws-appsearch-dedicated-v2" + + elasticsearch { + topology { + instance_configuration_id = "aws.data.highcpu.m5d" + memory_per_node = "1g" + } + } + + kibana { + topology { + instance_configuration_id = "aws.kibana.r5d" + } + } + + appsearch { + config { + user_settings_yaml = "app_search.auth.source: standard" + } + topology { + instance_configuration_id = "aws.appsearch.m5d" + } + } +} \ No newline at end of file diff --git a/ec/acc/testdata/deployment_appsearch_topology_config.tf b/ec/acc/testdata/deployment_appsearch_topology_config.tf new file mode 100644 index 000000000..fb554f294 --- /dev/null +++ b/ec/acc/testdata/deployment_appsearch_topology_config.tf @@ -0,0 +1,30 @@ +resource "ec_deployment" "appsearch" { + name = "%s" + region = "%s" + version = "%s" + + # TODO: Make this template ID dependent on the region. + deployment_template_id = "aws-appsearch-dedicated-v2" + + elasticsearch { + topology { + instance_configuration_id = "aws.data.highcpu.m5d" + memory_per_node = "1g" + } + } + + kibana { + topology { + instance_configuration_id = "aws.kibana.r5d" + } + } + + appsearch { + topology { + config { + user_settings_yaml = "app_search.auth.source: standard" + } + instance_configuration_id = "aws.appsearch.m5d" + } + } +} \ No newline at end of file diff --git a/ec/acc/testdata/deployment_basic.tf b/ec/acc/testdata/deployment_basic.tf index 4794de89b..184cafd64 100644 --- a/ec/acc/testdata/deployment_basic.tf +++ b/ec/acc/testdata/deployment_basic.tf @@ -1,15 +1,15 @@ resource "ec_deployment" "basic" { - name = "%s" - region = "%s" - version = "%s" - + name = "%s" + region = "%s" + version = "%s" + # TODO: Make this template ID dependent on the region. deployment_template_id = "aws-io-optimized-v2" elasticsearch { topology { instance_configuration_id = "aws.data.highio.i3" - memory_per_node = "1g" + memory_per_node = "1g" } } diff --git a/ec/acc/testdata/deployment_basic_top_config.tf b/ec/acc/testdata/deployment_basic_top_config.tf index 51775f9a3..c92d7b3d8 100644 --- a/ec/acc/testdata/deployment_basic_top_config.tf +++ b/ec/acc/testdata/deployment_basic_top_config.tf @@ -1,19 +1,22 @@ resource "ec_deployment" "basic" { - name = "%s" - region = "%s" - version = "%s" - + name = "%s" + region = "%s" + version = "%s" + # TODO: Make this template ID dependent on the region. deployment_template_id = "aws-io-optimized-v2" elasticsearch { topology { instance_configuration_id = "aws.data.highio.i3" - memory_per_node = "1g" + memory_per_node = "1g" } } kibana { + config { + user_settings_yaml = "csp.warnLegacyBrowsers: true" + } topology { instance_configuration_id = "aws.kibana.r5d" } diff --git a/ec/acc/testdata/deployment_basic_topology_config.tf b/ec/acc/testdata/deployment_basic_topology_config.tf index cdb62c637..455eb55b8 100644 --- a/ec/acc/testdata/deployment_basic_topology_config.tf +++ b/ec/acc/testdata/deployment_basic_topology_config.tf @@ -1,20 +1,23 @@ resource "ec_deployment" "basic" { - name = "%s" - region = "%s" - version = "%s" - + name = "%s" + region = "%s" + version = "%s" + # TODO: Make this template ID dependent on the region. deployment_template_id = "aws-io-optimized-v2" elasticsearch { topology { instance_configuration_id = "aws.data.highio.i3" - memory_per_node = "1g" + memory_per_node = "1g" } } kibana { topology { + config { + user_settings_yaml = "csp.warnLegacyBrowsers: true" + } instance_configuration_id = "aws.kibana.r5d" } } diff --git a/ec/acc/testdata/deployment_enterprise_search.tf b/ec/acc/testdata/deployment_enterprise_search.tf index f7853a482..35577ec0e 100644 --- a/ec/acc/testdata/deployment_enterprise_search.tf +++ b/ec/acc/testdata/deployment_enterprise_search.tf @@ -1,15 +1,15 @@ resource "ec_deployment" "enterprise_search" { - name = "%s" - region = "%s" - version = "%s" - + name = "%s" + region = "%s" + version = "%s" + # TODO: Make this template ID dependent on the region. deployment_template_id = "aws-enterprise-search-dedicated-v2" elasticsearch { topology { instance_configuration_id = "aws.data.highcpu.m5d" - memory_per_node = "1g" + memory_per_node = "1g" } } diff --git a/ec/acc/testdata/deployment_enterprise_search_top_config.tf b/ec/acc/testdata/deployment_enterprise_search_top_config.tf new file mode 100644 index 000000000..b1a21878d --- /dev/null +++ b/ec/acc/testdata/deployment_enterprise_search_top_config.tf @@ -0,0 +1,30 @@ +resource "ec_deployment" "enterprise_search" { + name = "%s" + region = "%s" + version = "%s" + + # TODO: Make this template ID dependent on the region. + deployment_template_id = "aws-enterprise-search-dedicated-v2" + + elasticsearch { + topology { + instance_configuration_id = "aws.data.highcpu.m5d" + memory_per_node = "1g" + } + } + + kibana { + topology { + instance_configuration_id = "aws.kibana.r5d" + } + } + + enterprise_search { + config { + user_settings_yaml = "ent_search.auth.source: standard" + } + topology { + instance_configuration_id = "aws.enterprisesearch.m5d" + } + } +} \ No newline at end of file diff --git a/ec/acc/testdata/deployment_enterprise_search_topology_config.tf b/ec/acc/testdata/deployment_enterprise_search_topology_config.tf new file mode 100644 index 000000000..9346f679a --- /dev/null +++ b/ec/acc/testdata/deployment_enterprise_search_topology_config.tf @@ -0,0 +1,30 @@ +resource "ec_deployment" "enterprise_search" { + name = "%s" + region = "%s" + version = "%s" + + # TODO: Make this template ID dependent on the region. + deployment_template_id = "aws-enterprise-search-dedicated-v2" + + elasticsearch { + topology { + instance_configuration_id = "aws.data.highcpu.m5d" + memory_per_node = "1g" + } + } + + kibana { + topology { + instance_configuration_id = "aws.kibana.r5d" + } + } + + enterprise_search { + topology { + config { + user_settings_yaml = "ent_search.auth.source: standard" + } + instance_configuration_id = "aws.enterprisesearch.m5d" + } + } +} \ No newline at end of file From 6fbf6f14d29ce236a4474266412ac6f61ea70599 Mon Sep 17 00:00:00 2001 From: Marc Lopez Date: Mon, 24 Aug 2020 15:22:49 +0300 Subject: [PATCH 7/7] Remove User settings comment Signed-off-by: Marc Lopez --- ec/ecresource/deploymentresource/schema_apm.go | 1 - ec/ecresource/deploymentresource/schema_appsearch.go | 1 - ec/ecresource/deploymentresource/schema_enteprise_search.go | 1 - ec/ecresource/deploymentresource/schema_kibana.go | 1 - 4 files changed, 4 deletions(-) diff --git a/ec/ecresource/deploymentresource/schema_apm.go b/ec/ecresource/deploymentresource/schema_apm.go index 531875815..9f798ddd4 100644 --- a/ec/ecresource/deploymentresource/schema_apm.go +++ b/ec/ecresource/deploymentresource/schema_apm.go @@ -123,7 +123,6 @@ func apmConfig() *schema.Schema { Computed: true, }, - // User settings "user_settings_json": { Type: schema.TypeString, Description: `An arbitrary JSON object allowing (non-admin) cluster owners to set their parameters (only one of this and 'user_settings_yaml' is allowed), provided they are on the whitelist ('user_settings_whitelist') and not on the blacklist ('user_settings_blacklist'). (This field together with 'user_settings_override*' and 'system_settings' defines the total set of resource settings)`, diff --git a/ec/ecresource/deploymentresource/schema_appsearch.go b/ec/ecresource/deploymentresource/schema_appsearch.go index 196fa1a26..e4e6b2171 100644 --- a/ec/ecresource/deploymentresource/schema_appsearch.go +++ b/ec/ecresource/deploymentresource/schema_appsearch.go @@ -124,7 +124,6 @@ func appSearchConfig() *schema.Schema { Computed: true, }, - // User settings "user_settings_json": { Type: schema.TypeString, Description: `An arbitrary JSON object allowing (non-admin) cluster owners to set their parameters (only one of this and 'user_settings_yaml' is allowed), provided they are on the whitelist ('user_settings_whitelist') and not on the blacklist ('user_settings_blacklist'). (This field together with 'user_settings_override*' and 'system_settings' defines the total set of resource settings)`, diff --git a/ec/ecresource/deploymentresource/schema_enteprise_search.go b/ec/ecresource/deploymentresource/schema_enteprise_search.go index 41ef44ece..6df103cce 100644 --- a/ec/ecresource/deploymentresource/schema_enteprise_search.go +++ b/ec/ecresource/deploymentresource/schema_enteprise_search.go @@ -127,7 +127,6 @@ func enterpriseSearchConfig() *schema.Schema { Computed: true, }, - // User settings "user_settings_json": { Type: schema.TypeString, Description: `An arbitrary JSON object allowing (non-admin) cluster owners to set their parameters (only one of this and 'user_settings_yaml' is allowed), provided they are on the whitelist ('user_settings_whitelist') and not on the blacklist ('user_settings_blacklist'). (This field together with 'user_settings_override*' and 'system_settings' defines the total set of resource settings)`, diff --git a/ec/ecresource/deploymentresource/schema_kibana.go b/ec/ecresource/deploymentresource/schema_kibana.go index fbf506017..f5839defe 100644 --- a/ec/ecresource/deploymentresource/schema_kibana.go +++ b/ec/ecresource/deploymentresource/schema_kibana.go @@ -107,7 +107,6 @@ func kibanaConfig() *schema.Schema { Description: `Optionally define the Kibana configuration options for the Kibana Server`, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - // User settings "user_settings_json": { Type: schema.TypeString, Description: `An arbitrary JSON object allowing (non-admin) cluster owners to set their parameters (only one of this and 'user_settings_yaml' is allowed), provided they are on the whitelist ('user_settings_whitelist') and not on the blacklist ('user_settings_blacklist'). (This field together with 'user_settings_override*' and 'system_settings' defines the total set of resource settings)`,