From 8c29ee8f332bfd437a49f5da976e1db41cde0f48 Mon Sep 17 00:00:00 2001 From: Toby Brain Date: Wed, 6 Mar 2024 19:01:51 +1100 Subject: [PATCH] Stateless resources require kibana (#792) * Stateless resources require kibana * Changelog --- .changelog/792.txt | 3 +++ ec/ecresource/deploymentresource/apm/v2/schema.go | 6 ++++++ .../deploymentresource/enterprisesearch/v2/schema.go | 6 ++++++ .../deploymentresource/integrationsserver/v2/schema.go | 6 ++++++ 4 files changed, 21 insertions(+) create mode 100644 .changelog/792.txt diff --git a/.changelog/792.txt b/.changelog/792.txt new file mode 100644 index 000000000..78828d2a9 --- /dev/null +++ b/.changelog/792.txt @@ -0,0 +1,3 @@ +```release-note:feature +resource/deployment: Validate the Kibana is present when attempting to enable other stateless resources. +``` diff --git a/ec/ecresource/deploymentresource/apm/v2/schema.go b/ec/ecresource/deploymentresource/apm/v2/schema.go index 56947d659..95baa6e15 100644 --- a/ec/ecresource/deploymentresource/apm/v2/schema.go +++ b/ec/ecresource/deploymentresource/apm/v2/schema.go @@ -19,16 +19,22 @@ package v2 import ( "github.com/elastic/terraform-provider-ec/ec/internal/planmodifiers" + "github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" ) func ApmConfigSchema() schema.Attribute { return schema.SingleNestedAttribute{ Description: `Optionally define the Apm configuration options for the APM Server`, Optional: true, + Validators: []validator.Object{ + objectvalidator.AlsoRequires(path.MatchRoot("kibana")), + }, Attributes: map[string]schema.Attribute{ "docker_image": schema.StringAttribute{ Description: "Optionally override the docker image the APM nodes will use. This option will not work in ESS customers and should only be changed if you know what you're doing.", diff --git a/ec/ecresource/deploymentresource/enterprisesearch/v2/schema.go b/ec/ecresource/deploymentresource/enterprisesearch/v2/schema.go index 5c6edae65..69b400c02 100644 --- a/ec/ecresource/deploymentresource/enterprisesearch/v2/schema.go +++ b/ec/ecresource/deploymentresource/enterprisesearch/v2/schema.go @@ -19,17 +19,23 @@ package v2 import ( "github.com/elastic/terraform-provider-ec/ec/internal/planmodifiers" + "github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" ) func EnterpriseSearchSchema() schema.Attribute { return schema.SingleNestedAttribute{ Description: "Enterprise Search cluster definition.", Optional: true, + Validators: []validator.Object{ + objectvalidator.AlsoRequires(path.MatchRoot("kibana")), + }, Attributes: map[string]schema.Attribute{ "elasticsearch_cluster_ref_id": schema.StringAttribute{ Optional: true, diff --git a/ec/ecresource/deploymentresource/integrationsserver/v2/schema.go b/ec/ecresource/deploymentresource/integrationsserver/v2/schema.go index f368da866..bf273f5e4 100644 --- a/ec/ecresource/deploymentresource/integrationsserver/v2/schema.go +++ b/ec/ecresource/deploymentresource/integrationsserver/v2/schema.go @@ -19,12 +19,15 @@ package v2 import ( "github.com/elastic/terraform-provider-ec/ec/internal/planmodifiers" + "github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -32,6 +35,9 @@ func IntegrationsServerSchema() schema.Attribute { return schema.SingleNestedAttribute{ Description: "Integrations Server cluster definition. Integrations Server replaces `apm` in Stack versions > 8.0", Optional: true, + Validators: []validator.Object{ + objectvalidator.AlsoRequires(path.MatchRoot("kibana")), + }, Attributes: map[string]schema.Attribute{ "elasticsearch_cluster_ref_id": schema.StringAttribute{ Optional: true,