Skip to content

Commit b5988cd

Browse files
committed
New modelV1 for resource/http
Earlier it was using modelV1 which also changed docs for data-source Introduced new modelV1 with when attribute for resource http
1 parent a040b3e commit b5988cd

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

docs/data-sources/http.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ resource "null_resource" "example" {
157157
- `request_headers` (Map of String) A map of request header field names and values.
158158
- `request_timeout_ms` (Number) The request timeout in milliseconds.
159159
- `retry` (Block, Optional) Retry request configuration. By default there are no retries. Configuring this block will result in retries if an error is returned by the client (e.g., connection errors) or if a 5xx-range (except 501) status code is received. For further details see [go-retryablehttp](https://pkg.go.dev/github.com/hashicorp/go-retryablehttp). (see [below for nested schema](#nestedblock--retry))
160-
- `when` (String) When to send the HTTP request. Valid values are `apply` (default) and `destroy`. When set to `apply`, the request is sent during resource creation and updates. When set to `destroy`, the request is only sent during resource destruction. This attribute is only applicable to the http resource, not the data source.
161160

162161
### Read-Only
163162

internal/provider/data_source_http.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,6 @@ a 5xx-range (except 501) status code is received. For further details see
160160
Optional: true,
161161
},
162162

163-
"when": schema.StringAttribute{
164-
Description: "When to send the HTTP request. Valid values are `apply` (default) and `destroy`. " +
165-
"When set to `apply`, the request is sent during resource creation and updates. " +
166-
"When set to `destroy`, the request is only sent during resource destruction. " +
167-
"This attribute is only applicable to the http resource, not the data source.",
168-
Optional: true,
169-
Validators: []validator.String{
170-
stringvalidator.OneOf([]string{
171-
"apply",
172-
"destroy",
173-
}...),
174-
},
175-
},
176-
177163
"response_headers": schema.MapAttribute{
178164
Description: `A map of response header field names and values.` +
179165
` Duplicate headers are concatenated according to [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2).`,
@@ -442,7 +428,6 @@ type modelV0 struct {
442428
RequestBody types.String `tfsdk:"request_body"`
443429
RequestTimeout types.Int64 `tfsdk:"request_timeout_ms"`
444430
Retry types.Object `tfsdk:"retry"`
445-
When types.String `tfsdk:"when"`
446431
ResponseHeaders types.Map `tfsdk:"response_headers"`
447432
CaCertificate types.String `tfsdk:"ca_cert_pem"`
448433
ClientCert types.String `tfsdk:"client_cert_pem"`

internal/provider/resource_http.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (r *httpResource) Configure(ctx context.Context, req resource.ConfigureRequ
222222
}
223223

224224
func (r *httpResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
225-
var model modelV0
225+
var model modelV1
226226
diags := req.Plan.Get(ctx, &model)
227227
resp.Diagnostics.Append(diags...)
228228
if resp.Diagnostics.HasError() {
@@ -258,7 +258,7 @@ func (r *httpResource) Create(ctx context.Context, req resource.CreateRequest, r
258258
}
259259

260260
func (r *httpResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
261-
var model modelV0
261+
var model modelV1
262262
diags := req.State.Get(ctx, &model)
263263
resp.Diagnostics.Append(diags...)
264264
if resp.Diagnostics.HasError() {
@@ -292,7 +292,7 @@ func (r *httpResource) Read(ctx context.Context, req resource.ReadRequest, resp
292292

293293
func (r *httpResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
294294
// Preserve computed fields across updates; reflect config changes and optionally perform request
295-
var plan, state modelV0
295+
var plan, state modelV1
296296
var diags diag.Diagnostics
297297

298298
// Read desired configuration from plan
@@ -336,7 +336,7 @@ func (r *httpResource) Update(ctx context.Context, req resource.UpdateRequest, r
336336
}
337337

338338
func (r *httpResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
339-
var model modelV0
339+
var model modelV1
340340
diags := req.State.Get(ctx, &model)
341341
resp.Diagnostics.Append(diags...)
342342
if resp.Diagnostics.HasError() {
@@ -356,7 +356,7 @@ func (r *httpResource) Delete(ctx context.Context, req resource.DeleteRequest, r
356356
}
357357
}
358358

359-
func (r *httpResource) performRequest(ctx context.Context, model *modelV0, diags *diag.Diagnostics) error {
359+
func (r *httpResource) performRequest(ctx context.Context, model *modelV1, diags *diag.Diagnostics) error {
360360
requestURL := model.URL.ValueString()
361361
method := model.Method.ValueString()
362362
requestHeaders := model.RequestHeaders
@@ -555,3 +555,23 @@ func (r *httpResource) performRequest(ctx context.Context, model *modelV0, diags
555555

556556
return nil
557557
}
558+
559+
type modelV1 struct {
560+
ID types.String `tfsdk:"id"`
561+
URL types.String `tfsdk:"url"`
562+
Method types.String `tfsdk:"method"`
563+
RequestHeaders types.Map `tfsdk:"request_headers"`
564+
RequestBody types.String `tfsdk:"request_body"`
565+
RequestTimeout types.Int64 `tfsdk:"request_timeout_ms"`
566+
Retry types.Object `tfsdk:"retry"`
567+
When types.String `tfsdk:"when"`
568+
ResponseHeaders types.Map `tfsdk:"response_headers"`
569+
CaCertificate types.String `tfsdk:"ca_cert_pem"`
570+
ClientCert types.String `tfsdk:"client_cert_pem"`
571+
ClientKey types.String `tfsdk:"client_key_pem"`
572+
Insecure types.Bool `tfsdk:"insecure"`
573+
ResponseBody types.String `tfsdk:"response_body"`
574+
Body types.String `tfsdk:"body"`
575+
ResponseBodyBase64 types.String `tfsdk:"response_body_base64"`
576+
StatusCode types.Int64 `tfsdk:"status_code"`
577+
}

0 commit comments

Comments
 (0)