Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Add support for manual builds, git source for webhook/pubsub triggered builds and filter field #563

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions converters/google/resources/cloudbuild_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down