Skip to content

Commit 436d8f4

Browse files
modular-magicianMario Machado
andauthored
Adds enterprise_config_resource_name field to cloudbuild trigger resource in order to support github enter… (#7236) (#5205)
* Adds enterprise_config_resource_name field to cloudbuild trigger resource in order to support github enterprise triggers * Fix newline at EOF --------- Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Mario Machado <[email protected]>
1 parent 003828c commit 436d8f4

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

.changelog/7236.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 `github.enterprise_config_resource_name` field to `google_cloudbuild_trigger` resource
3+
```

google-beta/resource_cloudbuild_trigger.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,12 @@ One of 'trigger_template', 'github', 'pubsub_config' or 'webhook_config' must be
856856
MaxItems: 1,
857857
Elem: &schema.Resource{
858858
Schema: map[string]*schema.Schema{
859+
"enterprise_config_resource_name": {
860+
Type: schema.TypeString,
861+
Optional: true,
862+
Description: `The resource name of the github enterprise config that should be applied to this installation.
863+
For example: "projects/{$projectId}/locations/{$locationId}/githubEnterpriseConfigs/{$configId}"`,
864+
},
859865
"name": {
860866
Type: schema.TypeString,
861867
Optional: true,
@@ -2083,6 +2089,8 @@ func flattenCloudBuildTriggerGithub(v interface{}, d *schema.ResourceData, confi
20832089
flattenCloudBuildTriggerGithubPullRequest(original["pullRequest"], d, config)
20842090
transformed["push"] =
20852091
flattenCloudBuildTriggerGithubPush(original["push"], d, config)
2092+
transformed["enterprise_config_resource_name"] =
2093+
flattenCloudBuildTriggerGithubEnterpriseConfigResourceName(original["enterpriseConfigResourceName"], d, config)
20862094
return []interface{}{transformed}
20872095
}
20882096
func flattenCloudBuildTriggerGithubOwner(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -2151,6 +2159,10 @@ func flattenCloudBuildTriggerGithubPushTag(v interface{}, d *schema.ResourceData
21512159
return v
21522160
}
21532161

2162+
func flattenCloudBuildTriggerGithubEnterpriseConfigResourceName(v interface{}, d *schema.ResourceData, config *Config) interface{} {
2163+
return v
2164+
}
2165+
21542166
func flattenCloudBuildTriggerBitbucketServerTriggerConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
21552167
if v == nil {
21562168
return nil
@@ -3255,6 +3267,13 @@ func expandCloudBuildTriggerGithub(v interface{}, d TerraformResourceData, confi
32553267
transformed["push"] = transformedPush
32563268
}
32573269

3270+
transformedEnterpriseConfigResourceName, err := expandCloudBuildTriggerGithubEnterpriseConfigResourceName(original["enterprise_config_resource_name"], d, config)
3271+
if err != nil {
3272+
return nil, err
3273+
} else if val := reflect.ValueOf(transformedEnterpriseConfigResourceName); val.IsValid() && !isEmptyValue(val) {
3274+
transformed["enterpriseConfigResourceName"] = transformedEnterpriseConfigResourceName
3275+
}
3276+
32583277
return transformed, nil
32593278
}
32603279

@@ -3356,6 +3375,10 @@ func expandCloudBuildTriggerGithubPushTag(v interface{}, d TerraformResourceData
33563375
return v, nil
33573376
}
33583377

3378+
func expandCloudBuildTriggerGithubEnterpriseConfigResourceName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
3379+
return v, nil
3380+
}
3381+
33593382
func expandCloudBuildTriggerBitbucketServerTriggerConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
33603383
l := v.([]interface{})
33613384
if len(l) == 0 || l[0] == nil {

website/docs/r/cloudbuild_trigger.html.markdown

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,26 @@ resource "google_cloudbuild_trigger" "bbs-pull-request-trigger" {
464464
filename = "cloudbuild.yaml"
465465
}
466466
```
467+
## Example Usage - Cloudbuild Trigger Github Enterprise
468+
469+
470+
```hcl
471+
resource "google_cloudbuild_trigger" "ghe-trigger" {
472+
name = "terraform-ghe-trigger"
473+
location = "us-central1"
474+
475+
github {
476+
owner = "hashicorp"
477+
name = "terraform-provider-google"
478+
push {
479+
branch = "^main$"
480+
}
481+
enterprise_config_resource_name = "projects/123456789/locations/us-central1/githubEnterpriseConfigs/configID"
482+
}
483+
484+
filename = "cloudbuild.yaml"
485+
}
486+
```
467487

468488
## Argument Reference
469489

@@ -774,6 +794,11 @@ The following arguments are supported:
774794
filter to match changes in refs, like branches or tags. Specify only one of `pull_request` or `push`.
775795
Structure is [documented below](#nested_push).
776796

797+
* `enterprise_config_resource_name` -
798+
(Optional)
799+
The resource name of the github enterprise config that should be applied to this installation.
800+
For example: "projects/{$projectId}/locations/{$locationId}/githubEnterpriseConfigs/{$configId}"
801+
777802

778803
<a name="nested_pull_request"></a>The `pull_request` block supports:
779804

0 commit comments

Comments
 (0)