Skip to content

Commit

Permalink
Adds enterprise_config_resource_name field to cloudbuild trigger reso…
Browse files Browse the repository at this point in the history
…urce 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]>
  • Loading branch information
modular-magician and Mario Machado authored Feb 14, 2023
1 parent 3a405d7 commit b90bec5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/7236.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudbuild: added `github.enterprise_config_resource_name` field to `google_cloudbuild_trigger` resource
```
23 changes: 23 additions & 0 deletions google/resource_cloudbuild_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,12 @@ One of 'trigger_template', 'github', 'pubsub_config' or 'webhook_config' must be
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enterprise_config_resource_name": {
Type: schema.TypeString,
Optional: true,
Description: `The resource name of the github enterprise config that should be applied to this installation.
For example: "projects/{$projectId}/locations/{$locationId}/githubEnterpriseConfigs/{$configId}"`,
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1908,6 +1914,8 @@ func flattenCloudBuildTriggerGithub(v interface{}, d *schema.ResourceData, confi
flattenCloudBuildTriggerGithubPullRequest(original["pullRequest"], d, config)
transformed["push"] =
flattenCloudBuildTriggerGithubPush(original["push"], d, config)
transformed["enterprise_config_resource_name"] =
flattenCloudBuildTriggerGithubEnterpriseConfigResourceName(original["enterpriseConfigResourceName"], d, config)
return []interface{}{transformed}
}
func flattenCloudBuildTriggerGithubOwner(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down Expand Up @@ -1976,6 +1984,10 @@ func flattenCloudBuildTriggerGithubPushTag(v interface{}, d *schema.ResourceData
return v
}

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

func flattenCloudBuildTriggerBitbucketServerTriggerConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -2953,6 +2965,13 @@ func expandCloudBuildTriggerGithub(v interface{}, d TerraformResourceData, confi
transformed["push"] = transformedPush
}

transformedEnterpriseConfigResourceName, err := expandCloudBuildTriggerGithubEnterpriseConfigResourceName(original["enterprise_config_resource_name"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedEnterpriseConfigResourceName); val.IsValid() && !isEmptyValue(val) {
transformed["enterpriseConfigResourceName"] = transformedEnterpriseConfigResourceName
}

return transformed, nil
}

Expand Down Expand Up @@ -3054,6 +3073,10 @@ func expandCloudBuildTriggerGithubPushTag(v interface{}, d TerraformResourceData
return v, nil
}

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

func expandCloudBuildTriggerBitbucketServerTriggerConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
25 changes: 25 additions & 0 deletions website/docs/r/cloudbuild_trigger.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,26 @@ resource "google_cloudbuild_trigger" "bbs-pull-request-trigger" {
filename = "cloudbuild.yaml"
}
```
## Example Usage - Cloudbuild Trigger Github Enterprise


```hcl
resource "google_cloudbuild_trigger" "ghe-trigger" {
name = "terraform-ghe-trigger"
location = "us-central1"
github {
owner = "hashicorp"
name = "terraform-provider-google"
push {
branch = "^main$"
}
enterprise_config_resource_name = "projects/123456789/locations/us-central1/githubEnterpriseConfigs/configID"
}
filename = "cloudbuild.yaml"
}
```

## Argument Reference

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

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


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

Expand Down

1 comment on commit b90bec5

@kuba-vodafone
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyone knows when this change will be included in the release?

Please sign in to comment.