Skip to content

Commit f661dfd

Browse files
committed
update function compute sample
1 parent 834197a commit f661dfd

File tree

2 files changed

+52
-36
lines changed

2 files changed

+52
-36
lines changed

function_compute_sample/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ $ vim terraform.tfvars
1414
=> Edit variables with your favorite editor.
1515
```
1616

17+
Upload sample code to OSS bucket as `function_compute.py.zip`.
18+
```python
19+
import logging
20+
21+
def handler(event, context):
22+
logger = logging.getLogger()
23+
logger.info('hello world')
24+
return 'hello world'
25+
```
26+
1727
Deploy to Alibaba Cloud
1828
```
1929
$ terraform apply

function_compute_sample/terraform.tf

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
variable "account_id" {}
22
variable "access_key" {}
33
variable "secret_key" {}
4-
varuable "oss_bucket" {}
4+
variable "oss_bucket" {}
55
variable "region" {}
6-
variable "zone" {}
76

87
provider "alicloud" {
98
access_key = "${var.access_key}"
109
secret_key = "${var.secret_key}"
1110
account_id = "${var.account_id}"
12-
region = "${var.region}"
11+
region = "${var.region}"
1312
}
1413

1514
resource "alicloud_log_project" "example" {
16-
name = "fc-log-20180730"
15+
name = "fc-log-20180730"
1716
description = "created by terraform"
1817
}
1918

@@ -23,66 +22,73 @@ resource "alicloud_log_store" "example" {
2322
}
2423

2524
resource "alicloud_ram_role" "role" {
26-
name = "fc-role"
27-
services = ["fc.aliyuncs.com"]
25+
name = "fc-role"
26+
services = ["fc.aliyuncs.com"]
2827
description = "this is a role test."
29-
force = true
28+
force = true
3029
}
3130

3231
resource "alicloud_ram_policy" "policy" {
3332
name = "fc-policy"
33+
3434
statement = [
35-
{
36-
effect = "Allow"
37-
action = ["log:PostLogStoreLogs"]
38-
resource = [
39-
"acs:log:*:*:project/${alicloud_log_project.example.name}/logstore/${alicloud_log_store.example.name}"]
40-
},
41-
{
42-
effect = "Allow"
43-
action = ["oss:*"]
44-
resource = ["*"]
45-
}
46-
]
35+
{
36+
effect = "Allow"
37+
action = ["log:PostLogStoreLogs"]
38+
39+
resource = [
40+
"acs:log:*:*:project/${alicloud_log_project.example.name}/logstore/${alicloud_log_store.example.name}",
41+
]
42+
},
43+
{
44+
effect = "Allow"
45+
action = ["oss:Get*"]
46+
resource = ["acs:oss:*:*:${var.oss_bucket}"]
47+
},
48+
]
49+
4750
description = "this is a policy test"
48-
force = true
51+
force = true
4952
}
5053

5154
resource "alicloud_ram_role_policy_attachment" "attach" {
5255
policy_name = "${alicloud_ram_policy.policy.name}"
5356
policy_type = "${alicloud_ram_policy.policy.type}"
54-
role_name = "${alicloud_ram_role.role.name}"
57+
role_name = "${alicloud_ram_role.role.name}"
5558
}
5659

5760
resource "alicloud_fc_service" "foo" {
58-
name = "my-fc-service"
59-
description = "created by tf"
61+
name = "my-fc-service"
62+
description = "my fc service for terraform test"
6063
internet_access = false
61-
role = "${alicloud_ram_role.role.arn}"
64+
role = "${alicloud_ram_role.role.arn}"
65+
6266
log_config = [
6367
{
64-
project = "${alicloud_log_project.example.name}"
68+
project = "${alicloud_log_project.example.name}"
6569
logstore = "${alicloud_log_store.example.name}"
66-
}
70+
},
6771
]
6872
}
6973

7074
resource "alicloud_fc_function" "foo" {
71-
service = "${alicloud_fc_service.foo.name}"
72-
name = "hello-world"
73-
description = "tf unit test"
74-
oss_bucket = "${var.oss_bucket}"
75-
oss_key = "function_compute.py.zip"
75+
service = "${alicloud_fc_service.foo.name}"
76+
name = "hello-world"
77+
description = "my fc function for terraform test"
78+
oss_bucket = "${var.oss_bucket}"
79+
oss_key = "function_compute.py.zip"
7680
memory_size = "512"
77-
runtime = "python2.7"
81+
runtime = "python2.7"
82+
handler = "function_compute.handler"
7883
}
7984

8085
resource "alicloud_fc_trigger" "foo" {
81-
service = "${alicloud_fc_service.foo.name}"
82-
function = "${alicloud_fc_function.foo.name}"
83-
name = "hello-trigger"
84-
type = "timer"
86+
service = "${alicloud_fc_service.foo.name}"
87+
function = "${alicloud_fc_function.foo.name}"
88+
name = "hello-trigger"
89+
type = "timer"
8590
source_arn = "test"
91+
8692
config = <<EOF
8793
{
8894
"payload": "aaaaa",

0 commit comments

Comments
 (0)