Skip to content

Commit

Permalink
Merge pull request #50 from netdata/fix/notification-integration-api
Browse files Browse the repository at this point in the history
fix: remove extra integration_id resource attribute
  • Loading branch information
witalisoft authored Dec 19, 2024
2 parents 41197ce + 0658e71 commit 6c001e3
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 90 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.2.1

BUGFIXES:

- the `integration_id` attribute is being removed because it is internally used for the create resource only and
doesn't bring much value to store it

## 0.2.0

FEATURES:
Expand Down
1 change: 0 additions & 1 deletion docs/resources/notification_discord_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ resource "netdata_notification_discord_channel" "test" {
### Read-Only

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

## Import

Expand Down
1 change: 0 additions & 1 deletion docs/resources/notification_pagerduty_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ resource "netdata_notification_pagerduty_channel" "test" {
### Read-Only

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

## Import

Expand Down
1 change: 0 additions & 1 deletion docs/resources/notification_slack_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ resource "netdata_notification_slack_channel" "test" {
### Read-Only

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

## Import

Expand Down
7 changes: 3 additions & 4 deletions internal/client/notification_discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ func (c *Client) UpdateDiscordChannelByID(spaceID string, commonParams Notificat
}

reqBody := notificationRequestPayload{
Name: commonParams.Name,
IntegrationID: commonParams.Integration.ID,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
Name: commonParams.Name,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
}

secretsJson, err := json.Marshal(discordParams)
Expand Down
7 changes: 3 additions & 4 deletions internal/client/notification_pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ func (c *Client) UpdatePagerdutyChannelByID(spaceID string, commonParams Notific
}

reqBody := notificationRequestPayload{
Name: commonParams.Name,
IntegrationID: commonParams.Integration.ID,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
Name: commonParams.Name,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
}

secretsJson, err := json.Marshal(pagerdutyParams)
Expand Down
7 changes: 3 additions & 4 deletions internal/client/notification_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ func (c *Client) UpdateSlackChannelByID(spaceID string, commonParams Notificatio
}

reqBody := notificationRequestPayload{
Name: commonParams.Name,
IntegrationID: commonParams.Integration.ID,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
Name: commonParams.Name,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
}
secretsJson, err := json.Marshal(slackParams)
if err != nil {
Expand Down
23 changes: 5 additions & 18 deletions internal/provider/notification_discord_channel_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type discordChannelResourceModel struct {
SpaceID types.String `tfsdk:"space_id"`
RoomsID types.List `tfsdk:"rooms_id"`
Alarms types.String `tfsdk:"alarms"`
IntegrationID types.String `tfsdk:"integration_id"`
WebhookURL types.String `tfsdk:"webhook_url"`
ChannelType types.String `tfsdk:"channel_type"`
ChannelThread types.String `tfsdk:"channel_thread"`
Expand Down Expand Up @@ -152,7 +151,6 @@ func (s *discordChannelResource) Create(ctx context.Context, req resource.Create
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
plan.Alarms = types.StringValue(notificationChannel.Alarms)
plan.IntegrationID = types.StringValue(notificationIntegration.ID)

diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
Expand Down Expand Up @@ -226,25 +224,15 @@ func (s *discordChannelResource) Update(ctx context.Context, req resource.Update
return
}

notificationIntegration, err := s.client.GetNotificationIntegrationByType(plan.SpaceID.ValueString(), "discord")
if err != nil {
resp.Diagnostics.AddError(
"Error Creating Discord Notification",
"err: "+err.Error(),
)
return
}

var roomsID []string
plan.RoomsID.ElementsAs(ctx, &roomsID, false)

commonParams := client.NotificationChannel{
ID: plan.ID.ValueString(),
Name: plan.Name.ValueString(),
Integration: *notificationIntegration,
Rooms: roomsID,
Alarms: plan.Alarms.ValueString(),
Enabled: plan.Enabled.ValueBool(),
ID: plan.ID.ValueString(),
Name: plan.Name.ValueString(),
Rooms: roomsID,
Alarms: plan.Alarms.ValueString(),
Enabled: plan.Enabled.ValueBool(),
}

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

diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestAccDiscordNotificationResource(t *testing.T) {
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "name", "discord"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "enabled", "true"),
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "space_id"),
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "integration_id"),
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "rooms_id.0"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "alarms", "ALARMS_SETTING_ALL"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "webhook_url", "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
Expand Down Expand Up @@ -62,7 +61,6 @@ func TestAccDiscordNotificationResource(t *testing.T) {
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "name", "discord"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "enabled", "false"),
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "space_id"),
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "integration_id"),
resource.TestCheckNoResourceAttr("netdata_notification_discord_channel.test", "rooms_id.0"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "alarms", "ALARMS_SETTING_ALL"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "webhook_url", "https://discord.com/api/webhooks/1000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
Expand Down
23 changes: 5 additions & 18 deletions internal/provider/notification_pagerduty_channel_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type pagerdutyChannelResourceModel struct {
SpaceID types.String `tfsdk:"space_id"`
RoomsID types.List `tfsdk:"rooms_id"`
Alarms types.String `tfsdk:"alarms"`
IntegrationID types.String `tfsdk:"integration_id"`
AlertEventsURL types.String `tfsdk:"alert_events_url"`
IntegrationKey types.String `tfsdk:"integration_key"`
}
Expand Down Expand Up @@ -124,7 +123,6 @@ func (s *pagerdutyChannelResource) Create(ctx context.Context, req resource.Crea
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
plan.Alarms = types.StringValue(notificationChannel.Alarms)
plan.IntegrationID = types.StringValue(notificationIntegration.ID)

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

notificationIntegration, err := s.client.GetNotificationIntegrationByType(plan.SpaceID.ValueString(), "pagerduty")
if err != nil {
resp.Diagnostics.AddError(
"Error Creating Pagerduty Notification",
"err: "+err.Error(),
)
return
}

var roomsID []string
plan.RoomsID.ElementsAs(ctx, &roomsID, false)

commonParams := client.NotificationChannel{
ID: plan.ID.ValueString(),
Name: plan.Name.ValueString(),
Integration: *notificationIntegration,
Rooms: roomsID,
Alarms: plan.Alarms.ValueString(),
Enabled: plan.Enabled.ValueBool(),
ID: plan.ID.ValueString(),
Name: plan.Name.ValueString(),
Rooms: roomsID,
Alarms: plan.Alarms.ValueString(),
Enabled: plan.Enabled.ValueBool(),
}

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

diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestAccPagerdutyNotificationResource(t *testing.T) {
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "name", "pagerduty"),
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "enabled", "true"),
resource.TestCheckResourceAttrSet("netdata_notification_pagerduty_channel.test", "space_id"),
resource.TestCheckResourceAttrSet("netdata_notification_pagerduty_channel.test", "integration_id"),
resource.TestCheckResourceAttrSet("netdata_notification_pagerduty_channel.test", "rooms_id.0"),
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "alarms", "ALARMS_SETTING_ALL"),
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "alert_events_url", "https://events.pagerduty.com/v2/enqueue"),
Expand Down Expand Up @@ -61,7 +60,6 @@ func TestAccPagerdutyNotificationResource(t *testing.T) {
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "name", "pagerduty"),
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "enabled", "false"),
resource.TestCheckResourceAttrSet("netdata_notification_pagerduty_channel.test", "space_id"),
resource.TestCheckResourceAttrSet("netdata_notification_pagerduty_channel.test", "integration_id"),
resource.TestCheckNoResourceAttr("netdata_notification_pagerduty_channel.test", "rooms_id.0"),
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "alarms", "ALARMS_SETTING_ALL"),
resource.TestCheckResourceAttr("netdata_notification_pagerduty_channel.test", "alert_events_url", "https://events.pagerduty.com/v2/enqueue"),
Expand Down
38 changes: 12 additions & 26 deletions internal/provider/notification_slack_channel_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ type slackChannelResource struct {
}

type slackChannelResourceModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Enabled types.Bool `tfsdk:"enabled"`
SpaceID types.String `tfsdk:"space_id"`
RoomsID types.List `tfsdk:"rooms_id"`
Alarms types.String `tfsdk:"alarms"`
IntegrationID types.String `tfsdk:"integration_id"`
WebhookURL types.String `tfsdk:"webhook_url"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Enabled types.Bool `tfsdk:"enabled"`
SpaceID types.String `tfsdk:"space_id"`
RoomsID types.List `tfsdk:"rooms_id"`
Alarms types.String `tfsdk:"alarms"`
WebhookURL types.String `tfsdk:"webhook_url"`
}

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

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

notificationIntegration, err := s.client.GetNotificationIntegrationByType(plan.SpaceID.ValueString(), "slack")

if err != nil {
resp.Diagnostics.AddError(
"Error Creating Slack Notification",
"err: "+err.Error(),
)
return
}

var roomsID []string
plan.RoomsID.ElementsAs(ctx, &roomsID, false)

commonParams := client.NotificationChannel{
ID: plan.ID.ValueString(),
Name: plan.Name.ValueString(),
Integration: *notificationIntegration,
Rooms: roomsID,
Alarms: plan.Alarms.ValueString(),
Enabled: plan.Enabled.ValueBool(),
ID: plan.ID.ValueString(),
Name: plan.Name.ValueString(),
Rooms: roomsID,
Alarms: plan.Alarms.ValueString(),
Enabled: plan.Enabled.ValueBool(),
}

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

diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
Expand Down
2 changes: 0 additions & 2 deletions internal/provider/notification_slack_channel_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func TestAccSlackNotificationResource(t *testing.T) {
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "name", "slack"),
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "enabled", "true"),
resource.TestCheckResourceAttrSet("netdata_notification_slack_channel.test", "space_id"),
resource.TestCheckResourceAttrSet("netdata_notification_slack_channel.test", "integration_id"),
resource.TestCheckResourceAttrSet("netdata_notification_slack_channel.test", "rooms_id.0"),
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "alarms", "ALARMS_SETTING_ALL"),
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "webhook_url", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
Expand All @@ -58,7 +57,6 @@ func TestAccSlackNotificationResource(t *testing.T) {
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "name", "slack"),
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "enabled", "false"),
resource.TestCheckResourceAttrSet("netdata_notification_slack_channel.test", "space_id"),
resource.TestCheckResourceAttrSet("netdata_notification_slack_channel.test", "integration_id"),
resource.TestCheckNoResourceAttr("netdata_notification_slack_channel.test", "rooms_id.0"),
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "alarms", "ALARMS_SETTING_ALL"),
resource.TestCheckResourceAttr("netdata_notification_slack_channel.test", "webhook_url", "https://hooks.slack.com/services/T10000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
Expand Down
7 changes: 0 additions & 7 deletions internal/provider/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ func commonNotificationSchema(notificationType string) schema.Schema {
),
},
},
"integration_id": schema.StringAttribute{
Description: "The ID of the notification integration",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
}
}

0 comments on commit 6c001e3

Please sign in to comment.