Skip to content

Commit 9856716

Browse files
committed
feat(provider/webhook): respect identifiers in responses and synthesise a standard resource id attribute
1 parent 90a25cd commit 9856716

3 files changed

Lines changed: 39 additions & 28 deletions

File tree

docs/resources/webhook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ resource "contentful_webhook" "this" {
6868

6969
### Read-Only
7070

71+
- `id` (String) The ID of this resource.
7172
- `webhook_id` (String)
7273

7374
<a id="nestedatt--filters"></a>

internal/provider/webhook_model_response.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
"strings"
56

67
cm "github.com/cysp/terraform-provider-contentful/internal/contentful-management-go"
78
"github.com/cysp/terraform-provider-contentful/internal/provider/util"
@@ -13,7 +14,12 @@ import (
1314
func (model *WebhookResourceModel) ReadFromResponse(ctx context.Context, webhookDefinition *cm.WebhookDefinition) diag.Diagnostics {
1415
diags := diag.Diagnostics{}
1516

16-
model.WebhookID = types.StringValue(webhookDefinition.Sys.ID)
17+
spaceID := webhookDefinition.Sys.Space.Sys.ID
18+
webhookID := webhookDefinition.Sys.ID
19+
20+
model.ID = types.StringValue(strings.Join([]string{spaceID, webhookID}, "/"))
21+
model.SpaceID = types.StringValue(spaceID)
22+
model.WebhookID = types.StringValue(webhookID)
1723

1824
model.Name = types.StringValue(webhookDefinition.Name)
1925

internal/provider/webhook_resource_model.go

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,62 @@ import (
1111
)
1212

1313
type WebhookResourceModel struct {
14-
Active types.Bool `tfsdk:"active"`
14+
ID types.String `tfsdk:"id"`
15+
SpaceID types.String `tfsdk:"space_id"`
16+
WebhookID types.String `tfsdk:"webhook_id"`
17+
Name types.String `tfsdk:"name"`
18+
URL types.String `tfsdk:"url"`
19+
Topics types.List `tfsdk:"topics"`
1520
Filters types.List `tfsdk:"filters"`
16-
Headers types.Map `tfsdk:"headers"`
1721
HTTPBasicPassword types.String `tfsdk:"http_basic_password"`
1822
HTTPBasicUsername types.String `tfsdk:"http_basic_username"`
19-
Name types.String `tfsdk:"name"`
20-
SpaceID types.String `tfsdk:"space_id"`
21-
Topics types.List `tfsdk:"topics"`
23+
Headers types.Map `tfsdk:"headers"`
2224
Transformation WebhookTransformationValue `tfsdk:"transformation"`
23-
URL types.String `tfsdk:"url"`
24-
WebhookID types.String `tfsdk:"webhook_id"`
25+
Active types.Bool `tfsdk:"active"`
2526
}
2627

2728
func WebhookResourceSchema(ctx context.Context) schema.Schema {
2829
return schema.Schema{
2930
Attributes: map[string]schema.Attribute{
30-
"active": schema.BoolAttribute{
31-
Optional: true,
31+
"id": schema.StringAttribute{
3232
Computed: true,
33-
Default: booldefault.StaticBool(true),
3433
},
35-
"filters": WebhookFiltersSchema(ctx, true),
36-
"headers": WebhookHeadersSchema(ctx, true),
37-
"http_basic_password": schema.StringAttribute{
38-
Optional: true,
34+
"space_id": schema.StringAttribute{
35+
Required: true,
36+
PlanModifiers: []planmodifier.String{
37+
stringplanmodifier.RequiresReplace(),
38+
},
3939
},
40-
"http_basic_username": schema.StringAttribute{
40+
"webhook_id": schema.StringAttribute{
41+
Computed: true,
42+
PlanModifiers: []planmodifier.String{
43+
stringplanmodifier.UseStateForUnknown(),
44+
},
45+
},
46+
"active": schema.BoolAttribute{
4147
Optional: true,
48+
Computed: true,
49+
Default: booldefault.StaticBool(true),
4250
},
4351
"name": schema.StringAttribute{
4452
Required: true,
4553
},
46-
"space_id": schema.StringAttribute{
54+
"url": schema.StringAttribute{
4755
Required: true,
48-
PlanModifiers: []planmodifier.String{
49-
stringplanmodifier.RequiresReplace(),
50-
},
5156
},
5257
"topics": schema.ListAttribute{
5358
ElementType: types.StringType,
5459
Optional: true,
5560
},
56-
"transformation": WebhookTransformationSchema(ctx, true),
57-
"url": schema.StringAttribute{
58-
Required: true,
61+
"filters": WebhookFiltersSchema(ctx, true),
62+
"http_basic_password": schema.StringAttribute{
63+
Optional: true,
5964
},
60-
"webhook_id": schema.StringAttribute{
61-
Computed: true,
62-
PlanModifiers: []planmodifier.String{
63-
stringplanmodifier.UseStateForUnknown(),
64-
},
65+
"http_basic_username": schema.StringAttribute{
66+
Optional: true,
6567
},
68+
"headers": WebhookHeadersSchema(ctx, true),
69+
"transformation": WebhookTransformationSchema(ctx, true),
6670
},
6771
}
6872
}

0 commit comments

Comments
 (0)