From 77f72591d96db8904d195993dad0fa7a3aeac30a Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Fri, 4 Mar 2022 17:39:58 +0000 Subject: [PATCH] Add support for manual builds, git source for webhook/pubsub triggered builds and filter field (#5738) * add filter support for cloudbuild * Add support for sourceToBuild and gitFileSource. Add examples for pubsub_config, webhook_config trigger and manual mode * Add support for sourceToBuild and gitFileSource. Add examples for pubsub_config, webhook_config trigger and manual mode * Fix description for field uri in sourceToBuild to be required Signed-off-by: Modular Magician --- .../google/resources/cloudbuild_trigger.go | 123 ++++++++++++++++++ go.mod | 2 +- go.sum | 4 +- 3 files changed, 126 insertions(+), 3 deletions(-) diff --git a/converters/google/resources/cloudbuild_trigger.go b/converters/google/resources/cloudbuild_trigger.go index 71eebd980..8f6a441c5 100644 --- a/converters/google/resources/cloudbuild_trigger.go +++ b/converters/google/resources/cloudbuild_trigger.go @@ -134,6 +134,24 @@ func GetCloudBuildTriggerApiObject(d TerraformResourceData, config *Config) (map } else if v, ok := d.GetOkExists("filename"); !isEmptyValue(reflect.ValueOf(filenameProp)) && (ok || !reflect.DeepEqual(v, filenameProp)) { obj["filename"] = filenameProp } + filterProp, err := expandCloudBuildTriggerFilter(d.Get("filter"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("filter"); !isEmptyValue(reflect.ValueOf(filterProp)) && (ok || !reflect.DeepEqual(v, filterProp)) { + obj["filter"] = filterProp + } + gitFileSourceProp, err := expandCloudBuildTriggerGitFileSource(d.Get("git_file_source"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("git_file_source"); !isEmptyValue(reflect.ValueOf(gitFileSourceProp)) && (ok || !reflect.DeepEqual(v, gitFileSourceProp)) { + obj["gitFileSource"] = gitFileSourceProp + } + sourceToBuildProp, err := expandCloudBuildTriggerSourceToBuild(d.Get("source_to_build"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("source_to_build"); !isEmptyValue(reflect.ValueOf(sourceToBuildProp)) && (ok || !reflect.DeepEqual(v, sourceToBuildProp)) { + obj["sourceToBuild"] = sourceToBuildProp + } ignoredFilesProp, err := expandCloudBuildTriggerIgnoredFiles(d.Get("ignored_files"), d, config) if err != nil { return nil, err @@ -215,6 +233,111 @@ func expandCloudBuildTriggerFilename(v interface{}, d TerraformResourceData, con return v, nil } +func expandCloudBuildTriggerFilter(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerGitFileSource(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedPath, err := expandCloudBuildTriggerGitFileSourcePath(original["path"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPath); val.IsValid() && !isEmptyValue(val) { + transformed["path"] = transformedPath + } + + transformedUri, err := expandCloudBuildTriggerGitFileSourceUri(original["uri"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUri); val.IsValid() && !isEmptyValue(val) { + transformed["uri"] = transformedUri + } + + transformedRepoType, err := expandCloudBuildTriggerGitFileSourceRepoType(original["repo_type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRepoType); val.IsValid() && !isEmptyValue(val) { + transformed["repoType"] = transformedRepoType + } + + transformedRevision, err := expandCloudBuildTriggerGitFileSourceRevision(original["revision"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRevision); val.IsValid() && !isEmptyValue(val) { + transformed["revision"] = transformedRevision + } + + return transformed, nil +} + +func expandCloudBuildTriggerGitFileSourcePath(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerGitFileSourceUri(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerGitFileSourceRepoType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerGitFileSourceRevision(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerSourceToBuild(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedUri, err := expandCloudBuildTriggerSourceToBuildUri(original["uri"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUri); val.IsValid() && !isEmptyValue(val) { + transformed["uri"] = transformedUri + } + + transformedRef, err := expandCloudBuildTriggerSourceToBuildRef(original["ref"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRef); val.IsValid() && !isEmptyValue(val) { + transformed["ref"] = transformedRef + } + + transformedRepoType, err := expandCloudBuildTriggerSourceToBuildRepoType(original["repo_type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRepoType); val.IsValid() && !isEmptyValue(val) { + transformed["repoType"] = transformedRepoType + } + + return transformed, nil +} + +func expandCloudBuildTriggerSourceToBuildUri(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerSourceToBuildRef(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerSourceToBuildRepoType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandCloudBuildTriggerIgnoredFiles(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/go.mod b/go.mod index 9fed2976d..a2f879d3c 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/terraform-json v0.13.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1 - github.com/hashicorp/terraform-provider-google v1.20.1-0.20220303202432-ed9ef83b1c15 + github.com/hashicorp/terraform-provider-google v1.20.1-0.20220304173527-51b2397eb08f github.com/kr/pretty v0.3.0 // indirect github.com/mitchellh/go-homedir v1.1.0 github.com/onsi/gomega v1.17.0 // indirect diff --git a/go.sum b/go.sum index 82e392f3d..d12ad99fa 100644 --- a/go.sum +++ b/go.sum @@ -691,8 +691,8 @@ github.com/hashicorp/terraform-plugin-log v0.2.0 h1:rjflRuBqCnSk3UHOR25MP1G5BDLK github.com/hashicorp/terraform-plugin-log v0.2.0/go.mod h1:E1kJmapEHzqu1x6M++gjvhzM2yMQNXPVWZRCB8sgYjg= github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1 h1:B9AocC+dxrCqcf4vVhztIkSkt3gpRjUkEka8AmZWGlQ= github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1/go.mod h1:FjM9DXWfP0w/AeOtJoSKHBZ01LqmaO6uP4bXhv3fekw= -github.com/hashicorp/terraform-provider-google v1.20.1-0.20220303202432-ed9ef83b1c15 h1:/UZeO2WtIcTpXcyg7uuLeWHiIlpU3gVtW7OEJ/nSE5M= -github.com/hashicorp/terraform-provider-google v1.20.1-0.20220303202432-ed9ef83b1c15/go.mod h1:9lU0yL549TyrGC2JPAX4xepNG3C61cNA5bOIXZq4oyk= +github.com/hashicorp/terraform-provider-google v1.20.1-0.20220304173527-51b2397eb08f h1:8hchd/TPlRE4XTiZiEZ2famBHq/rJ8TlinWWJG1sA4Y= +github.com/hashicorp/terraform-provider-google v1.20.1-0.20220304173527-51b2397eb08f/go.mod h1:9lU0yL549TyrGC2JPAX4xepNG3C61cNA5bOIXZq4oyk= github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 h1:1FGtlkJw87UsTMg5s8jrekrHmUPUJaMcu6ELiVhQrNw= github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896/go.mod h1:bzBPnUIkI0RxauU8Dqo+2KrZZ28Cf48s8V6IHt3p4co= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=