diff --git a/.changelog/7236.txt b/.changelog/7236.txt new file mode 100644 index 00000000000..341188fe474 --- /dev/null +++ b/.changelog/7236.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +cloudbuild: added `github.enterprise_config_resource_name` field to `google_cloudbuild_trigger` resource +``` diff --git a/google/resource_cloudbuild_trigger.go b/google/resource_cloudbuild_trigger.go index 155662de0a1..5531288b7f3 100644 --- a/google/resource_cloudbuild_trigger.go +++ b/google/resource_cloudbuild_trigger.go @@ -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, @@ -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{} { @@ -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 @@ -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 } @@ -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 { diff --git a/website/docs/r/cloudbuild_trigger.html.markdown b/website/docs/r/cloudbuild_trigger.html.markdown index 795b9307b18..a3f5dd5cf50 100644 --- a/website/docs/r/cloudbuild_trigger.html.markdown +++ b/website/docs/r/cloudbuild_trigger.html.markdown @@ -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 @@ -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}" + The `pull_request` block supports: