-
Notifications
You must be signed in to change notification settings - Fork 120
/
helpers.go.tmpl
32 lines (24 loc) · 1.16 KB
/
helpers.go.tmpl
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
{{- /*gotype: tftemplate/models.ResourceTemplate*/ -}}
package scaleway
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/scaleway/scaleway-sdk-go/scw"
)
// {{.API}}APIWith{{.LocalityUpper}} returns a new {{.API}} API and the {{.Locality}} for a Create request
func {{.API}}APIWith{{.LocalityUpper}}(d *schema.ResourceData, m interface{}) (*{{.API}}.API, scw.{{.LocalityUpper}}, error) {
{{.API}}API := {{.API}}.NewAPI(meta.ExtractScwClient(m))
{{.Locality}}, err := extract{{.LocalityUpper}}(d, m)
if err != nil {
return nil, "", err
}
return {{.API}}API, {{.Locality}}, nil
}
// {{.API}}APIWith{{.LocalityAdjectiveUpper}}AndID returns a new {{.API }} API with {{.Locality}} and ID extracted from the state
func {{.API}}APIWith{{.LocalityUpper}}AndID(m interface{}, {{.LocalityAdjective}}ID string) (*{{.API}}.API, scw.{{.LocalityUpper}}, string, error) {
{{.API}}API := {{.API}}.NewAPI(meta.ExtractScwClient(m))
{{.Locality}}, ID, err := parse{{.LocalityAdjectiveUpper}}ID({{.LocalityAdjective}}ID)
if err != nil {
return nil, "", "", err
}
return {{.API}}API, {{.Locality}}, ID, nil
}