Skip to content

Commit 9b34a4a

Browse files
committed
create resource_iploadbalancing_ssl
1 parent c22ccde commit 9b34a4a

5 files changed

+527
-0
lines changed

ovh/provider_new.go

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func (p *OvhProvider) Resources(_ context.Context) []func() resource.Resource {
215215
NewDomainZoneImportResource,
216216
NewIpFirewallResource,
217217
NewIpFirewallRuleResource,
218+
NewIploadbalancingSslResource,
218219
NewIploadbalancingUdpFrontendResource,
219220
NewIpMitigationResource,
220221
NewVpsResource,

ovh/resource_iploadbalancing_ssl.go

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package ovh
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/url"
7+
"strconv"
8+
9+
"github.com/hashicorp/terraform-plugin-framework/resource"
10+
)
11+
12+
var _ resource.ResourceWithConfigure = (*iploadbalancingSslResource)(nil)
13+
14+
func NewIploadbalancingSslResource() resource.Resource {
15+
return &iploadbalancingSslResource{}
16+
}
17+
18+
type iploadbalancingSslResource struct {
19+
config *Config
20+
}
21+
22+
func (r *iploadbalancingSslResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
23+
resp.TypeName = req.ProviderTypeName + "_iploadbalancing_ssl"
24+
}
25+
26+
func (d *iploadbalancingSslResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
27+
if req.ProviderData == nil {
28+
return
29+
}
30+
31+
config, ok := req.ProviderData.(*Config)
32+
if !ok {
33+
resp.Diagnostics.AddError(
34+
"Unexpected Resource Configure Type",
35+
fmt.Sprintf("Expected *Config, got: %T. Please report this issue to the provider developers.", req.ProviderData),
36+
)
37+
return
38+
}
39+
40+
d.config = config
41+
}
42+
43+
func (d *iploadbalancingSslResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
44+
resp.Schema = IploadbalancingSslResourceSchema(ctx)
45+
}
46+
47+
func (r *iploadbalancingSslResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
48+
var data, responseData IploadbalancingSslModel
49+
50+
// Read Terraform plan data into the model
51+
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
52+
if resp.Diagnostics.HasError() {
53+
return
54+
}
55+
56+
endpoint := "/ipLoadbalancing/" + url.PathEscape(data.ServiceName.ValueString()) + "/ssl"
57+
if err := r.config.OVHClient.Post(endpoint, data.ToCreate(), &responseData); err != nil {
58+
resp.Diagnostics.AddError(
59+
fmt.Sprintf("Error calling Post %s", endpoint),
60+
err.Error(),
61+
)
62+
return
63+
}
64+
65+
responseData.MergeWith(&data)
66+
67+
// Save data into Terraform state
68+
resp.Diagnostics.Append(resp.State.Set(ctx, &responseData)...)
69+
}
70+
71+
func (r *iploadbalancingSslResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
72+
var data, responseData IploadbalancingSslModel
73+
74+
// Read Terraform prior state data into the model
75+
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
76+
if resp.Diagnostics.HasError() {
77+
return
78+
}
79+
80+
endpoint := "/ipLoadbalancing/" + url.PathEscape(data.ServiceName.ValueString()) + "/ssl/" + strconv.FormatInt(data.Id.ValueInt64(), 10) + ""
81+
82+
if err := r.config.OVHClient.Get(endpoint, &responseData); err != nil {
83+
resp.Diagnostics.AddError(
84+
fmt.Sprintf("Error calling Get %s", endpoint),
85+
err.Error(),
86+
)
87+
return
88+
}
89+
90+
data.MergeWith(&responseData)
91+
92+
// Save updated data into Terraform state
93+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
94+
}
95+
96+
func (r *iploadbalancingSslResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
97+
var data, planData, responseData IploadbalancingSslModel
98+
99+
// Read Terraform plan data into the model
100+
resp.Diagnostics.Append(req.Plan.Get(ctx, &planData)...)
101+
if resp.Diagnostics.HasError() {
102+
return
103+
}
104+
105+
// Read Terraform prior state data into the model
106+
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
107+
if resp.Diagnostics.HasError() {
108+
return
109+
}
110+
111+
// Update resource
112+
endpoint := "/ipLoadbalancing/" + url.PathEscape(data.ServiceName.ValueString()) + "/ssl/" + strconv.FormatInt(data.Id.ValueInt64(), 10) + ""
113+
if err := r.config.OVHClient.Put(endpoint, planData.ToUpdate(), nil); err != nil {
114+
resp.Diagnostics.AddError(
115+
fmt.Sprintf("Error calling Put %s", endpoint),
116+
err.Error(),
117+
)
118+
return
119+
}
120+
121+
// Read updated resource
122+
endpoint = "/ipLoadbalancing/" + url.PathEscape(data.ServiceName.ValueString()) + "/ssl/" + strconv.FormatInt(data.Id.ValueInt64(), 10) + ""
123+
if err := r.config.OVHClient.Get(endpoint, &responseData); err != nil {
124+
resp.Diagnostics.AddError(
125+
fmt.Sprintf("Error calling Get %s", endpoint),
126+
err.Error(),
127+
)
128+
return
129+
}
130+
131+
responseData.MergeWith(&planData)
132+
133+
// Save updated data into Terraform state
134+
resp.Diagnostics.Append(resp.State.Set(ctx, &responseData)...)
135+
}
136+
137+
func (r *iploadbalancingSslResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
138+
var data IploadbalancingSslModel
139+
140+
// Read Terraform prior state data into the model
141+
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
142+
143+
if resp.Diagnostics.HasError() {
144+
return
145+
}
146+
147+
// Delete API call logic
148+
endpoint := "/ipLoadbalancing/" + url.PathEscape(data.ServiceName.ValueString()) + "/ssl/" + strconv.FormatInt(data.Id.ValueInt64(), 10) + ""
149+
if err := r.config.OVHClient.Delete(endpoint, nil); err != nil {
150+
resp.Diagnostics.AddError(
151+
fmt.Sprintf("Error calling Delete %s", endpoint),
152+
err.Error(),
153+
)
154+
}
155+
}

ovh/resource_iploadbalancing_ssl_gen.go

+199
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)