Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename xrole and app arguments for fgs #1095

Merged
merged 1 commit into from
Apr 30, 2021
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
7 changes: 4 additions & 3 deletions docs/resources/fgs_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down
67 changes: 57 additions & 10 deletions huaweicloud/resource_huaweicloud_fgs_function_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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,
}

Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion huaweicloud/resource_huaweicloud_fgs_function_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down