Skip to content

Commit

Permalink
Add cloudbuild invert regex option (#3628) (#6594)
Browse files Browse the repository at this point in the history
* Add cloudbuild invert regex option

* Fix invert_regex name in tf tests

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jun 15, 2020
1 parent 047d0e4 commit 6985704
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/3628.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudbuild: Added invert_regex flag in Github PullRequestFilter and PushFilter + in triggerTemplate
```
22 changes: 22 additions & 0 deletions google/resource_cloud_build_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ This must be a relative path. If a step's dir is specified and
is an absolute path, this value is ignored for that step's
execution.`,
},
"invert_regex": {
Type: schema.TypeBool,
Optional: true,
Description: `Only trigger a build if the revision regex does NOT match the revision regex.`,
},
"project_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -747,6 +752,8 @@ func flattenCloudBuildTriggerTriggerTemplate(v interface{}, d *schema.ResourceDa
flattenCloudBuildTriggerTriggerTemplateRepoName(original["repoName"], d, config)
transformed["dir"] =
flattenCloudBuildTriggerTriggerTemplateDir(original["dir"], d, config)
transformed["invert_regex"] =
flattenCloudBuildTriggerTriggerTemplateInvertRegex(original["invertRegex"], d, config)
transformed["branch_name"] =
flattenCloudBuildTriggerTriggerTemplateBranchName(original["branchName"], d, config)
transformed["tag_name"] =
Expand All @@ -767,6 +774,10 @@ func flattenCloudBuildTriggerTriggerTemplateDir(v interface{}, d *schema.Resourc
return v
}

func flattenCloudBuildTriggerTriggerTemplateInvertRegex(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenCloudBuildTriggerTriggerTemplateBranchName(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
Expand Down Expand Up @@ -970,6 +981,13 @@ func expandCloudBuildTriggerTriggerTemplate(v interface{}, d TerraformResourceDa
transformed["dir"] = transformedDir
}

transformedInvertRegex, err := expandCloudBuildTriggerTriggerTemplateInvertRegex(original["invert_regex"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedInvertRegex); val.IsValid() && !isEmptyValue(val) {
transformed["invertRegex"] = transformedInvertRegex
}

transformedBranchName, err := expandCloudBuildTriggerTriggerTemplateBranchName(original["branch_name"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1006,6 +1024,10 @@ func expandCloudBuildTriggerTriggerTemplateDir(v interface{}, d TerraformResourc
return v, nil
}

func expandCloudBuildTriggerTriggerTemplateInvertRegex(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandCloudBuildTriggerTriggerTemplateBranchName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down
2 changes: 2 additions & 0 deletions google/resource_cloudbuild_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ resource "google_cloudbuild_trigger" "build_trigger" {
trigger_template {
branch_name = "master"
repo_name = "some-repo"
invert_regex = false
}
build {
images = ["gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA"]
Expand Down Expand Up @@ -221,6 +222,7 @@ resource "google_cloudbuild_trigger" "build_trigger" {
trigger_template {
branch_name = "master-updated"
repo_name = "some-repo-updated"
invert_regex = true
}
build {
images = ["gcr.io/$PROJECT_ID/$REPO_NAME:$SHORT_SHA"]
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/cloudbuild_trigger.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ The `trigger_template` block supports:
is an absolute path, this value is ignored for that step's
execution.

* `invert_regex` -
(Optional)
Only trigger a build if the revision regex does NOT match the revision regex.

* `branch_name` -
(Optional)
Name of the branch to build. Exactly one a of branch name, tag, or commit SHA must be provided.
Expand Down

0 comments on commit 6985704

Please sign in to comment.