/
data_source_dcnm_template.go
68 lines (61 loc) · 1.5 KB
/
data_source_dcnm_template.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
package dcnm
import (
"log"
"github.com/ciscoecosystem/dcnm-go-client/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func datasourceDCNMTemplate() *schema.Resource {
return &schema.Resource{
Read: datasourceDCNMTemplateRead,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"content": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"description": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"tags": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"supported_platforms": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"template_type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"template_sub_type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"template_content_type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
}
}
func datasourceDCNMTemplateRead(d *schema.ResourceData, m interface{}) error {
log.Println("[DEBUG] Begining Read Method ", d.Id())
dcnmClient := m.(*client.Client)
name := d.Get("name").(string)
cont, err := getTemplate(dcnmClient, name)
if err != nil {
return getErrorFromContainer(cont, err)
}
setTemplateAttribute(d, cont)
d.SetId(name)
log.Println("[DEBUG] End of Read method ", d.Id())
return nil
}