From 307a8d58a764e2d70a86d5f408b9acc5a64615b1 Mon Sep 17 00:00:00 2001 From: Will Beebe Date: Fri, 18 Oct 2019 14:52:51 +0000 Subject: [PATCH] Adding "name" to Cloud Build resource Signed-off-by: Modular Magician --- google/resource_cloud_build_trigger.go | 27 +++++++++++++++++++ .../docs/r/cloudbuild_trigger.html.markdown | 4 +++ 2 files changed, 31 insertions(+) diff --git a/google/resource_cloud_build_trigger.go b/google/resource_cloud_build_trigger.go index 6b3d15d509f..ce8c9a72b82 100644 --- a/google/resource_cloud_build_trigger.go +++ b/google/resource_cloud_build_trigger.go @@ -170,6 +170,10 @@ func resourceCloudBuildTrigger() *schema.Resource { Type: schema.TypeString, }, }, + "name": { + Type: schema.TypeString, + Optional: true, + }, "substitutions": { Type: schema.TypeMap, Optional: true, @@ -232,6 +236,12 @@ func resourceCloudBuildTriggerCreate(d *schema.ResourceData, meta interface{}) e config := meta.(*Config) obj := make(map[string]interface{}) + nameProp, err := expandCloudBuildTriggerName(d.Get("name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } descriptionProp, err := expandCloudBuildTriggerDescription(d.Get("description"), d, config) if err != nil { return err @@ -347,6 +357,9 @@ func resourceCloudBuildTriggerRead(d *schema.ResourceData, meta interface{}) err if err := d.Set("trigger_id", flattenCloudBuildTriggerTriggerId(res["id"], d)); err != nil { return fmt.Errorf("Error reading Trigger: %s", err) } + if err := d.Set("name", flattenCloudBuildTriggerName(res["name"], d)); err != nil { + return fmt.Errorf("Error reading Trigger: %s", err) + } if err := d.Set("description", flattenCloudBuildTriggerDescription(res["description"], d)); err != nil { return fmt.Errorf("Error reading Trigger: %s", err) } @@ -387,6 +400,12 @@ func resourceCloudBuildTriggerUpdate(d *schema.ResourceData, meta interface{}) e } obj := make(map[string]interface{}) + nameProp, err := expandCloudBuildTriggerName(d.Get("name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } descriptionProp, err := expandCloudBuildTriggerDescription(d.Get("description"), d, config) if err != nil { return err @@ -501,6 +520,10 @@ func flattenCloudBuildTriggerTriggerId(v interface{}, d *schema.ResourceData) in return v } +func flattenCloudBuildTriggerName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + func flattenCloudBuildTriggerDescription(v interface{}, d *schema.ResourceData) interface{} { return v } @@ -696,6 +719,10 @@ func flattenCloudBuildTriggerBuildStepWaitFor(v interface{}, d *schema.ResourceD return v } +func expandCloudBuildTriggerName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandCloudBuildTriggerDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/website/docs/r/cloudbuild_trigger.html.markdown b/website/docs/r/cloudbuild_trigger.html.markdown index eb337078c20..4db78775aba 100644 --- a/website/docs/r/cloudbuild_trigger.html.markdown +++ b/website/docs/r/cloudbuild_trigger.html.markdown @@ -63,6 +63,10 @@ The following arguments are supported: - - - +* `name` - + (Optional) + Name of the trigger. Must be unique within the project. + * `description` - (Optional) Human-readable description of the trigger.