From a72a8600a4456ce93a2553a7e9fede50888fbe6c Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Fri, 30 Apr 2021 08:09:44 +0000 Subject: [PATCH] Rename xrole and app arguments for fgs It's a bit confused that app means package in terrafrom and agency means xrole --- docs/resources/fgs_function.md | 7 +- .../resource_huaweicloud_fgs_function_v2.go | 67 ++++++++++++++++--- ...source_huaweicloud_fgs_function_v2_test.go | 2 +- 3 files changed, 62 insertions(+), 14 deletions(-) diff --git a/docs/resources/fgs_function.md b/docs/resources/fgs_function.md index 1fd949d11a..45e7836774 100644 --- a/docs/resources/fgs_function.md +++ b/docs/resources/fgs_function.md @@ -12,7 +12,8 @@ This is an alternative to `huaweicloud_fgs_function_v2` ```hcl resource "huaweicloud_fgs_function" "f_1" { name = "func_1" - package = "default" + app = "default" + agency = "test" description = "fuction test" handler = "test.handler" memory_size = 128 @@ -31,7 +32,7 @@ The following arguments are supported: * `name` - (Required, String, ForceNew) A unique name for the function. Changing this creates a new function. -* `package` - (Required, String) Group to which the function belongs. Changing this creates a new function. +* `app` - (Required, String) Group to which the function belongs. Changing this creates a new function. * `code_type` - (Required, String, ForceNew) Function code type, which can be inline: inline code, zip: ZIP file, jar: JAR file or java functions, obs: function code stored in an OBS bucket. Changing this @@ -55,7 +56,7 @@ The following arguments are supported: * `user_data` - (Optional, String, ForceNew) Key/Value information defined for the function. Changing this creates a new function. -* `xrole` - (Optional, String, ForceNew) This parameter is mandatory if the function needs to access other cloud services. +* `agency` - (Optional, String, ForceNew) This parameter is mandatory if the function needs to access other cloud services. Changing this creates a new function. * `func_code` - (Required, String, ForceNew) Function code. When code_type is set to inline, zip, or jar, this parameter is mandatory, diff --git a/huaweicloud/resource_huaweicloud_fgs_function_v2.go b/huaweicloud/resource_huaweicloud_fgs_function_v2.go index 2463231c3e..d9ec437940 100644 --- a/huaweicloud/resource_huaweicloud_fgs_function_v2.go +++ b/huaweicloud/resource_huaweicloud_fgs_function_v2.go @@ -43,9 +43,17 @@ func resourceFgsFunctionV2() *schema.Resource { ForceNew: true, }, "package": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"app"}, + Deprecated: "use app instead", + }, + "app": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"package"}, }, "code_type": { Type: schema.TypeString, @@ -89,9 +97,17 @@ func resourceFgsFunctionV2() *schema.Resource { ForceNew: true, }, "xrole": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"agency"}, + Deprecated: "use agency instead", + }, + "agency": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"xrole"}, }, "func_code": { Type: schema.TypeString, @@ -109,13 +125,34 @@ func resourceFgsFunctionV2Create(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error creating HuaweiCloud FGS V2 client: %s", err) } + // check app and package + app, app_ok := d.GetOk("app") + pak, pak_ok := d.GetOk("package") + if !app_ok && !pak_ok { + return fmt.Errorf("One of app or package must be configured") + } + pack_v := "" + if app_ok { + pack_v = app.(string) + } else { + pack_v = pak.(string) + } + + // get value from agency or xrole + agency_v := "" + if v, ok := d.GetOk("agency"); ok { + agency_v = v.(string) + } else if v, ok := d.GetOk("xrole"); ok { + agency_v = v.(string) + } + func_code := function.FunctionCodeOpts{ File: d.Get("func_code").(string), } createOpts := function.CreateOpts{ FuncName: d.Get("name").(string), - Package: d.Get("package").(string), + Package: pack_v, CodeType: d.Get("code_type").(string), CodeUrl: d.Get("code_url").(string), Description: d.Get("description").(string), @@ -125,7 +162,7 @@ func resourceFgsFunctionV2Create(d *schema.ResourceData, meta interface{}) error Runtime: d.Get("runtime").(string), Timeout: d.Get("timeout").(int), UserData: d.Get("user_data").(string), - Xrole: d.Get("xrole").(string), + Xrole: agency_v, FuncCode: func_code, } @@ -155,7 +192,6 @@ func resourceFgsFunctionV2Read(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Retrieved Function %s: %+v", d.Id(), f) d.Set("name", f.FuncName) - d.Set("package", f.Package) d.Set("code_type", f.CodeType) d.Set("code_url", f.CodeUrl) d.Set("description", f.Description) @@ -165,7 +201,18 @@ func resourceFgsFunctionV2Read(d *schema.ResourceData, meta interface{}) error { d.Set("runtime", f.Runtime) d.Set("timeout", f.Timeout) d.Set("user_data", f.UserData) - d.Set("xrole", f.Xrole) + + if _, ok := d.GetOk("app"); ok { + d.Set("app", f.Package) + } else { + d.Set("package", f.Package) + } + + if _, ok := d.GetOk("agency"); ok { + d.Set("agency", f.Xrole) + } else { + d.Set("xrole", f.Xrole) + } return nil } diff --git a/huaweicloud/resource_huaweicloud_fgs_function_v2_test.go b/huaweicloud/resource_huaweicloud_fgs_function_v2_test.go index 5071981400..e6c2b7b3e9 100644 --- a/huaweicloud/resource_huaweicloud_fgs_function_v2_test.go +++ b/huaweicloud/resource_huaweicloud_fgs_function_v2_test.go @@ -85,7 +85,7 @@ func testAccCheckFgsV2FunctionExists(n string, ft *function.Function) resource.T const testAccFgsV2Function_basic = ` resource "huaweicloud_fgs_function_v2" "f_1" { name = "func_1" - package = "default" + app = "default" description = "fuction test" handler = "test.handler" memory_size = 128