Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

add data source alerting channel office365 #151

Merged
merged 7 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add data source alerting channel office365
  • Loading branch information
rumenvasilev committed Jul 26, 2023
commit 2e47e9781206e7427c49d1af9245e0a4b46d276d
23 changes: 23 additions & 0 deletions instana/data-source-alerting-channel-google-chat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package instana

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// NewSyntheticLocationDataSource creates a new DataSource for Synthetic Locations
func NewAlertingChannelGoogleChatDataSource() DataSource {
return &alertingChannelGoogleChatDataSource{}
}

const (
//DataSourceAlertingChannelGoogleChat the name of the terraform-provider-instana resource to manage alerting channels of type Google Chat
DataSourceAlertingChannelGoogleChat = "instana_alerting_channel_google_chat"
)

type alertingChannelGoogleChatDataSource struct{}

// CreateResource creates the resource handle Synthetic Locations
func (ds *alertingChannelGoogleChatDataSource) CreateResource() *schema.Resource {
// unimplemented
return nil
}
74 changes: 74 additions & 0 deletions instana/data-source-alerting-channel-office365.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package instana

import (
"fmt"

"github.com/gessnerfl/terraform-provider-instana/instana/restapi"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// NewSyntheticLocationDataSource creates a new DataSource for Synthetic Locations
func NewAlertingChannelOffice365DataSource() DataSource {
return &alertingChannelOffice365DataSource{}
}

const (
//DataSourceAlertingChannelOffice365 the name of the terraform-provider-instana resource to manage alerting channels of type Office 365
DataSourceAlertingChannelOffice365 = "instana_alerting_channel_office_365"
)

type alertingChannelOffice365DataSource struct{}

// CreateResource creates the resource handle Synthetic Locations
func (ds *alertingChannelOffice365DataSource) CreateResource() *schema.Resource {
return &schema.Resource{
Read: ds.read,
Schema: map[string]*schema.Schema{
AlertingChannelFieldName: {
Type: schema.TypeString,
Required: true,
Description: "The name of the alerting channel",
// TODO: What is the max length here?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No restriction defined in the API specification. Would skip also not add any validation in this case.

// ValidateFunc: validation.StringLenBetween(0, 512),
},
},
}
}

func (ds *alertingChannelOffice365DataSource) read(d *schema.ResourceData, meta interface{}) error {
providerMeta := meta.(*ProviderMeta)
instanaAPI := providerMeta.InstanaAPI

name := d.Get(AlertingChannelFieldName).(string)

data, err := instanaAPI.AlertingChannelsDS().GetAll()
if err != nil {
return err
}

alertChannel, err := ds.findAlertChannel(name, data)

if err != nil {
return err
}

return ds.updateState(d, alertChannel)
}

func (ds *alertingChannelOffice365DataSource) findAlertChannel(name string, data *[]restapi.InstanaDataObject) (*restapi.AlertingChannel, error) {
for _, e := range *data {
alertingChannel, ok := e.(*restapi.AlertingChannel)
if ok {
if alertingChannel.Name == name {
return alertingChannel, nil
}
}
}
return nil, fmt.Errorf("no alerting channel found")
}

func (ds *alertingChannelOffice365DataSource) updateState(d *schema.ResourceData, alertingChannel *restapi.AlertingChannel) error {
d.SetId(alertingChannel.ID)
d.Set(AlertingChannelFieldName, alertingChannel.Name)
return nil
}
23 changes: 23 additions & 0 deletions instana/data-source-alerting-channel-webhook-based.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package instana

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// NewSyntheticLocationDataSource creates a new DataSource for Synthetic Locations
func NewAlertingChannelWebhookBasedFieldDataSource() DataSource {
return &alertingChannelWebhookBasedFieldDataSource{}
}

const (
//DataSourceAlertingChannelWebhookBasedFieldWebhookURL const for the webhookUrl field of the alerting channel
DataSourceAlertingChannelWebhookBasedFieldWebhookURL = "webhook_url"
)

type alertingChannelWebhookBasedFieldDataSource struct{}

// CreateResource creates the resource handle Synthetic Locations
func (ds *alertingChannelWebhookBasedFieldDataSource) CreateResource() *schema.Resource {
// unimplemented
return nil
}
5 changes: 3 additions & 2 deletions instana/data-source-builtin-event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

//NewBuiltinEventDataSource creates a new DataSource for Builtin Events
// NewBuiltinEventDataSource creates a new DataSource for Builtin Events
func NewBuiltinEventDataSource() DataSource {
return &builtInEventDataSource{}
}
Expand All @@ -30,11 +30,12 @@ const (

//DataSourceBuiltinEvent the name of the terraform-provider-instana data sourcefor builtin event specifications
DataSourceBuiltinEvent = "instana_builtin_event_spec"
//
)

type builtInEventDataSource struct{}

//CreateResource creates the terraform Resource for the data source for Instana builtin events
// CreateResource creates the terraform Resource for the data source for Instana builtin events
func (ds *builtInEventDataSource) CreateResource() *schema.Resource {
return &schema.Resource{
Read: ds.read,
Expand Down
3 changes: 3 additions & 0 deletions instana/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,8 @@ func providerDataSources() map[string]*schema.Resource {
dataSources := make(map[string]*schema.Resource)
dataSources[DataSourceBuiltinEvent] = NewBuiltinEventDataSource().CreateResource()
dataSources[DataSourceSyntheticLocation] = NewSyntheticLocationDataSource().CreateResource()
// dataSources[DataSourceAlertingChannelWebhookBasedFieldWebhookURL] = NewAlertingChannelWebhookBasedFieldDataSource().CreateResource()
dataSources[DataSourceAlertingChannelOffice365] = NewAlertingChannelOffice365DataSource().CreateResource()
// dataSources[DataSourceAlertingChannelGoogleChat] = NewAlertingChannelGoogleChatDataSource().CreateResource()
return dataSources
}
6 changes: 6 additions & 0 deletions instana/restapi/Instana-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type InstanaAPI interface {
ApplicationAlertConfigs() RestResource
GlobalApplicationAlertConfigs() RestResource
AlertingChannels() RestResource
AlertingChannelsDS() ReadOnlyRestResource
AlertingConfigurations() RestResource
SliConfigs() RestResource
WebsiteMonitoringConfig() RestResource
Expand Down Expand Up @@ -87,6 +88,11 @@ func (api *baseInstanaAPI) AlertingChannels() RestResource {
return NewCreatePUTUpdatePUTRestResource(AlertingChannelsResourcePath, NewDefaultJSONUnmarshaller(&AlertingChannel{}), api.client)
}

// AlertingChannelsDS read-only implementation of InstanaAPI interface
func (api *baseInstanaAPI) AlertingChannelsDS() ReadOnlyRestResource {
return NewReadOnlyRestResource(AlertingChannelsResourcePath, NewDefaultJSONUnmarshaller(&AlertingChannel{}), NewDefaultJSONUnmarshaller(&[]AlertingChannel{}), api.client)
}

// AlertingConfigurations implementation of InstanaAPI interface
func (api *baseInstanaAPI) AlertingConfigurations() RestResource {
return NewCreatePUTUpdatePUTRestResource(AlertsResourcePath, NewDefaultJSONUnmarshaller(&AlertingConfiguration{}), api.client)
Expand Down
8 changes: 8 additions & 0 deletions mocks/Instana-api_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions mocks/data-source-alerting-channel-office365_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.