Skip to content

Commit 6c001e3

Browse files
authored
Merge pull request #50 from netdata/fix/notification-integration-api
fix: remove extra integration_id resource attribute
2 parents 41197ce + 0658e71 commit 6c001e3

14 files changed

+38
-90
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.2.1
2+
3+
BUGFIXES:
4+
5+
- the `integration_id` attribute is being removed because it is internally used for the create resource only and
6+
doesn't bring much value to store it
7+
18
## 0.2.0
29

310
FEATURES:

docs/resources/notification_discord_channel.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ resource "netdata_notification_discord_channel" "test" {
4545
### Read-Only
4646

4747
- `id` (String) The ID of the Discord notification
48-
- `integration_id` (String) The ID of the notification integration
4948

5049
## Import
5150

docs/resources/notification_pagerduty_channel.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ resource "netdata_notification_pagerduty_channel" "test" {
4444
### Read-Only
4545

4646
- `id` (String) The ID of the Pagerduty notification
47-
- `integration_id` (String) The ID of the notification integration
4847

4948
## Import
5049

docs/resources/notification_slack_channel.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ resource "netdata_notification_slack_channel" "test" {
4242
### Read-Only
4343

4444
- `id` (String) The ID of the Slack notification
45-
- `integration_id` (String) The ID of the notification integration
4645

4746
## Import
4847

internal/client/notification_discord.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ func (c *Client) UpdateDiscordChannelByID(spaceID string, commonParams Notificat
7070
}
7171

7272
reqBody := notificationRequestPayload{
73-
Name: commonParams.Name,
74-
IntegrationID: commonParams.Integration.ID,
75-
Rooms: commonParams.Rooms,
76-
Alarms: commonParams.Alarms,
73+
Name: commonParams.Name,
74+
Rooms: commonParams.Rooms,
75+
Alarms: commonParams.Alarms,
7776
}
7877

7978
secretsJson, err := json.Marshal(discordParams)

internal/client/notification_pagerduty.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ func (c *Client) UpdatePagerdutyChannelByID(spaceID string, commonParams Notific
6969
}
7070

7171
reqBody := notificationRequestPayload{
72-
Name: commonParams.Name,
73-
IntegrationID: commonParams.Integration.ID,
74-
Rooms: commonParams.Rooms,
75-
Alarms: commonParams.Alarms,
72+
Name: commonParams.Name,
73+
Rooms: commonParams.Rooms,
74+
Alarms: commonParams.Alarms,
7675
}
7776

7877
secretsJson, err := json.Marshal(pagerdutyParams)

internal/client/notification_slack.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ func (c *Client) UpdateSlackChannelByID(spaceID string, commonParams Notificatio
6868
}
6969

7070
reqBody := notificationRequestPayload{
71-
Name: commonParams.Name,
72-
IntegrationID: commonParams.Integration.ID,
73-
Rooms: commonParams.Rooms,
74-
Alarms: commonParams.Alarms,
71+
Name: commonParams.Name,
72+
Rooms: commonParams.Rooms,
73+
Alarms: commonParams.Alarms,
7574
}
7675
secretsJson, err := json.Marshal(slackParams)
7776
if err != nil {

internal/provider/notification_discord_channel_resource.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ type discordChannelResourceModel struct {
3737
SpaceID types.String `tfsdk:"space_id"`
3838
RoomsID types.List `tfsdk:"rooms_id"`
3939
Alarms types.String `tfsdk:"alarms"`
40-
IntegrationID types.String `tfsdk:"integration_id"`
4140
WebhookURL types.String `tfsdk:"webhook_url"`
4241
ChannelType types.String `tfsdk:"channel_type"`
4342
ChannelThread types.String `tfsdk:"channel_thread"`
@@ -152,7 +151,6 @@ func (s *discordChannelResource) Create(ctx context.Context, req resource.Create
152151
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
153152
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
154153
plan.Alarms = types.StringValue(notificationChannel.Alarms)
155-
plan.IntegrationID = types.StringValue(notificationIntegration.ID)
156154

157155
diags = resp.State.Set(ctx, plan)
158156
resp.Diagnostics.Append(diags...)
@@ -226,25 +224,15 @@ func (s *discordChannelResource) Update(ctx context.Context, req resource.Update
226224
return
227225
}
228226

229-
notificationIntegration, err := s.client.GetNotificationIntegrationByType(plan.SpaceID.ValueString(), "discord")
230-
if err != nil {
231-
resp.Diagnostics.AddError(
232-
"Error Creating Discord Notification",
233-
"err: "+err.Error(),
234-
)
235-
return
236-
}
237-
238227
var roomsID []string
239228
plan.RoomsID.ElementsAs(ctx, &roomsID, false)
240229

241230
commonParams := client.NotificationChannel{
242-
ID: plan.ID.ValueString(),
243-
Name: plan.Name.ValueString(),
244-
Integration: *notificationIntegration,
245-
Rooms: roomsID,
246-
Alarms: plan.Alarms.ValueString(),
247-
Enabled: plan.Enabled.ValueBool(),
231+
ID: plan.ID.ValueString(),
232+
Name: plan.Name.ValueString(),
233+
Rooms: roomsID,
234+
Alarms: plan.Alarms.ValueString(),
235+
Enabled: plan.Enabled.ValueBool(),
248236
}
249237

250238
discordParams := client.NotificationDiscordChannel{
@@ -273,7 +261,6 @@ func (s *discordChannelResource) Update(ctx context.Context, req resource.Update
273261
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
274262
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
275263
plan.Alarms = types.StringValue(notificationChannel.Alarms)
276-
plan.IntegrationID = types.StringValue(notificationIntegration.ID)
277264

278265
diags = resp.State.Set(ctx, plan)
279266
resp.Diagnostics.Append(diags...)

internal/provider/notification_discord_channel_resource_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestAccDiscordNotificationResource(t *testing.T) {
3333
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "name", "discord"),
3434
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "enabled", "true"),
3535
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "space_id"),
36-
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "integration_id"),
3736
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "rooms_id.0"),
3837
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "alarms", "ALARMS_SETTING_ALL"),
3938
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "webhook_url", "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
@@ -62,7 +61,6 @@ func TestAccDiscordNotificationResource(t *testing.T) {
6261
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "name", "discord"),
6362
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "enabled", "false"),
6463
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "space_id"),
65-
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "integration_id"),
6664
resource.TestCheckNoResourceAttr("netdata_notification_discord_channel.test", "rooms_id.0"),
6765
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "alarms", "ALARMS_SETTING_ALL"),
6866
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "webhook_url", "https://discord.com/api/webhooks/1000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"),

