added ignored_files and included_files to google_cloudbuild_trigger (#2553)

This commit is contained in:
The Magician 2018-12-05 10:23:56 -08:00 committed by Nathan McKinley
parent eb843f67e0
commit 1bafe6b8e0
3 changed files with 37 additions and 0 deletions

View File

@ -87,6 +87,20 @@ func resourceCloudBuildTrigger() *schema.Resource {
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeString},
},
"included_files": &schema.Schema{
Optional: true,
Type: schema.TypeList,
MaxItems: 50,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"ignored_files": &schema.Schema{
Optional: true,
Type: schema.TypeList,
MaxItems: 50,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"trigger_template": &schema.Schema{
Optional: true,
Type: schema.TypeList,
@ -137,6 +151,9 @@ func resourceCloudbuildBuildTriggerCreate(d *schema.ResourceData, meta interface
return err
}
buildTrigger.IgnoredFiles = expandStringSlice(d, "ignored_files")
buildTrigger.IncludedFiles = expandStringSlice(d, "included_files")
tstr, err := json.Marshal(buildTrigger)
if err != nil {
return err
@ -168,6 +185,8 @@ func resourceCloudbuildBuildTriggerRead(d *schema.ResourceData, meta interface{}
d.Set("description", buildTrigger.Description)
d.Set("substitutions", buildTrigger.Substitutions)
d.Set("ignored_files", buildTrigger.IgnoredFiles)
d.Set("included_files", buildTrigger.IncludedFiles)
if buildTrigger.TriggerTemplate != nil {
d.Set("trigger_template", flattenCloudbuildBuildTriggerTemplate(d, config, buildTrigger.TriggerTemplate))

View File

@ -291,6 +291,19 @@ func expandEnvironmentVariables(d *schema.ResourceData) map[string]string {
return expandStringMap(d, "environment_variables")
}
// expandStringSlice pulls the value of key out of schema.ResourceData as a []string
func expandStringSlice(d *schema.ResourceData, key string) []string {
var strings []string
if interfaceStrings, ok := d.GetOk(key); ok {
for _, str := range interfaceStrings.([]interface{}) {
strings = append(strings, str.(string))
}
}
return strings
}
// expandStringMap pulls the value of key out of a schema.ResourceData as a map[string]string.
func expandStringMap(d *schema.ResourceData, key string) map[string]string {
v, ok := d.GetOk(key)

View File

@ -71,6 +71,11 @@ will be expanded when the build is created:
* `description` - (Optional) A brief description of this resource.
* `ignored_files` - (Optional) `ignored_files` and `included_files` are file glob matches using http://godoc/pkg/path/filepath#Match extended with support for "\*\*". If `ignored_files` and changed files are both empty, then they are not used to determine whether or not to trigger a build. If `ignored_files` is not empty, then we ignore any files that match any of the ignored_file globs. If the change has no files that are outside of the `ignored_files` globs, then
we do not trigger a build.
* `included_files` - (Optional) If any of the files altered in the commit pass the `ignored_files` filter and `included_files` is empty, then as far as this filter is concerned, we should trigger the build. If any of the files altered in the commit pass the `ignored_files` filter and `included_files` is not empty, then we make sure that at least one of those files matches a `included_files` glob. If not, then we do not trigger a build.
* `filename` - (Optional) Specify the path to a Cloud Build configuration file
in the Git repo. This is mutually exclusive with `build`. This is typically
`cloudbuild.yaml` however it can be specified by the user.