Skip to content

Commit b9f6caa

Browse files
modular-magicianMario Machado
and
Mario Machado
authored
Adds support for github enterprise configs inside git_file_source and source… (#6963) (#13518)
Co-authored-by: Mario Machado <[email protected]> Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Mario Machado <[email protected]>
1 parent 6f4ad9f commit b9f6caa

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

.changelog/6963.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
cloudbuild: added `github_enterprise_config` fields to `google_cloudbuild_trigger` resource.
3+
```

google/resource_cloudbuild_trigger.go

+46
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,12 @@ When using Pub/Sub, Webhook or Manual set the file name using git_file_source in
740740
ValidateFunc: validateEnum([]string{"UNKNOWN", "CLOUD_SOURCE_REPOSITORIES", "GITHUB", "BITBUCKET_SERVER"}),
741741
Description: `The type of the repo, since it may not be explicit from the repo field (e.g from a URL).
742742
Values can be UNKNOWN, CLOUD_SOURCE_REPOSITORIES, GITHUB, BITBUCKET_SERVER Possible values: ["UNKNOWN", "CLOUD_SOURCE_REPOSITORIES", "GITHUB", "BITBUCKET_SERVER"]`,
743+
},
744+
"github_enterprise_config": {
745+
Type: schema.TypeString,
746+
Optional: true,
747+
Description: `The full resource name of the github enterprise config.
748+
Format: projects/{project}/locations/{location}/githubEnterpriseConfigs/{id}. projects/{project}/githubEnterpriseConfigs/{id}.`,
743749
},
744750
"revision": {
745751
Type: schema.TypeString,
@@ -969,6 +975,12 @@ Values can be UNKNOWN, CLOUD_SOURCE_REPOSITORIES, GITHUB, BITBUCKET_SERVER Possi
969975
Required: true,
970976
Description: `The URI of the repo (required).`,
971977
},
978+
"github_enterprise_config": {
979+
Type: schema.TypeString,
980+
Optional: true,
981+
Description: `The full resource name of the github enterprise config.
982+
Format: projects/{project}/locations/{location}/githubEnterpriseConfigs/{id}. projects/{project}/githubEnterpriseConfigs/{id}.`,
983+
},
972984
},
973985
},
974986
AtLeastOneOf: []string{"trigger_template", "github", "pubsub_config", "webhook_config", "source_to_build"},
@@ -1661,6 +1673,8 @@ func flattenCloudBuildTriggerGitFileSource(v interface{}, d *schema.ResourceData
16611673
flattenCloudBuildTriggerGitFileSourceRepoType(original["repoType"], d, config)
16621674
transformed["revision"] =
16631675
flattenCloudBuildTriggerGitFileSourceRevision(original["revision"], d, config)
1676+
transformed["github_enterprise_config"] =
1677+
flattenCloudBuildTriggerGitFileSourceGithubEnterpriseConfig(original["githubEnterpriseConfig"], d, config)
16641678
return []interface{}{transformed}
16651679
}
16661680
func flattenCloudBuildTriggerGitFileSourcePath(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -1679,6 +1693,10 @@ func flattenCloudBuildTriggerGitFileSourceRevision(v interface{}, d *schema.Reso
16791693
return v
16801694
}
16811695

1696+
func flattenCloudBuildTriggerGitFileSourceGithubEnterpriseConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1697+
return v
1698+
}
1699+
16821700
func flattenCloudBuildTriggerSourceToBuild(v interface{}, d *schema.ResourceData, config *Config) interface{} {
16831701
if v == nil {
16841702
return nil
@@ -1694,6 +1712,8 @@ func flattenCloudBuildTriggerSourceToBuild(v interface{}, d *schema.ResourceData
16941712
flattenCloudBuildTriggerSourceToBuildRef(original["ref"], d, config)
16951713
transformed["repo_type"] =
16961714
flattenCloudBuildTriggerSourceToBuildRepoType(original["repoType"], d, config)
1715+
transformed["github_enterprise_config"] =
1716+
flattenCloudBuildTriggerSourceToBuildGithubEnterpriseConfig(original["githubEnterpriseConfig"], d, config)
16971717
return []interface{}{transformed}
16981718
}
16991719
func flattenCloudBuildTriggerSourceToBuildUri(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -1708,6 +1728,10 @@ func flattenCloudBuildTriggerSourceToBuildRepoType(v interface{}, d *schema.Reso
17081728
return v
17091729
}
17101730

1731+
func flattenCloudBuildTriggerSourceToBuildGithubEnterpriseConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1732+
return v
1733+
}
1734+
17111735
func flattenCloudBuildTriggerIgnoredFiles(v interface{}, d *schema.ResourceData, config *Config) interface{} {
17121736
return v
17131737
}
@@ -2520,6 +2544,13 @@ func expandCloudBuildTriggerGitFileSource(v interface{}, d TerraformResourceData
25202544
transformed["revision"] = transformedRevision
25212545
}
25222546

2547+
transformedGithubEnterpriseConfig, err := expandCloudBuildTriggerGitFileSourceGithubEnterpriseConfig(original["github_enterprise_config"], d, config)
2548+
if err != nil {
2549+
return nil, err
2550+
} else if val := reflect.ValueOf(transformedGithubEnterpriseConfig); val.IsValid() && !isEmptyValue(val) {
2551+
transformed["githubEnterpriseConfig"] = transformedGithubEnterpriseConfig
2552+
}
2553+
25232554
return transformed, nil
25242555
}
25252556

@@ -2539,6 +2570,10 @@ func expandCloudBuildTriggerGitFileSourceRevision(v interface{}, d TerraformReso
25392570
return v, nil
25402571
}
25412572

2573+
func expandCloudBuildTriggerGitFileSourceGithubEnterpriseConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2574+
return v, nil
2575+
}
2576+
25422577
func expandCloudBuildTriggerSourceToBuild(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
25432578
l := v.([]interface{})
25442579
if len(l) == 0 || l[0] == nil {
@@ -2569,6 +2604,13 @@ func expandCloudBuildTriggerSourceToBuild(v interface{}, d TerraformResourceData
25692604
transformed["repoType"] = transformedRepoType
25702605
}
25712606

2607+
transformedGithubEnterpriseConfig, err := expandCloudBuildTriggerSourceToBuildGithubEnterpriseConfig(original["github_enterprise_config"], d, config)
2608+
if err != nil {
2609+
return nil, err
2610+
} else if val := reflect.ValueOf(transformedGithubEnterpriseConfig); val.IsValid() && !isEmptyValue(val) {
2611+
transformed["githubEnterpriseConfig"] = transformedGithubEnterpriseConfig
2612+
}
2613+
25722614
return transformed, nil
25732615
}
25742616

@@ -2584,6 +2626,10 @@ func expandCloudBuildTriggerSourceToBuildRepoType(v interface{}, d TerraformReso
25842626
return v, nil
25852627
}
25862628

2629+
func expandCloudBuildTriggerSourceToBuildGithubEnterpriseConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
2630+
return v, nil
2631+
}
2632+
25872633
func expandCloudBuildTriggerIgnoredFiles(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
25882634
return v, nil
25892635
}

website/docs/r/cloudbuild_trigger.html.markdown

+33
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,29 @@ resource "google_cloudbuild_trigger" "manual-trigger" {
346346
347347
}
348348
```
349+
## Example Usage - Cloudbuild Trigger Manual Github Enterprise
350+
351+
352+
```hcl
353+
resource "google_cloudbuild_trigger" "manual-ghe-trigger" {
354+
name = "terraform-manual-ghe-trigger"
355+
356+
source_to_build {
357+
uri = "https://hashicorp/terraform-provider-google-beta"
358+
ref = "refs/heads/main"
359+
repo_type = "GITHUB"
360+
github_enterprise_config = "projects/myProject/locations/global/githubEnterpriseConfigs/configID"
361+
}
362+
363+
git_file_source {
364+
path = "cloudbuild.yaml"
365+
uri = "https://hashicorp/terraform-provider-google-beta"
366+
revision = "refs/heads/main"
367+
repo_type = "GITHUB"
368+
github_enterprise_config = "projects/myProject/locations/global/githubEnterpriseConfigs/configID"
369+
}
370+
}
371+
```
349372

350373
## Argument Reference
351374

@@ -510,6 +533,11 @@ The following arguments are supported:
510533
filename (optional). This field respects the same syntax/resolution as described here: https://git-scm.com/docs/gitrevisions
511534
If unspecified, the revision from which the trigger invocation originated is assumed to be the revision from which to read the specified path.
512535

536+
* `github_enterprise_config` -
537+
(Optional)
538+
The full resource name of the github enterprise config.
539+
Format: projects/{project}/locations/{location}/githubEnterpriseConfigs/{id}. projects/{project}/githubEnterpriseConfigs/{id}.
540+
513541
<a name="nested_source_to_build"></a>The `source_to_build` block supports:
514542

515543
* `uri` -
@@ -526,6 +554,11 @@ The following arguments are supported:
526554
Values can be UNKNOWN, CLOUD_SOURCE_REPOSITORIES, GITHUB, BITBUCKET_SERVER
527555
Possible values are `UNKNOWN`, `CLOUD_SOURCE_REPOSITORIES`, `GITHUB`, and `BITBUCKET_SERVER`.
528556

557+
* `github_enterprise_config` -
558+
(Optional)
559+
The full resource name of the github enterprise config.
560+
Format: projects/{project}/locations/{location}/githubEnterpriseConfigs/{id}. projects/{project}/githubEnterpriseConfigs/{id}.
561+
529562
<a name="nested_trigger_template"></a>The `trigger_template` block supports:
530563

531564
* `project_id` -

0 commit comments

Comments
 (0)