Skip to content

Commit 4a72126

Browse files
Add repository_event_config field to google_cloudbuild_trigger (beta) (#7183) (#5142)
Signed-off-by: Modular Magician <[email protected]>
1 parent 5d2170f commit 4a72126

File tree

4 files changed

+476
-5
lines changed

4 files changed

+476
-5
lines changed

.changelog/7183.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
cloudbuild: added field `repository_event_config` to resource `trigger` (beta)
3+
```

google-beta/resource_cloudbuild_trigger.go

Lines changed: 307 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ https://github.com/googlecloudplatform/cloud-builders is "googlecloudplatform".`
842842
},
843843
},
844844
},
845-
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build"},
845+
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build", "repository_event_config"},
846846
},
847847
"ignored_files": {
848848
Type: schema.TypeList,
@@ -933,7 +933,88 @@ Only populated on get requests.`,
933933
},
934934
},
935935
},
936-
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build"},
936+
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build", "repository_event_config"},
937+
},
938+
"repository_event_config": {
939+
Type: schema.TypeList,
940+
Optional: true,
941+
Description: `The configuration of a trigger that creates a build whenever an event from Repo API is received.`,
942+
MaxItems: 1,
943+
Elem: &schema.Resource{
944+
Schema: map[string]*schema.Schema{
945+
"pull_request": {
946+
Type: schema.TypeList,
947+
Optional: true,
948+
Description: `Contains filter properties for matching Pull Requests.`,
949+
MaxItems: 1,
950+
Elem: &schema.Resource{
951+
Schema: map[string]*schema.Schema{
952+
"branch": {
953+
Type: schema.TypeString,
954+
Optional: true,
955+
Description: `Regex of branches to match.
956+
957+
The syntax of the regular expressions accepted is the syntax accepted by
958+
RE2 and described at https://github.com/google/re2/wiki/Syntax`,
959+
ExactlyOneOf: []string{},
960+
},
961+
"comment_control": {
962+
Type: schema.TypeString,
963+
Optional: true,
964+
ValidateFunc: validateEnum([]string{"COMMENTS_DISABLED", "COMMENTS_ENABLED", "COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY", ""}),
965+
Description: `Configure builds to run whether a repository owner or collaborator need to comment '/gcbrun'. Possible values: ["COMMENTS_DISABLED", "COMMENTS_ENABLED", "COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY"]`,
966+
},
967+
"invert_regex": {
968+
Type: schema.TypeBool,
969+
Optional: true,
970+
Description: `If true, branches that do NOT match the git_ref will trigger a build.`,
971+
},
972+
},
973+
},
974+
ExactlyOneOf: []string{},
975+
},
976+
"push": {
977+
Type: schema.TypeList,
978+
Optional: true,
979+
Description: `Contains filter properties for matching git pushes.`,
980+
MaxItems: 1,
981+
Elem: &schema.Resource{
982+
Schema: map[string]*schema.Schema{
983+
"branch": {
984+
Type: schema.TypeString,
985+
Optional: true,
986+
Description: `Regex of branches to match.
987+
988+
The syntax of the regular expressions accepted is the syntax accepted by
989+
RE2 and described at https://github.com/google/re2/wiki/Syntax`,
990+
ExactlyOneOf: []string{},
991+
},
992+
"invert_regex": {
993+
Type: schema.TypeBool,
994+
Optional: true,
995+
Description: `If true, only trigger a build if the revision regex does NOT match the git_ref regex.`,
996+
},
997+
"tag": {
998+
Type: schema.TypeString,
999+
Optional: true,
1000+
Description: `Regex of tags to match.
1001+
1002+
The syntax of the regular expressions accepted is the syntax accepted by
1003+
RE2 and described at https://github.com/google/re2/wiki/Syntax`,
1004+
ExactlyOneOf: []string{},
1005+
},
1006+
},
1007+
},
1008+
ExactlyOneOf: []string{},
1009+
},
1010+
"repository": {
1011+
Type: schema.TypeString,
1012+
Optional: true,
1013+
Description: `The resource name of the Repo API resource.`,
1014+
},
1015+
},
1016+
},
1017+
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build", "repository_event_config"},
9371018
},
9381019
"service_account": {
9391020
Type: schema.TypeString,
@@ -983,7 +1064,7 @@ Format: projects/{project}/locations/{location}/githubEnterpriseConfigs/{id}. pr
9831064
},
9841065
},
9851066
},
986-
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build"},
1067+
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build", "repository_event_config"},
9871068
},
9881069
"substitutions": {
9891070
Type: schema.TypeMap,
@@ -1061,7 +1142,7 @@ This field is a regular expression.`,
10611142
},
10621143
},
10631144
},
1064-
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build"},
1145+
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build", "repository_event_config"},
10651146
},
10661147
"webhook_config": {
10671148
Type: schema.TypeList,
@@ -1086,7 +1167,7 @@ Only populated on get requests.`,
10861167
},
10871168
},
10881169
},
1089-
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build"},
1170+
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build", "repository_event_config"},
10901171
},
10911172
"create_time": {
10921173
Type: schema.TypeString,
@@ -1177,6 +1258,12 @@ func resourceCloudBuildTriggerCreate(d *schema.ResourceData, meta interface{}) e
11771258
} else if v, ok := d.GetOkExists("git_file_source"); !isEmptyValue(reflect.ValueOf(gitFileSourceProp)) && (ok || !reflect.DeepEqual(v, gitFileSourceProp)) {
11781259
obj["gitFileSource"] = gitFileSourceProp
11791260
}
1261+
repositoryEventConfigProp, err := expandCloudBuildTriggerRepositoryEventConfig(d.Get("repository_event_config"), d, config)
1262+
if err != nil {
1263+
return err
1264+
} else if v, ok := d.GetOkExists("repository_event_config"); !isEmptyValue(reflect.ValueOf(repositoryEventConfigProp)) && (ok || !reflect.DeepEqual(v, repositoryEventConfigProp)) {
1265+
obj["repositoryEventConfig"] = repositoryEventConfigProp
1266+
}
11801267
sourceToBuildProp, err := expandCloudBuildTriggerSourceToBuild(d.Get("source_to_build"), d, config)
11811268
if err != nil {
11821269
return err
@@ -1359,6 +1446,9 @@ func resourceCloudBuildTriggerRead(d *schema.ResourceData, meta interface{}) err
13591446
if err := d.Set("git_file_source", flattenCloudBuildTriggerGitFileSource(res["gitFileSource"], d, config)); err != nil {
13601447
return fmt.Errorf("Error reading Trigger: %s", err)
13611448
}
1449+
if err := d.Set("repository_event_config", flattenCloudBuildTriggerRepositoryEventConfig(res["repositoryEventConfig"], d, config)); err != nil {
1450+
return fmt.Errorf("Error reading Trigger: %s", err)
1451+
}
13621452
if err := d.Set("source_to_build", flattenCloudBuildTriggerSourceToBuild(res["sourceToBuild"], d, config)); err != nil {
13631453
return fmt.Errorf("Error reading Trigger: %s", err)
13641454
}
@@ -1466,6 +1556,12 @@ func resourceCloudBuildTriggerUpdate(d *schema.ResourceData, meta interface{}) e
14661556
} else if v, ok := d.GetOkExists("git_file_source"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, gitFileSourceProp)) {
14671557
obj["gitFileSource"] = gitFileSourceProp
14681558
}
1559+
repositoryEventConfigProp, err := expandCloudBuildTriggerRepositoryEventConfig(d.Get("repository_event_config"), d, config)
1560+
if err != nil {
1561+
return err
1562+
} else if v, ok := d.GetOkExists("repository_event_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, repositoryEventConfigProp)) {
1563+
obj["repositoryEventConfig"] = repositoryEventConfigProp
1564+
}
14691565
sourceToBuildProp, err := expandCloudBuildTriggerSourceToBuild(d.Get("source_to_build"), d, config)
14701566
if err != nil {
14711567
return err
@@ -1697,6 +1793,85 @@ func flattenCloudBuildTriggerGitFileSourceGithubEnterpriseConfig(v interface{},
16971793
return v
16981794
}
16991795

1796+
func flattenCloudBuildTriggerRepositoryEventConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1797+
if v == nil {
1798+
return nil
1799+
}
1800+
original := v.(map[string]interface{})
1801+
if len(original) == 0 {
1802+
return nil
1803+
}
1804+
transformed := make(map[string]interface{})
1805+
transformed["repository"] =
1806+
flattenCloudBuildTriggerRepositoryEventConfigRepository(original["repository"], d, config)
1807+
transformed["pull_request"] =
1808+
flattenCloudBuildTriggerRepositoryEventConfigPullRequest(original["pullRequest"], d, config)
1809+
transformed["push"] =
1810+
flattenCloudBuildTriggerRepositoryEventConfigPush(original["push"], d, config)
1811+
return []interface{}{transformed}
1812+
}
1813+
func flattenCloudBuildTriggerRepositoryEventConfigRepository(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1814+
return v
1815+
}
1816+
1817+
func flattenCloudBuildTriggerRepositoryEventConfigPullRequest(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1818+
if v == nil {
1819+
return nil
1820+
}
1821+
original := v.(map[string]interface{})
1822+
if len(original) == 0 {
1823+
return nil
1824+
}
1825+
transformed := make(map[string]interface{})
1826+
transformed["branch"] =
1827+
flattenCloudBuildTriggerRepositoryEventConfigPullRequestBranch(original["branch"], d, config)
1828+
transformed["invert_regex"] =
1829+
flattenCloudBuildTriggerRepositoryEventConfigPullRequestInvertRegex(original["invertRegex"], d, config)
1830+
transformed["comment_control"] =
1831+
flattenCloudBuildTriggerRepositoryEventConfigPullRequestCommentControl(original["commentControl"], d, config)
1832+
return []interface{}{transformed}
1833+
}
1834+
func flattenCloudBuildTriggerRepositoryEventConfigPullRequestBranch(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1835+
return v
1836+
}
1837+
1838+
func flattenCloudBuildTriggerRepositoryEventConfigPullRequestInvertRegex(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1839+
return v
1840+
}
1841+
1842+
func flattenCloudBuildTriggerRepositoryEventConfigPullRequestCommentControl(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1843+
return v
1844+
}
1845+
1846+
func flattenCloudBuildTriggerRepositoryEventConfigPush(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1847+
if v == nil {
1848+
return nil
1849+
}
1850+
original := v.(map[string]interface{})
1851+
if len(original) == 0 {
1852+
return nil
1853+
}
1854+
transformed := make(map[string]interface{})
1855+
transformed["branch"] =
1856+
flattenCloudBuildTriggerRepositoryEventConfigPushBranch(original["branch"], d, config)
1857+
transformed["tag"] =
1858+
flattenCloudBuildTriggerRepositoryEventConfigPushTag(original["tag"], d, config)
1859+
transformed["invert_regex"] =
1860+
flattenCloudBuildTriggerRepositoryEventConfigPushInvertRegex(original["invertRegex"], d, config)
1861+
return []interface{}{transformed}
1862+
}
1863+
func flattenCloudBuildTriggerRepositoryEventConfigPushBranch(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1864+
return v
1865+
}
1866+
1867+
func flattenCloudBuildTriggerRepositoryEventConfigPushTag(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1868+
return v
1869+
}
1870+
1871+
func flattenCloudBuildTriggerRepositoryEventConfigPushInvertRegex(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1872+
return v
1873+
}
1874+
17001875
func flattenCloudBuildTriggerSourceToBuild(v interface{}, d *schema.ResourceData, config *Config) interface{} {
17011876
if v == nil {
17021877
return nil
@@ -2574,6 +2749,133 @@ func expandCloudBuildTriggerGitFileSourceGithubEnterpriseConfig(v interface{}, d
25742749
return v, nil
25752750
}
25762751

2752+
func expandCloudBuildTriggerRepositoryEventConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2753+
l := v.([]interface{})
2754+
if len(l) == 0 || l[0] == nil {
2755+
return nil, nil
2756+
}
2757+
raw := l[0]
2758+
original := raw.(map[string]interface{})
2759+
transformed := make(map[string]interface{})
2760+
2761+
transformedRepository, err := expandCloudBuildTriggerRepositoryEventConfigRepository(original["repository"], d, config)
2762+
if err != nil {
2763+
return nil, err
2764+
} else if val := reflect.ValueOf(transformedRepository); val.IsValid() && !isEmptyValue(val) {
2765+
transformed["repository"] = transformedRepository
2766+
}
2767+
2768+
transformedPullRequest, err := expandCloudBuildTriggerRepositoryEventConfigPullRequest(original["pull_request"], d, config)
2769+
if err != nil {
2770+
return nil, err
2771+
} else if val := reflect.ValueOf(transformedPullRequest); val.IsValid() && !isEmptyValue(val) {
2772+
transformed["pullRequest"] = transformedPullRequest
2773+
}
2774+
2775+
transformedPush, err := expandCloudBuildTriggerRepositoryEventConfigPush(original["push"], d, config)
2776+
if err != nil {
2777+
return nil, err
2778+
} else if val := reflect.ValueOf(transformedPush); val.IsValid() && !isEmptyValue(val) {
2779+
transformed["push"] = transformedPush
2780+
}
2781+
2782+
return transformed, nil
2783+
}
2784+
2785+
func expandCloudBuildTriggerRepositoryEventConfigRepository(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2786+
return v, nil
2787+
}
2788+
2789+
func expandCloudBuildTriggerRepositoryEventConfigPullRequest(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2790+
l := v.([]interface{})
2791+
if len(l) == 0 || l[0] == nil {
2792+
return nil, nil
2793+
}
2794+
raw := l[0]
2795+
original := raw.(map[string]interface{})
2796+
transformed := make(map[string]interface{})
2797+
2798+
transformedBranch, err := expandCloudBuildTriggerRepositoryEventConfigPullRequestBranch(original["branch"], d, config)
2799+
if err != nil {
2800+
return nil, err
2801+
} else if val := reflect.ValueOf(transformedBranch); val.IsValid() && !isEmptyValue(val) {
2802+
transformed["branch"] = transformedBranch
2803+
}
2804+
2805+
transformedInvertRegex, err := expandCloudBuildTriggerRepositoryEventConfigPullRequestInvertRegex(original["invert_regex"], d, config)
2806+
if err != nil {
2807+
return nil, err
2808+
} else if val := reflect.ValueOf(transformedInvertRegex); val.IsValid() && !isEmptyValue(val) {
2809+
transformed["invertRegex"] = transformedInvertRegex
2810+
}
2811+
2812+
transformedCommentControl, err := expandCloudBuildTriggerRepositoryEventConfigPullRequestCommentControl(original["comment_control"], d, config)
2813+
if err != nil {
2814+
return nil, err
2815+
} else if val := reflect.ValueOf(transformedCommentControl); val.IsValid() && !isEmptyValue(val) {
2816+
transformed["commentControl"] = transformedCommentControl
2817+
}
2818+
2819+
return transformed, nil
2820+
}
2821+
2822+
func expandCloudBuildTriggerRepositoryEventConfigPullRequestBranch(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2823+
return v, nil
2824+
}
2825+
2826+
func expandCloudBuildTriggerRepositoryEventConfigPullRequestInvertRegex(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2827+
return v, nil
2828+
}
2829+
2830+
func expandCloudBuildTriggerRepositoryEventConfigPullRequestCommentControl(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2831+
return v, nil
2832+
}
2833+
2834+
func expandCloudBuildTriggerRepositoryEventConfigPush(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2835+
l := v.([]interface{})
2836+
if len(l) == 0 || l[0] == nil {
2837+
return nil, nil
2838+
}
2839+
raw := l[0]
2840+
original := raw.(map[string]interface{})
2841+
transformed := make(map[string]interface{})
2842+
2843+
transformedBranch, err := expandCloudBuildTriggerRepositoryEventConfigPushBranch(original["branch"], d, config)
2844+
if err != nil {
2845+
return nil, err
2846+
} else if val := reflect.ValueOf(transformedBranch); val.IsValid() && !isEmptyValue(val) {
2847+
transformed["branch"] = transformedBranch
2848+
}
2849+
2850+
transformedTag, err := expandCloudBuildTriggerRepositoryEventConfigPushTag(original["tag"], d, config)
2851+
if err != nil {
2852+
return nil, err
2853+
} else if val := reflect.ValueOf(transformedTag); val.IsValid() && !isEmptyValue(val) {
2854+
transformed["tag"] = transformedTag
2855+
}
2856+
2857+
transformedInvertRegex, err := expandCloudBuildTriggerRepositoryEventConfigPushInvertRegex(original["invert_regex"], d, config)
2858+
if err != nil {
2859+
return nil, err
2860+
} else if val := reflect.ValueOf(transformedInvertRegex); val.IsValid() && !isEmptyValue(val) {
2861+
transformed["invertRegex"] = transformedInvertRegex
2862+
}
2863+
2864+
return transformed, nil
2865+
}
2866+
2867+
func expandCloudBuildTriggerRepositoryEventConfigPushBranch(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2868+
return v, nil
2869+
}
2870+
2871+
func expandCloudBuildTriggerRepositoryEventConfigPushTag(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2872+
return v, nil
2873+
}
2874+
2875+
func expandCloudBuildTriggerRepositoryEventConfigPushInvertRegex(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2876+
return v, nil
2877+
}
2878+
25772879
func expandCloudBuildTriggerSourceToBuild(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
25782880
l := v.([]interface{})
25792881
if len(l) == 0 || l[0] == nil {

0 commit comments

Comments
 (0)