From ddcc52839523cded22247f0d707840b41fe69742 Mon Sep 17 00:00:00 2001
From: Sander Philipse <94373878+sphilipse@users.noreply.github.com>
Date: Fri, 13 Oct 2023 18:03:21 +0200
Subject: [PATCH] [Search] Fix native connectors not configuring correctly
 (#168858)

## Summary

This fixes an issue with native connectors not being set to configured
after being configured.
---
 .../kbn-search-connectors/lib/create_connector_document.ts     | 2 +-
 .../lib/update_connector_configuration.ts                      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/packages/kbn-search-connectors/lib/create_connector_document.ts b/packages/kbn-search-connectors/lib/create_connector_document.ts
index c5654e9a2436a..bd05ef3c79958 100644
--- a/packages/kbn-search-connectors/lib/create_connector_document.ts
+++ b/packages/kbn-search-connectors/lib/create_connector_document.ts
@@ -116,7 +116,7 @@ export function createConnectorDocument({
       incremental: { enabled: false, interval: '0 0 0 * * ?' },
     },
     service_type: serviceType || null,
-    status: ConnectorStatus.CREATED,
+    status: isNative ? ConnectorStatus.NEEDS_CONFIGURATION : ConnectorStatus.CREATED,
     sync_now: false,
   };
 }
diff --git a/packages/kbn-search-connectors/lib/update_connector_configuration.ts b/packages/kbn-search-connectors/lib/update_connector_configuration.ts
index dfb43af53db44..473932ecfddca 100644
--- a/packages/kbn-search-connectors/lib/update_connector_configuration.ts
+++ b/packages/kbn-search-connectors/lib/update_connector_configuration.ts
@@ -26,7 +26,8 @@ export const updateConnectorConfiguration = async (
   const connector = connectorResult?.value;
   if (connector) {
     const status =
-      connector.status === ConnectorStatus.NEEDS_CONFIGURATION
+      connector.status === ConnectorStatus.NEEDS_CONFIGURATION ||
+      connector.status === ConnectorStatus.CREATED
         ? ConnectorStatus.CONFIGURED
         : connector.status;
     const updatedConfig = Object.keys(connector.configuration)