/
data_source_ibm_function_action.go
146 lines (135 loc) · 3.97 KB
/
data_source_ibm_function_action.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package ibm
import (
"fmt"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceIBMFunctionAction() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMFunctionActionRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of action.",
},
"limits": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"timeout": {
Type: schema.TypeInt,
Computed: true,
Description: "The timeout LIMIT in milliseconds after which the action is terminated.",
},
"memory": {
Type: schema.TypeInt,
Computed: true,
Description: "The maximum memory LIMIT in MB for the action (default 256.",
},
"log_size": {
Type: schema.TypeInt,
Computed: true,
Description: "The maximum log size LIMIT in MB for the action.",
},
},
},
},
"exec": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"image": {
Type: schema.TypeString,
Computed: true,
Description: "Container image name when kind is 'blackbox'.",
},
"init": {
Type: schema.TypeString,
Computed: true,
Description: "Optional zipfile reference.",
},
"code": {
Type: schema.TypeString,
Computed: true,
Description: "The code to execute when kind is not 'blackbox'.",
},
"kind": {
Type: schema.TypeString,
Computed: true,
Description: "The type of action. Possible values:php:7.1, nodejs:8, swift:3, nodejs, blackbox, java, sequence, nodejs:6, python:3, python, python:2, swift, swift:3.1.1.",
},
"main": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the action entry point (function or fully-qualified method name when applicable)",
},
"components": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "The List of fully qualified action",
},
},
},
},
"publish": {
Type: schema.TypeBool,
Computed: true,
Description: "Action visibilty.",
},
"version": {
Type: schema.TypeString,
Computed: true,
Description: "Semantic version of the item.",
},
"annotations": {
Type: schema.TypeString,
Computed: true,
Description: "All annotations set on action by user and those set by the IBM Cloud Function backend/API.",
},
"parameters": {
Type: schema.TypeString,
Computed: true,
Description: "All paramters set on action by user and those set by the IBM Cloud Function backend/API.",
},
},
}
}
func dataSourceIBMFunctionActionRead(d *schema.ResourceData, meta interface{}) error {
wskClient, err := meta.(ClientSession).FunctionClient()
if err != nil {
return err
}
actionService := wskClient.Actions
name := d.Get("name").(string)
action, _, err := actionService.Get(name)
if err != nil {
return fmt.Errorf("Error retrieving IBM Cloud Function Action %s : %s", name, err)
}
temp := strings.Split(action.Namespace, "/")
if len(temp) == 2 {
d.SetId(fmt.Sprintf("%s/%s", temp[1], action.Name))
d.Set("name", fmt.Sprintf("%s/%s", temp[1], action.Name))
} else {
d.SetId(action.Name)
d.Set("name", action.Name)
}
d.Set("limits", flattenLimits(action.Limits))
d.Set("exec", flattenExec(action.Exec))
d.Set("publish", action.Publish)
d.Set("version", action.Version)
annotations, err := flattenAnnotations(action.Annotations)
if err != nil {
return err
}
d.Set("annotations", annotations)
parameters, err := flattenParameters(action.Parameters)
if err != nil {
return err
}
d.Set("parameters", parameters)
return nil
}