Skip to content

Commit b90bec5

Browse files
modular-magicianMario Machado
and
Mario Machado
authored
Adds enterprise_config_resource_name field to cloudbuild trigger resource in order to support github enter… (#7236) (#13739)
* 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 3a405d7 commit b90bec5

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

.changelog/7236.txt

+3
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/resource_cloudbuild_trigger.go

+23
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,
@@ -1908,6 +1914,8 @@ func flattenCloudBuildTriggerGithub(v interface{}, d *schema.ResourceData, confi
19081914
flattenCloudBuildTriggerGithubPullRequest(original["pullRequest"], d, config)
19091915
transformed["push"] =
19101916
flattenCloudBuildTriggerGithubPush(original["push"], d, config)
1917+
transformed["enterprise_config_resource_name"] =
1918+
flattenCloudBuildTriggerGithubEnterpriseConfigResourceName(original["enterpriseConfigResourceName"], d, config)
19111919
return []interface{}{transformed}
19121920
}
19131921
func flattenCloudBuildTriggerGithubOwner(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -1976,6 +1984,10 @@ func flattenCloudBuildTriggerGithubPushTag(v interface{}, d *schema.ResourceData
19761984
return v
19771985
}
19781986

1987+
func flattenCloudBuildTriggerGithubEnterpriseConfigResourceName(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1988+
return v
1989+
}
1990+
19791991
func flattenCloudBuildTriggerBitbucketServerTriggerConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
19801992
if v == nil {
19811993
return nil
@@ -2953,6 +2965,13 @@ func expandCloudBuildTriggerGithub(v interface{}, d TerraformResourceData, confi
29532965
transformed["push"] = transformedPush
29542966
}
29552967

2968+
transformedEnterpriseConfigResourceName, err := expandCloudBuildTriggerGithubEnterpriseConfigResourceName(original["enterprise_config_resource_name"], d, config)
2969+
if err != nil {
2970+
return nil, err
2971+
} else if val := reflect.ValueOf(transformedEnterpriseConfigResourceName); val.IsValid() && !isEmptyValue(val) {
2972+
transformed["enterpriseConfigResourceName"] = transformedEnterpriseConfigResourceName
2973+
}
2974+
29562975
return transformed, nil
29572976
}
29582977

@@ -3054,6 +3073,10 @@ func expandCloudBuildTriggerGithubPushTag(v interface{}, d TerraformResourceData
30543073
return v, nil
30553074
}
30563075

3076+
func expandCloudBuildTriggerGithubEnterpriseConfigResourceName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
3077+
return v, nil
3078+
}
3079+
30573080
func expandCloudBuildTriggerBitbucketServerTriggerConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
30583081
l := v.([]interface{})
30593082
if len(l) == 0 || l[0] == nil {

website/docs/r/cloudbuild_trigger.html.markdown

+25
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)