Skip to content

Commit 6796a6a

Browse files
committed
resource/alicloud_fc_function: Adds new attribute function_arn
1 parent 4ba86c6 commit 6796a6a

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

alicloud/resource_alicloud_fc_function.go

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package alicloud
33
import (
44
"encoding/json"
55
"fmt"
6+
"log"
67
"time"
78

89
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
@@ -107,6 +108,10 @@ func resourceAlicloudFCFunction() *schema.Resource {
107108
Type: schema.TypeString,
108109
Computed: true,
109110
},
111+
"function_arn": {
112+
Type: schema.TypeString,
113+
Computed: true,
114+
},
110115
"initializer": {
111116
Type: schema.TypeString,
112117
Optional: true,
@@ -278,6 +283,11 @@ func resourceAlicloudFCFunctionRead(d *schema.ResourceData, meta interface{}) er
278283
d.Set("code_checksum", object.CodeChecksum)
279284
d.Set("name", object.FunctionName)
280285
d.Set("function_id", object.FunctionID)
286+
if accountId, err := client.AccountId(); err != nil {
287+
log.Print(WrapError(err))
288+
} else {
289+
d.Set("function_arn", fmt.Sprintf("acs:fc:%s:%s:services/%s.LATEST/functions/%s", client.RegionId, accountId, parts[0], parts[1]))
290+
}
281291
d.Set("description", object.Description)
282292
d.Set("handler", object.Handler)
283293
d.Set("memory_size", object.MemorySize)

alicloud/resource_alicloud_fc_function_test.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,14 @@ func TestAccAlicloudFCFunction_basic(t *testing.T) {
106106
rand := acctest.RandIntRange(10000, 999999)
107107
name := fmt.Sprintf("tf-testaccalicloudfcfunction-%d", rand)
108108
var basicMap = map[string]string{
109-
"service": CHECKSET,
110-
"name": name,
111-
"runtime": "nodejs12",
112-
"description": "tf",
113-
"handler": "hello.handler",
114-
"oss_bucket": CHECKSET,
115-
"oss_key": CHECKSET,
109+
"service": CHECKSET,
110+
"name": name,
111+
"runtime": "nodejs12",
112+
"description": "tf",
113+
"handler": "hello.handler",
114+
"oss_bucket": CHECKSET,
115+
"oss_key": CHECKSET,
116+
"function_arn": CHECKSET,
116117
}
117118
resourceId := "alicloud_fc_function.default"
118119
ra := resourceAttrInit(resourceId, basicMap)
@@ -444,6 +445,11 @@ output "container_args" {
444445
resource "alicloud_log_project" "default" {
445446
name = "${var.name}"
446447
description = "tf unit test"
448+
lifecycle {
449+
ignore_changes = [
450+
policy
451+
]
452+
}
447453
}
448454
449455
resource "alicloud_log_store" "default" {

website/docs/r/fc_function.html.markdown

+3-2
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ The custom_container_config following arguments:
153153

154154
The following arguments are exported:
155155

156-
* `id` - The ID of the function. The value is formate as `<service>:<name>`.
156+
* `id` - The ID of the function. It formats as `<service>:<name>`.
157157
* `last_modified` - The date this resource was last modified.
158-
* `function_id` - The Function Compute service ID.
158+
* `function_id` - The Function Compute service function ID.
159+
* `function_arn` - The Function Compute service function arn. It formats as `acs:fc:<region>:<uid>:services/<serviceName>.LATEST/functions/<functionName>`.
159160

160161
## Import
161162

0 commit comments

Comments
 (0)