This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
add data source alerting channel office365 #151
Merged
gessnerfl
merged 7 commits into
gessnerfl:feature/datasource-alert-config-o365
from
rumenvasilev:main
Jul 29, 2023
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2e47e97
add data source alerting channel office365
rumenvasilev a3f34d4
adjust code so it doesn't panic. add documentation
rumenvasilev f45cc05
update func annotations
rumenvasilev 5c009e1
DRY code
rumenvasilev 6a158ee
correct alert-channel ds tests
rumenvasilev 32957cc
collapse helper funcs into api file
rumenvasilev c918c14
clarify details in documentation
rumenvasilev File filter
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
commit 2e47e9781206e7427c49d1af9245e0a4b46d276d
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.