Skip to content

Commit 8ff0c7d

Browse files
feat: fix(workers_domain): treat PUT /workers/domains as a create operation
* fix(workers_domain): treat `PUT /workers/domains` as a create operation
1 parent 1b94fcd commit 8ff0c7d

File tree

3 files changed

+15
-55
lines changed

3 files changed

+15
-55
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 1826
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-7a82c42f729d63b7f6ac232f6c30b71a959346d1aa52daf9e50eb1f43d70d1ac.yml
33
openapi_spec_hash: b93acd5c37e6f6119efc0f466c724f5a
4-
config_hash: 6b1c4254f3918c63e1abef683bb728c3
4+
config_hash: 293d685513e3b1277b3451ba4b08f40b

internal/services/workers_custom_domain/resource.go

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -96,51 +96,7 @@ func (r *WorkersCustomDomainResource) Create(ctx context.Context, req resource.C
9696
}
9797

9898
func (r *WorkersCustomDomainResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
99-
var data *WorkersCustomDomainModel
100-
101-
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
102-
103-
if resp.Diagnostics.HasError() {
104-
return
105-
}
106-
107-
var state *WorkersCustomDomainModel
108-
109-
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
110-
111-
if resp.Diagnostics.HasError() {
112-
return
113-
}
114-
115-
dataBytes, err := data.MarshalJSONForUpdate(*state)
116-
if err != nil {
117-
resp.Diagnostics.AddError("failed to serialize http request", err.Error())
118-
return
119-
}
120-
res := new(http.Response)
121-
env := WorkersCustomDomainResultEnvelope{*data}
122-
_, err = r.client.Workers.Domains.Update(
123-
ctx,
124-
workers.DomainUpdateParams{
125-
AccountID: cloudflare.F(data.AccountID.ValueString()),
126-
},
127-
option.WithRequestBody("application/json", dataBytes),
128-
option.WithResponseBodyInto(&res),
129-
option.WithMiddleware(logging.Middleware(ctx)),
130-
)
131-
if err != nil {
132-
resp.Diagnostics.AddError("failed to make http request", err.Error())
133-
return
134-
}
135-
bytes, _ := io.ReadAll(res.Body)
136-
err = apijson.UnmarshalComputed(bytes, &env)
137-
if err != nil {
138-
resp.Diagnostics.AddError("failed to deserialize http request", err.Error())
139-
return
140-
}
141-
data = &env.Result
142-
143-
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
99+
// Update is not supported for this resource
144100
}
145101

146102
func (r *WorkersCustomDomainResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {

internal/services/workers_custom_domain/schema.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,32 @@ func ResourceSchema(ctx context.Context) schema.Schema {
1919
"id": schema.StringAttribute{
2020
Description: "Identifer of the Worker Domain.",
2121
Computed: true,
22-
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
22+
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown(), stringplanmodifier.RequiresReplace()},
2323
},
2424
"account_id": schema.StringAttribute{
2525
Description: "Identifer of the account.",
2626
Required: true,
2727
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
2828
},
2929
"environment": schema.StringAttribute{
30-
Description: "Worker environment associated with the zone and hostname.",
31-
Required: true,
30+
Description: "Worker environment associated with the zone and hostname.",
31+
Required: true,
32+
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
3233
},
3334
"hostname": schema.StringAttribute{
34-
Description: "Hostname of the Worker Domain.",
35-
Required: true,
35+
Description: "Hostname of the Worker Domain.",
36+
Required: true,
37+
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
3638
},
3739
"service": schema.StringAttribute{
38-
Description: "Worker service associated with the zone and hostname.",
39-
Required: true,
40+
Description: "Worker service associated with the zone and hostname.",
41+
Required: true,
42+
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
4043
},
4144
"zone_id": schema.StringAttribute{
42-
Description: "Identifier of the zone.",
43-
Required: true,
45+
Description: "Identifier of the zone.",
46+
Required: true,
47+
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
4448
},
4549
"zone_name": schema.StringAttribute{
4650
Description: "Name of the zone.",

0 commit comments

Comments
 (0)