internal/provider/notification_pagerduty_channel_resource.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type pagerdutyChannelResourceModel struct {
3434
SpaceID types.String `tfsdk:"space_id"`
3535
RoomsID types.List `tfsdk:"rooms_id"`
3636
Alarms types.String `tfsdk:"alarms"`
37-
IntegrationID types.String `tfsdk:"integration_id"`
3837
AlertEventsURL types.String `tfsdk:"alert_events_url"`
3938
IntegrationKey types.String `tfsdk:"integration_key"`
4039
}
@@ -124,7 +123,6 @@ func (s *pagerdutyChannelResource) Create(ctx context.Context, req resource.Crea
124123
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
125124
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
126125
plan.Alarms = types.StringValue(notificationChannel.Alarms)
127-
plan.IntegrationID = types.StringValue(notificationIntegration.ID)
128126

129127
diags = resp.State.Set(ctx, plan)
130128
resp.Diagnostics.Append(diags...)
@@ -186,25 +184,15 @@ func (s *pagerdutyChannelResource) Update(ctx context.Context, req resource.Upda
186184
return
187185
}
188186

189-
notificationIntegration, err := s.client.GetNotificationIntegrationByType(plan.SpaceID.ValueString(), "pagerduty")
190-
if err != nil {
191-
resp.Diagnostics.AddError(
192-
"Error Creating Pagerduty Notification",
193-
"err: "+err.Error(),
194-
)
195-
return
196-
}
197-
198187
var roomsID []string
199188
plan.RoomsID.ElementsAs(ctx, &roomsID, false)
200189

201190
commonParams := client.NotificationChannel{
202-
ID: plan.ID.ValueString(),
203-
Name: plan.Name.ValueString(),
204-
Integration: *notificationIntegration,
205-
Rooms: roomsID,
206-
Alarms: plan.Alarms.ValueString(),
207-
Enabled: plan.Enabled.ValueBool(),
191+
ID: plan.ID.ValueString(),
192+
Name: plan.Name.ValueString(),
193+
Rooms: roomsID,
194+
Alarms: plan.Alarms.ValueString(),
195+
Enabled: plan.Enabled.ValueBool(),
208196
}
209197

210198
pagerdutyParams := client.NotificationPagerdutyChannel{
@@ -227,7 +215,6 @@ func (s *pagerdutyChannelResource) Update(ctx context.Context, req resource.Upda
227215
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
228216
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
229217
plan.Alarms = types.StringValue(notificationChannel.Alarms)
230-
plan.IntegrationID = types.StringValue(notificationIntegration.ID)
231218

232219
diags = resp.State.Set(ctx, plan)
233220
resp.Diagnostics.Append(diags...)

internal/provider/notification_pagerduty_channel_resource_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestAccPagerdutyNotificationResource(t *testing.T) {
3333
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "name", "pagerduty"),
3434
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "enabled", "true"),
3535
resource.TestCheckResourceAttrSet("netdata_notification_pagerduty_channel.test", "space_id"),
36-
resource.TestCheckResourceAttrSet("netdata_notification_pagerduty_channel.test", "integration_id"),
3736
resource.TestCheckResourceAttrSet("netdata_notification_pagerduty_channel.test", "rooms_id.0"),
3837
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "alarms", "ALARMS_SETTING_ALL"),
3938
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "alert_events_url", "https://events.pagerduty.com/v2/enqueue"),
@@ -61,7 +60,6 @@ func TestAccPagerdutyNotificationResource(t *testing.T) {
6160
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "name", "pagerduty"),
6261
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "enabled", "false"),
6362
resource.TestCheckResourceAttrSet("netdata_notification_pagerduty_channel.test", "space_id"),
64-
resource.TestCheckResourceAttrSet("netdata_notification_pagerduty_channel.test", "integration_id"),
6563
resource.TestCheckNoResourceAttr("netdata_notification_pagerduty_channel.test", "rooms_id.0"),
6664
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "alarms", "ALARMS_SETTING_ALL"),
6765
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "alert_events_url", "https://events.pagerduty.com/v2/enqueue"),

