Skip to content

Commit 4bf79d8

Browse files
Meghana-Shahjotruon
authored andcommitted
Added - Support for File Filter Devops
1 parent ff20fdc commit 4bf79d8

File tree

5 files changed

+864
-13
lines changed

5 files changed

+864
-13
lines changed

examples/devops/build_service/build.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,24 @@ resource "oci_devops_trigger" "test_trigger" {
252252

253253
#Optional
254254
events = ["PUSH"]
255+
exclude {
256+
257+
#Optional
258+
file_filter {
259+
260+
#Optional
261+
file_paths = ["**/*.md"]
262+
}
263+
}
255264
include {
256265

257266
#Optional
258267
base_ref = "baseRef"
268+
file_filter {
269+
270+
#Optional
271+
file_paths = ["**/*.txt"]
272+
}
259273
head_ref = "headRef"
260274
}
261275
}
@@ -282,10 +296,24 @@ resource "oci_devops_trigger" "test_gitlab_trigger" {
282296

283297
#Optional
284298
events = ["PUSH"]
299+
exclude {
300+
301+
#Optional
302+
file_filter {
303+
304+
#Optional
305+
file_paths = ["**/*.md"]
306+
}
307+
}
285308
include {
286309

287310
#Optional
288311
base_ref = "baseRef"
312+
file_filter {
313+
314+
#Optional
315+
file_paths = ["**/*.txt"]
316+
}
289317
head_ref = "headRef"
290318
}
291319
}
@@ -312,10 +340,24 @@ resource "oci_devops_trigger" "test_code_repo_trigger" {
312340

313341
#Optional
314342
events = ["PUSH"]
343+
exclude {
344+
345+
#Optional
346+
file_filter {
347+
348+
#Optional
349+
file_paths = ["**/*.md"]
350+
}
351+
}
315352
include {
316353

317354
#Optional
318355
base_ref = "baseRef"
356+
file_filter {
357+
358+
#Optional
359+
file_paths = ["**/*.txt"]
360+
}
319361
head_ref = "headRef"
320362
}
321363
}

