This repository has been archived by the owner on Sep 22, 2020. It is now read-only.
/
resource_vthunder_fw_vrid.go
86 lines (71 loc) · 1.96 KB
/
resource_vthunder_fw_vrid.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
package vthunder
//vThunder resource FwVrid
import (
"github.com/go_vthunder/vthunder"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"strconv"
"util"
)
func resourceFwVrid() *schema.Resource {
return &schema.Resource{
Create: resourceFwVridCreate,
Update: resourceFwVridUpdate,
Read: resourceFwVridRead,
Delete: resourceFwVridDelete,
Schema: map[string]*schema.Schema{
"vrid": {
Type: schema.TypeInt,
Optional: true,
Description: "",
},
"uuid": {
Type: schema.TypeString,
Optional: true,
Description: "",
},
},
}
}
func resourceFwVridCreate(d *schema.ResourceData, meta interface{}) error {
logger := util.GetLoggerInstance()
client := meta.(vThunder)
if client.Host != "" {
logger.Println("[INFO] Creating FwVrid (Inside resourceFwVridCreate) ")
data := dataToFwVrid(d)
logger.Println("[INFO] received formatted data from method data to FwVrid --")
d.SetId(strconv.Itoa('1'))
go_vthunder.PostFwVrid(client.Token, data, client.Host)
return resourceFwVridRead(d, meta)
}
return nil
}
func resourceFwVridRead(d *schema.ResourceData, meta interface{}) error {
logger := util.GetLoggerInstance()
client := meta.(vThunder)
logger.Println("[INFO] Reading FwVrid (Inside resourceFwVridRead)")
if client.Host != "" {
name := d.Id()
logger.Println("[INFO] Fetching service Read" + name)
data, err := go_vthunder.GetFwVrid(client.Token, client.Host)
if data == nil {
logger.Println("[INFO] No data found " + name)
d.SetId("")
return nil
}
return err
}
return nil
}
func resourceFwVridUpdate(d *schema.ResourceData, meta interface{}) error {
return resourceFwVridRead(d, meta)
}
func resourceFwVridDelete(d *schema.ResourceData, meta interface{}) error {
return resourceFwVridRead(d, meta)
}
func dataToFwVrid(d *schema.ResourceData) go_vthunder.FwVrid {
var vc go_vthunder.FwVrid
var c go_vthunder.FwVridInstance
c.Vrid = d.Get("vrid").(int)
vc.Vrid = c
return vc
}