99	"github.com/elastic/terraform-provider-elasticstack/internal/acctest" 
1010	"github.com/elastic/terraform-provider-elasticstack/internal/clients" 
1111	"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" 
12+ 	"github.com/elastic/terraform-provider-elasticstack/internal/kibana" 
1213	"github.com/elastic/terraform-provider-elasticstack/internal/versionutils" 
14+ 	"github.com/google/uuid" 
1315	"github.com/hashicorp/go-version" 
1416	sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" 
1517	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" 
@@ -21,7 +23,11 @@ func TestAccResourceKibanaConnectorCasesWebhook(t *testing.T) {
2123
2224	connectorName  :=  sdkacctest .RandStringFromCharSet (22 , sdkacctest .CharSetAlphaNum )
2325
24- 	create  :=  func (name  string ) string  {
26+ 	create  :=  func (name , id  string ) string  {
27+ 		idAttribute  :=  "" 
28+ 		if  id  !=  ""  {
29+ 			idAttribute  =  fmt .Sprintf (`connector_id = "%s"` , id )
30+ 		}
2531		return  fmt .Sprintf (` 
2632	provider "elasticstack" { 
2733	  elasticsearch {} 
@@ -30,6 +36,7 @@ func TestAccResourceKibanaConnectorCasesWebhook(t *testing.T) {
3036
3137	resource "elasticstack_kibana_action_connector" "test" { 
3238	  name         = "%s" 
39+ 	  %s 
3340	  config       = jsonencode({ 
3441		createIncidentJson = "{}" 
3542		createIncidentResponseKey = "key" 
@@ -46,10 +53,14 @@ func TestAccResourceKibanaConnectorCasesWebhook(t *testing.T) {
4653	  }) 
4754	  connector_type_id = ".cases-webhook" 
4855	}` ,
49- 			name )
56+ 			name ,  idAttribute )
5057	}
5158
52- 	update  :=  func (name  string ) string  {
59+ 	update  :=  func (name , id  string ) string  {
60+ 		idAttribute  :=  "" 
61+ 		if  id  !=  ""  {
62+ 			idAttribute  =  fmt .Sprintf (`connector_id = "%s"` , id )
63+ 		}
5364		return  fmt .Sprintf (` 
5465	provider "elasticstack" { 
5566	  elasticsearch {} 
@@ -58,6 +69,7 @@ func TestAccResourceKibanaConnectorCasesWebhook(t *testing.T) {
5869
5970	resource "elasticstack_kibana_action_connector" "test" { 
6071	  name         = "Updated %s" 
72+ 	  %s 
6173	  config = jsonencode({ 
6274		createIncidentJson = "{}" 
6375		createIncidentResponseKey = "key" 
@@ -75,57 +87,81 @@ func TestAccResourceKibanaConnectorCasesWebhook(t *testing.T) {
7587	  }) 
7688	  connector_type_id = ".cases-webhook" 
7789	}` ,
78- 			name )
90+ 			name , idAttribute )
91+ 	}
92+ 
93+ 	for  _ , connectorID  :=  range  []string {"" , uuid .NewString ()} {
94+ 		t .Run (fmt .Sprintf ("with connector ID '%s'" , connectorID ), func (t  * testing.T ) {
95+ 			minVersion  :=  minSupportedVersion 
96+ 			if  connectorID  !=  ""  {
97+ 				minVersion  =  kibana .MinVersionSupportingPreconfiguredIDs 
98+ 			}
99+ 
100+ 			resource .Test (t , resource.TestCase {
101+ 				PreCheck :                 func () { acctest .PreCheck (t ) },
102+ 				CheckDestroy :             checkResourceKibanaConnectorDestroy ,
103+ 				ProtoV6ProviderFactories : acctest .Providers ,
104+ 				Steps : []resource.TestStep {
105+ 					{
106+ 						SkipFunc : versionutils .CheckIfVersionIsUnsupported (minVersion ),
107+ 						Config :   create (connectorName , connectorID ),
108+ 						Check : resource .ComposeTestCheckFunc (
109+ 							testCommonAttributes (connectorName , ".cases-webhook" ),
110+ 
111+ 							resource .TestCheckResourceAttrWith ("elasticstack_kibana_action_connector.test" , "connector_id" , func (value  string ) error  {
112+ 								if  connectorID  ==  ""  {
113+ 									if  _ , err  :=  uuid .Parse (value ); err  !=  nil  {
114+ 										return  fmt .Errorf ("expected connector_id to be a uuid: %w" , err )
115+ 									}
116+ 
117+ 									return  nil 
118+ 								}
119+ 
120+ 								if  connectorID  !=  value  {
121+ 									return  fmt .Errorf ("expected connector_id to match pre-defined id. '%s' != %s" , connectorID , value )
122+ 								}
123+ 
124+ 								return  nil 
125+ 							}),
126+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentJson\":\"{}\"` )),
127+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentResponseKey\":\"key\"` )),
128+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentUrl\":\"https://www\.elastic\.co/\"` )),
129+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentResponseExternalTitleKey\":\"title\"` )),
130+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentUrl\":\"https://www\.elastic\.co/\"` )),
131+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentJson\":\"{}\"` )),
132+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentUrl\":\"https://www.elastic\.co/\"` )),
133+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"viewIncidentUrl\":\"https://www\.elastic\.co/\"` )),
134+ 							// `post` is the default value that is returned by backend 
135+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`"createIncidentMethod\":\"post\"` )),
136+ 
137+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"user\":\"user1\"` )),
138+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"password\":\"password1\"` )),
139+ 						),
140+ 					},
141+ 					{
142+ 						SkipFunc : versionutils .CheckIfVersionIsUnsupported (minSupportedVersion ),
143+ 						Config :   update (connectorName , connectorID ),
144+ 						Check : resource .ComposeTestCheckFunc (
145+ 							testCommonAttributes (fmt .Sprintf ("Updated %s" , connectorName ), ".cases-webhook" ),
146+ 
147+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentJson\":\"{}\"` )),
148+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentResponseKey\":\"key\"` )),
149+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentUrl\":\"https://www\.elastic\.co/\"` )),
150+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentResponseExternalTitleKey\":\"title\"` )),
151+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentUrl\":\"https://www\.elastic\.co/\"` )),
152+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentJson\":\"{}\"` )),
153+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentUrl\":\"https://elasticsearch\.com/\"` )),
154+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"viewIncidentUrl\":\"https://www\.elastic\.co/\"` )),
155+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`createIncidentMethod\":\"put\"` )),
156+ 
157+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"user\":\"user2\"` )),
158+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"password\":\"password2\"` )),
159+ 						),
160+ 					},
161+ 				},
162+ 			})
163+ 		})
79164	}
80- 
81- 	resource .Test (t , resource.TestCase {
82- 		PreCheck :                 func () { acctest .PreCheck (t ) },
83- 		CheckDestroy :             checkResourceKibanaConnectorDestroy ,
84- 		ProtoV6ProviderFactories : acctest .Providers ,
85- 		Steps : []resource.TestStep {
86- 			{
87- 				SkipFunc : versionutils .CheckIfVersionIsUnsupported (minSupportedVersion ),
88- 				Config :   create (connectorName ),
89- 				Check : resource .ComposeTestCheckFunc (
90- 					testCommonAttributes (connectorName , ".cases-webhook" ),
91- 
92- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentJson\":\"{}\"` )),
93- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentResponseKey\":\"key\"` )),
94- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentUrl\":\"https://www\.elastic\.co/\"` )),
95- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentResponseExternalTitleKey\":\"title\"` )),
96- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentUrl\":\"https://www\.elastic\.co/\"` )),
97- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentJson\":\"{}\"` )),
98- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentUrl\":\"https://www.elastic\.co/\"` )),
99- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"viewIncidentUrl\":\"https://www\.elastic\.co/\"` )),
100- 					// `post` is the default value that is returned by backend 
101- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`"createIncidentMethod\":\"post\"` )),
102- 
103- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"user\":\"user1\"` )),
104- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"password\":\"password1\"` )),
105- 				),
106- 			},
107- 			{
108- 				SkipFunc : versionutils .CheckIfVersionIsUnsupported (minSupportedVersion ),
109- 				Config :   update (connectorName ),
110- 				Check : resource .ComposeTestCheckFunc (
111- 					testCommonAttributes (fmt .Sprintf ("Updated %s" , connectorName ), ".cases-webhook" ),
112- 
113- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentJson\":\"{}\"` )),
114- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentResponseKey\":\"key\"` )),
115- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentUrl\":\"https://www\.elastic\.co/\"` )),
116- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentResponseExternalTitleKey\":\"title\"` )),
117- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentUrl\":\"https://www\.elastic\.co/\"` )),
118- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentJson\":\"{}\"` )),
119- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentUrl\":\"https://elasticsearch\.com/\"` )),
120- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"viewIncidentUrl\":\"https://www\.elastic\.co/\"` )),
121- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`createIncidentMethod\":\"put\"` )),
122- 
123- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"user\":\"user2\"` )),
124- 					resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"password\":\"password2\"` )),
125- 				),
126- 			},
127- 		},
128- 	})
129165}
130166
131167func  TestAccResourceKibanaConnectorEmail (t  * testing.T ) {
0 commit comments