internal/integrationtest/devops_trigger_test.go

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var (
4848
"actions": acctest.RepresentationGroup{RepType: acctest.Required, Group: DevopsTriggerActionsRepresentation},
4949
"project_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_devops_project.test_project.id}`},
5050
"trigger_source": acctest.Representation{RepType: acctest.Required, Create: `GITHUB`},
51+
"connection_id": acctest.Representation{RepType: acctest.Optional, Create: `${oci_devops_connection.test_connection.id}`},
5152
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
5253
"description": acctest.Representation{RepType: acctest.Optional, Create: `description`, Update: `description2`},
5354
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
@@ -61,16 +62,29 @@ var (
6162
}
6263
DevopsTriggerActionsFilterRepresentation = map[string]interface{}{
6364
"trigger_source": acctest.Representation{RepType: acctest.Required, Create: `GITHUB`, Update: `GITHUB`},
64-
"events": acctest.Representation{RepType: acctest.Optional, Create: []string{`PUSH`}, Update: []string{`PULL_REQUEST_CREATED`}},
65+
"events": acctest.Representation{RepType: acctest.Optional, Create: []string{`PUSH`}, Update: []string{`PUSH`}},
6566
"include": acctest.RepresentationGroup{RepType: acctest.Optional, Group: DevopsTriggerActionsFilterIncludeRepresentation},
67+
"exclude": acctest.RepresentationGroup{RepType: acctest.Optional, Group: triggerActionsFilterExcludeRepresentation},
68+
}
69+
triggerActionsFilterExcludeRepresentation = map[string]interface{}{
70+
"file_filter": acctest.RepresentationGroup{RepType: acctest.Optional, Group: triggerActionsFilterExcludeFileFilterRepresentation},
6671
}
6772
DevopsTriggerActionsFilterIncludeRepresentation = map[string]interface{}{
68-
"base_ref": acctest.Representation{RepType: acctest.Optional, Create: `baseRef`, Update: `baseRef2`},
69-
"head_ref": acctest.Representation{RepType: acctest.Optional, Create: `headRef`, Update: `headRef2`},
73+
"base_ref": acctest.Representation{RepType: acctest.Optional, Create: `baseRef`, Update: `baseRef2`},
74+
"file_filter": acctest.RepresentationGroup{RepType: acctest.Optional, Group: triggerActionsFilterIncludeFileFilterRepresentation},
75+
"head_ref": acctest.Representation{RepType: acctest.Optional, Create: `headRef`, Update: `headRef2`},
76+
}
77+
triggerActionsFilterExcludeFileFilterRepresentation = map[string]interface{}{
78+
"file_paths": acctest.Representation{RepType: acctest.Optional, Create: []string{`filePaths1`}, Update: []string{`filePaths1`}},
79+
}
80+
triggerActionsFilterIncludeFileFilterRepresentation = map[string]interface{}{
81+
"file_paths": acctest.Representation{RepType: acctest.Optional, Create: []string{`filePaths2`}, Update: []string{`filePaths2`}},
7082
}
7183

7284
DevopsTriggerResourceDependencies = acctest.GenerateResourceFromRepresentationMap("oci_devops_build_pipeline", "test_build_pipeline", acctest.Required, acctest.Create, DevopsBuildPipelineRepresentation) +
85+
acctest.GenerateResourceFromRepresentationMap("oci_devops_connection", "test_connection", acctest.Required, acctest.Create, DevopsConnectionRepresentation) +
7386
acctest.GenerateResourceFromRepresentationMap("oci_devops_project", "test_project", acctest.Required, acctest.Create, DevopsProjectRepresentation) +
87+
acctest.GenerateResourceFromRepresentationMap("oci_devops_repository", "test_repository", acctest.Required, acctest.Create, DevopsRepositoryRepresentation) +
7488
DefinedTagsDependencies +
7589
acctest.GenerateResourceFromRepresentationMap("oci_ons_notification_topic", "test_notification_topic", acctest.Required, acctest.Create, OnsNotificationTopicRepresentation)
7690
)
@@ -85,19 +99,22 @@ func TestDevopsTriggerResource_basic(t *testing.T) {
8599
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
86100
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
87101

102+
githubAccessTokenVaultId := utils.GetEnvSettingWithBlankDefault("github_access_token_vault_id")
103+
githubAccessTokenVaultIdStr := fmt.Sprintf("variable \"github_access_token_vault_id\" { default = \"%s\" }\n", githubAccessTokenVaultId)
104+
88105
resourceName := "oci_devops_trigger.test_trigger"
89106
datasourceName := "data.oci_devops_triggers.test_triggers"
90107
singularDatasourceName := "data.oci_devops_trigger.test_trigger"
91108

92109
var resId, resId2 string
93110
// Save TF content to Create resource with optional properties. This has to be exactly the same as the config part in the "create with optionals" step in the test.
94-
acctest.SaveConfigContent(config+compartmentIdVariableStr+DevopsTriggerResourceDependencies+
111+
acctest.SaveConfigContent(config+compartmentIdVariableStr+githubAccessTokenVaultIdStr+DevopsTriggerResourceDependencies+
95112
acctest.GenerateResourceFromRepresentationMap("oci_devops_trigger", "test_trigger", acctest.Optional, acctest.Create, DevopsTriggerRepresentation), "devops", "trigger", t)
96113

97114
acctest.ResourceTest(t, testAccCheckDevopsTriggerDestroy, []resource.TestStep{
98115
// verify Create
99116
{
100-
Config: config + compartmentIdVariableStr + DevopsTriggerResourceDependencies +
117+
Config: config + compartmentIdVariableStr + githubAccessTokenVaultIdStr + DevopsTriggerResourceDependencies +
101118
acctest.GenerateResourceFromRepresentationMap("oci_devops_trigger", "test_trigger", acctest.Required, acctest.Create, DevopsTriggerRepresentation),
102119
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
103120
resource.TestCheckResourceAttr(resourceName, "actions.#", "1"),
@@ -113,25 +130,27 @@ func TestDevopsTriggerResource_basic(t *testing.T) {
113130
),
114131
},
115132

116-
// delete before next Create
117-
{
118-
Config: config + compartmentIdVariableStr + DevopsTriggerResourceDependencies,
119-
},
120133
// verify Create with optionals
121134
{
122-
Config: config + compartmentIdVariableStr + DevopsTriggerResourceDependencies +
135+
Config: config + compartmentIdVariableStr + githubAccessTokenVaultIdStr + DevopsTriggerResourceDependencies +
123136
acctest.GenerateResourceFromRepresentationMap("oci_devops_trigger", "test_trigger", acctest.Optional, acctest.Create, DevopsTriggerRepresentation),
124137
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
125138
resource.TestCheckResourceAttr(resourceName, "actions.#", "1"),
126139
resource.TestCheckResourceAttrSet(resourceName, "actions.0.build_pipeline_id"),
127140
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.#", "1"),
128141
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.events.#", "1"),
142+
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.exclude.#", "1"),
143+
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.exclude.0.file_filter.#", "1"),
144+
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.exclude.0.file_filter.0.file_paths.#", "1"),
129145
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.include.#", "1"),
130146
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.include.0.base_ref", "baseRef"),
147+
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.include.0.file_filter.#", "1"),
148+
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.include.0.file_filter.0.file_paths.#", "1"),
131149
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.include.0.head_ref", "headRef"),
132150
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.trigger_source", "GITHUB"),
133151
resource.TestCheckResourceAttr(resourceName, "actions.0.type", "TRIGGER_BUILD_PIPELINE"),
134152
resource.TestCheckResourceAttrSet(resourceName, "compartment_id"),
153+
resource.TestCheckResourceAttrSet(resourceName, "connection_id"),
135154
resource.TestCheckResourceAttr(resourceName, "description", "description"),
136155
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
137156
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
@@ -154,19 +173,25 @@ func TestDevopsTriggerResource_basic(t *testing.T) {
154173

155174
// verify updates to updatable parameters
156175
{
157-
Config: config + compartmentIdVariableStr + DevopsTriggerResourceDependencies +
176+
Config: config + compartmentIdVariableStr + githubAccessTokenVaultIdStr + DevopsTriggerResourceDependencies +
158177
acctest.GenerateResourceFromRepresentationMap("oci_devops_trigger", "test_trigger", acctest.Optional, acctest.Update, DevopsTriggerRepresentation),
159178
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
160179
resource.TestCheckResourceAttr(resourceName, "actions.#", "1"),
161180
resource.TestCheckResourceAttrSet(resourceName, "actions.0.build_pipeline_id"),
162181
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.#", "1"),
163182
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.events.#", "1"),
183+
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.exclude.#", "1"),
184+
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.exclude.0.file_filter.#", "1"),
185+
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.exclude.0.file_filter.0.file_paths.#", "1"),
164186
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.include.#", "1"),
165187
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.include.0.base_ref", "baseRef2"),
188+
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.include.0.file_filter.#", "1"),
189+
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.include.0.file_filter.0.file_paths.#", "1"),
166190
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.include.0.head_ref", "headRef2"),
167191
resource.TestCheckResourceAttr(resourceName, "actions.0.filter.0.trigger_source", "GITHUB"),
168192
resource.TestCheckResourceAttr(resourceName, "actions.0.type", "TRIGGER_BUILD_PIPELINE"),
169193
resource.TestCheckResourceAttrSet(resourceName, "compartment_id"),
194+
resource.TestCheckResourceAttrSet(resourceName, "connection_id"),
170195
resource.TestCheckResourceAttr(resourceName, "description", "description2"),
171196
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
172197
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
@@ -188,7 +213,7 @@ func TestDevopsTriggerResource_basic(t *testing.T) {
188213
{
189214
Config: config +
190215
acctest.GenerateDataSourceFromRepresentationMap("oci_devops_triggers", "test_triggers", acctest.Optional, acctest.Update, DevopsDevopsTriggerDataSourceRepresentation) +
191-
compartmentIdVariableStr + DevopsTriggerResourceDependencies +
216+
compartmentIdVariableStr + githubAccessTokenVaultIdStr + DevopsTriggerResourceDependencies +
192217
acctest.GenerateResourceFromRepresentationMap("oci_devops_trigger", "test_trigger", acctest.Optional, acctest.Update, DevopsTriggerRepresentation),
193218
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
194219
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
@@ -201,15 +226,20 @@ func TestDevopsTriggerResource_basic(t *testing.T) {
201226
{
202227
Config: config +
203228
acctest.GenerateDataSourceFromRepresentationMap("oci_devops_trigger", "test_trigger", acctest.Required, acctest.Create, DevopsDevopsTriggerSingularDataSourceRepresentation) +
204-
compartmentIdVariableStr + DevopsTriggerResourceConfig,
229+
compartmentIdVariableStr + githubAccessTokenVaultIdStr + DevopsTriggerResourceConfig,
205230
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
206231
resource.TestCheckResourceAttrSet(singularDatasourceName, "trigger_id"),
207232

208233
resource.TestCheckResourceAttr(singularDatasourceName, "actions.#", "1"),
209234
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.#", "1"),
210235
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.0.events.#", "1"),
236+
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.0.exclude.#", "1"),
237+
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.0.exclude.0.file_filter.#", "1"),
238+
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.0.exclude.0.file_filter.0.file_paths.#", "1"),
211239
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.0.include.#", "1"),
212240
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.0.include.0.base_ref", "baseRef2"),
241+
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.0.include.0.file_filter.#", "1"),
242+
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.0.include.0.file_filter.0.file_paths.#", "1"),
213243
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.0.include.0.head_ref", "headRef2"),
214244
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.filter.0.trigger_source", "GITHUB"),
215245
resource.TestCheckResourceAttr(singularDatasourceName, "actions.0.type", "TRIGGER_BUILD_PIPELINE"),

0 commit comments

Comments
 (0)