internal/provider/notification_slack_channel_resource.go

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ type slackChannelResource struct {
2828
}
2929

3030
type slackChannelResourceModel struct {
31-
ID types.String `tfsdk:"id"`
32-
Name types.String `tfsdk:"name"`
33-
Enabled types.Bool `tfsdk:"enabled"`
34-
SpaceID types.String `tfsdk:"space_id"`
35-
RoomsID types.List `tfsdk:"rooms_id"`
36-
Alarms types.String `tfsdk:"alarms"`
37-
IntegrationID types.String `tfsdk:"integration_id"`
38-
WebhookURL types.String `tfsdk:"webhook_url"`
31+
ID types.String `tfsdk:"id"`
32+
Name types.String `tfsdk:"name"`
33+
Enabled types.Bool `tfsdk:"enabled"`
34+
SpaceID types.String `tfsdk:"space_id"`
35+
RoomsID types.List `tfsdk:"rooms_id"`
36+
Alarms types.String `tfsdk:"alarms"`
37+
WebhookURL types.String `tfsdk:"webhook_url"`
3938
}
4039

4140
func (s *slackChannelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
@@ -117,7 +116,6 @@ func (s *slackChannelResource) Create(ctx context.Context, req resource.CreateRe
117116
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
118117
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
119118
plan.Alarms = types.StringValue(notificationChannel.Alarms)
120-
plan.IntegrationID = types.StringValue(notificationIntegration.ID)
121119

122120
diags = resp.State.Set(ctx, plan)
123121
resp.Diagnostics.Append(diags...)
@@ -178,26 +176,15 @@ func (s *slackChannelResource) Update(ctx context.Context, req resource.UpdateRe
178176
return
179177
}
180178

181-
notificationIntegration, err := s.client.GetNotificationIntegrationByType(plan.SpaceID.ValueString(), "slack")
182-
183-
if err != nil {
184-
resp.Diagnostics.AddError(
185-
"Error Creating Slack Notification",
186-
"err: "+err.Error(),
187-
)
188-
return
189-
}
190-
191179
var roomsID []string
192180
plan.RoomsID.ElementsAs(ctx, &roomsID, false)
193181

194182
commonParams := client.NotificationChannel{
195-
ID: plan.ID.ValueString(),
196-
Name: plan.Name.ValueString(),
197-
Integration: *notificationIntegration,
198-
Rooms: roomsID,
199-
Alarms: plan.Alarms.ValueString(),
200-
Enabled: plan.Enabled.ValueBool(),
183+
ID: plan.ID.ValueString(),
184+
Name: plan.Name.ValueString(),
185+
Rooms: roomsID,
186+
Alarms: plan.Alarms.ValueString(),
187+
Enabled: plan.Enabled.ValueBool(),
201188
}
202189

203190
slackParams := client.NotificationSlackChannel{
@@ -218,7 +205,6 @@ func (s *slackChannelResource) Update(ctx context.Context, req resource.UpdateRe
218205
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
219206
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
220207
plan.Alarms = types.StringValue(notificationChannel.Alarms)
221-
plan.IntegrationID = types.StringValue(notificationIntegration.ID)
222208

223209
diags = resp.State.Set(ctx, plan)
224210
resp.Diagnostics.Append(diags...)

internal/provider/notification_slack_channel_resource_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func TestAccSlackNotificationResource(t *testing.T) {
3232
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "name", "slack"),
3333
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "enabled", "true"),
3434
resource.TestCheckResourceAttrSet("netdata_notification_slack_channel.test", "space_id"),
35-
resource.TestCheckResourceAttrSet("netdata_notification_slack_channel.test", "integration_id"),
3635
resource.TestCheckResourceAttrSet("netdata_notification_slack_channel.test", "rooms_id.0"),
3736
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "alarms", "ALARMS_SETTING_ALL"),
3837
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "webhook_url", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
@@ -58,7 +57,6 @@ func TestAccSlackNotificationResource(t *testing.T) {
5857
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "name", "slack"),
5958
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "enabled", "false"),
6059
resource.TestCheckResourceAttrSet("netdata_notification_slack_channel.test", "space_id"),
61-
resource.TestCheckResourceAttrSet("netdata_notification_slack_channel.test", "integration_id"),
6260
resource.TestCheckNoResourceAttr("netdata_notification_slack_channel.test", "rooms_id.0"),
6361
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "alarms", "ALARMS_SETTING_ALL"),
6462
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "webhook_url", "https://hooks.slack.com/services/T10000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"),

internal/provider/notifications.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ func commonNotificationSchema(notificationType string) schema.Schema {
5757
),
5858
},
5959
},
60-
"integration_id": schema.StringAttribute{
61-
Description: "The ID of the notification integration",
62-
Computed: true,
63-
PlanModifiers: []planmodifier.String{
64-
stringplanmodifier.UseStateForUnknown(),
65-
},
66-
},
6760
},
6861
}
6962
}

0 commit comments

Comments
 (0)