/
resource_service_partition.go
111 lines (105 loc) · 3.56 KB
/
resource_service_partition.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
package thunder
import (
"context"
edpt "github.com/a10networks/terraform-provider-thunder/thunder/axapi/endpoint"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceServicePartition() *schema.Resource {
return &schema.Resource{
Description: "`thunder_service_partition`: Create/unload a service partition\n\n__PLACEHOLDER__",
CreateContext: resourceServicePartitionCreate,
UpdateContext: resourceServicePartitionUpdate,
ReadContext: resourceServicePartitionRead,
DeleteContext: resourceServicePartitionDelete,
Schema: map[string]*schema.Schema{
"application_type": {
Type: schema.TypeString, Optional: true, Description: "'adc': Application type ADC;",
},
"follow_vrid": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Join a vrrp group (Specify ha VRRP-A vrid)",
},
"id1": {
Type: schema.TypeInt, Optional: true, Description: "Specify unique service partition id",
},
"partition_name": {
Type: schema.TypeString, Required: true, Description: "Object service partition name",
},
"user_tag": {
Type: schema.TypeString, Optional: true, Description: "Customized tag",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
}
}
func resourceServicePartitionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceServicePartitionCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointServicePartition(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceServicePartitionRead(ctx, d, meta)
}
return diags
}
func resourceServicePartitionUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceServicePartitionUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointServicePartition(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceServicePartitionRead(ctx, d, meta)
}
return diags
}
func resourceServicePartitionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceServicePartitionDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointServicePartition(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceServicePartitionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceServicePartitionRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointServicePartition(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func dataToEndpointServicePartition(d *schema.ResourceData) edpt.ServicePartition {
var ret edpt.ServicePartition
ret.Inst.ApplicationType = d.Get("application_type").(string)
ret.Inst.FollowVrid = d.Get("follow_vrid").(int)
ret.Inst.Id1 = d.Get("id1").(int)
ret.Inst.PartitionName = d.Get("partition_name").(string)
ret.Inst.UserTag = d.Get("user_tag").(string)
//omit uuid
return ret
}