@@ -10,6 +10,7 @@ import (
1010	"github.com/elastic/terraform-provider-elasticstack/internal/clients" 
1111	"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" 
1212	"github.com/elastic/terraform-provider-elasticstack/internal/versionutils" 
13+ 	"github.com/google/uuid" 
1314	"github.com/hashicorp/go-version" 
1415	sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" 
1516	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" 
@@ -21,7 +22,11 @@ func TestAccResourceKibanaConnectorCasesWebhook(t *testing.T) {
2122
2223	connectorName  :=  sdkacctest .RandStringFromCharSet (22 , sdkacctest .CharSetAlphaNum )
2324
24- 	create  :=  func (name  string ) string  {
25+ 	create  :=  func (name , id  string ) string  {
26+ 		idAttribute  :=  "" 
27+ 		if  id  !=  ""  {
28+ 			idAttribute  =  fmt .Sprintf (`connector_id = "%s"` , id )
29+ 		}
2530		return  fmt .Sprintf (` 
2631	provider "elasticstack" { 
2732	  elasticsearch {} 
@@ -30,6 +35,7 @@ func TestAccResourceKibanaConnectorCasesWebhook(t *testing.T) {
3035
3136	resource "elasticstack_kibana_action_connector" "test" { 
3237	  name         = "%s" 
38+ 	  %s 
3339	  config       = jsonencode({ 
3440		createIncidentJson = "{}" 
3541		createIncidentResponseKey = "key" 
@@ -46,10 +52,14 @@ func TestAccResourceKibanaConnectorCasesWebhook(t *testing.T) {
4652	  }) 
4753	  connector_type_id = ".cases-webhook" 
4854	}` ,
49- 			name )
55+ 			name ,  idAttribute )
5056	}
5157
52- 	update  :=  func (name  string ) string  {
58+ 	update  :=  func (name , id  string ) string  {
59+ 		idAttribute  :=  "" 
60+ 		if  id  !=  ""  {
61+ 			idAttribute  =  fmt .Sprintf (`connector_id = "%s"` , id )
62+ 		}
5363		return  fmt .Sprintf (` 
5464	provider "elasticstack" { 
5565	  elasticsearch {} 
@@ -58,6 +68,7 @@ func TestAccResourceKibanaConnectorCasesWebhook(t *testing.T) {
5868
5969	resource "elasticstack_kibana_action_connector" "test" { 
6070	  name         = "Updated %s" 
71+ 	  %s 
6172	  config = jsonencode({ 
6273		createIncidentJson = "{}" 
6374		createIncidentResponseKey = "key" 
@@ -75,57 +86,76 @@ func TestAccResourceKibanaConnectorCasesWebhook(t *testing.T) {
7586	  }) 
7687	  connector_type_id = ".cases-webhook" 
7788	}` ,
78- 			name )
89+ 			name , idAttribute )
90+ 	}
91+ 
92+ 	for  _ , connectorID  :=  range  []string {"" , uuid .NewString ()} {
93+ 		t .Run (fmt .Sprintf ("with connector ID '%s'" , connectorID ), func (t  * testing.T ) {
94+ 			resource .Test (t , resource.TestCase {
95+ 				PreCheck :                 func () { acctest .PreCheck (t ) },
96+ 				CheckDestroy :             checkResourceKibanaConnectorDestroy ,
97+ 				ProtoV6ProviderFactories : acctest .Providers ,
98+ 				Steps : []resource.TestStep {
99+ 					{
100+ 						SkipFunc : versionutils .CheckIfVersionIsUnsupported (minSupportedVersion ),
101+ 						Config :   create (connectorName , connectorID ),
102+ 						Check : resource .ComposeTestCheckFunc (
103+ 							testCommonAttributes (connectorName , ".cases-webhook" ),
104+ 
105+ 							resource .TestCheckResourceAttrWith ("elasticstack_kibana_action_connector.test" , "connector_id" , func (value  string ) error  {
106+ 								if  connectorID  ==  ""  {
107+ 									if  _ , err  :=  uuid .Parse (value ); err  !=  nil  {
108+ 										return  fmt .Errorf ("expected connector_id to be a uuid: %w" , err )
109+ 									}
110+ 
111+ 									return  nil 
112+ 								}
113+ 
114+ 								if  connectorID  !=  value  {
115+ 									return  fmt .Errorf ("expected connector_id to match pre-defined id. '%s' != %s" , connectorID , value )
116+ 								}
117+ 
118+ 								return  nil 
119+ 							}),
120+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentJson\":\"{}\"` )),
121+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentResponseKey\":\"key\"` )),
122+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentUrl\":\"https://www\.elastic\.co/\"` )),
123+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentResponseExternalTitleKey\":\"title\"` )),
124+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentUrl\":\"https://www\.elastic\.co/\"` )),
125+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentJson\":\"{}\"` )),
126+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentUrl\":\"https://www.elastic\.co/\"` )),
127+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"viewIncidentUrl\":\"https://www\.elastic\.co/\"` )),
128+ 							// `post` is the default value that is returned by backend 
129+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`"createIncidentMethod\":\"post\"` )),
130+ 
131+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"user\":\"user1\"` )),
132+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"password\":\"password1\"` )),
133+ 						),
134+ 					},
135+ 					{
136+ 						SkipFunc : versionutils .CheckIfVersionIsUnsupported (minSupportedVersion ),
137+ 						Config :   update (connectorName , connectorID ),
138+ 						Check : resource .ComposeTestCheckFunc (
139+ 							testCommonAttributes (fmt .Sprintf ("Updated %s" , connectorName ), ".cases-webhook" ),
140+ 
141+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentJson\":\"{}\"` )),
142+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentResponseKey\":\"key\"` )),
143+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"createIncidentUrl\":\"https://www\.elastic\.co/\"` )),
144+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentResponseExternalTitleKey\":\"title\"` )),
145+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"getIncidentUrl\":\"https://www\.elastic\.co/\"` )),
146+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentJson\":\"{}\"` )),
147+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"updateIncidentUrl\":\"https://elasticsearch\.com/\"` )),
148+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`\"viewIncidentUrl\":\"https://www\.elastic\.co/\"` )),
149+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "config" , regexp .MustCompile (`createIncidentMethod\":\"put\"` )),
150+ 
151+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"user\":\"user2\"` )),
152+ 							resource .TestMatchResourceAttr ("elasticstack_kibana_action_connector.test" , "secrets" , regexp .MustCompile (`\"password\":\"password2\"` )),
153+ 						),
154+ 					},
155+ 				},
156+ 			})
157+ 		})
79158	}
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- 	})
129159}
130160
131161func  TestAccResourceKibanaConnectorEmail (t  * testing.T ) {
0 commit comments