forked from GoogleCloudPlatform/terraformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Mackerel" as further provider (GoogleCloudPlatform#1125)
- Loading branch information
Showing
16 changed files
with
697 additions
and
0 deletions.
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
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,46 @@ | ||
// Copyright 2021 The Terraformer Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
mackerel_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/mackerel" | ||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newCmdMackerelImporter(options ImportOptions) *cobra.Command { | ||
var apiKey string | ||
cmd := &cobra.Command{ | ||
Use: "mackerel", | ||
Short: "Import current state to Terraform configuration from Mackerel", | ||
Long: "Import current state to Terraform configuration from Mackerel", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
provider := newMackerelProvider() | ||
err := Import(provider, options, []string{apiKey}) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
cmd.AddCommand(listCmd(newMackerelProvider())) | ||
baseProviderFlags(cmd.PersistentFlags(), &options, "service,role,aws_integration", "aws_integration=id1:id2:id4") | ||
cmd.PersistentFlags().StringVarP(&apiKey, "api-key", "", "", "YOUR_MACKEREL_API_KEY or env param MACKEREL_API_KEY") | ||
return cmd | ||
} | ||
|
||
func newMackerelProvider() terraformutils.ProviderGenerator { | ||
return &mackerel_terraforming.MackerelProvider{} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
### Use with Mackerel | ||
|
||
Example: | ||
|
||
```bash | ||
./terraformer import mackerel --resources=service --api-key=YOUR_MACKEREL_API_KEY // or MACKEREL_API_KEY in env --app-key=YOUR_MACKEREL_API_KEY | ||
./terraformer import mackerel --resources=service --filter=service=name1:name2:name4 --api-key=YOUR_MACKEREL_API_KEY // or MACKEREL_API_KEY in env --app-key=YOUR_MACKEREL_API_KEY | ||
./terraformer import mackerel --resources=aws_integration --filter=aws_integration=id1:id2:id4 --api-key=YOUR_MACKEREL_API_KEY // or MACKEREL_API_KEY in env --app-key=YOUR_MACKEREL_API_KEY | ||
``` | ||
|
||
List of supported Mackerel services: | ||
|
||
* `alert_group_setting` | ||
* `mackerel_alert_group_setting` | ||
* `aws_integration` | ||
* `mackerel_aws_integration` | ||
* Sensitive field `secret_key` is not generated and needs to be manually set | ||
* Sensitive field `external_id` is not generated and needs to be manually set | ||
* `channel` | ||
* `mackerel_channel` | ||
* `downtime` | ||
* `mackerel_downtime` | ||
* `monitor` | ||
* `mackerel_monitor` | ||
* `notification_group` | ||
* `mackerel_notification_group` | ||
* `role` | ||
* `mackerel_role` | ||
* `service` | ||
* `mackerel_service` |
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
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,58 @@ | ||
// Copyright 2021 The Terraformer Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mackerel | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
"github.com/mackerelio/mackerel-client-go" | ||
) | ||
|
||
// AlertGroupSettingGenerator ... | ||
type AlertGroupSettingGenerator struct { | ||
MackerelService | ||
} | ||
|
||
func (g *AlertGroupSettingGenerator) createResources(alertGroupSettings []*mackerel.AlertGroupSetting) []terraformutils.Resource { | ||
resources := []terraformutils.Resource{} | ||
for _, alertGroupSetting := range alertGroupSettings { | ||
resources = append(resources, g.createResource(alertGroupSetting.ID)) | ||
} | ||
return resources | ||
} | ||
|
||
func (g *AlertGroupSettingGenerator) createResource(alertGroupSettingID string) terraformutils.Resource { | ||
return terraformutils.NewSimpleResource( | ||
alertGroupSettingID, | ||
fmt.Sprintf("alert_group_setting_%s", alertGroupSettingID), | ||
"mackerel_alert_group_setting", | ||
"mackerel", | ||
[]string{}, | ||
) | ||
} | ||
|
||
// InitResources Generate TerraformResources from Mackerel API, | ||
// from each alert group setting create 1 TerraformResource. | ||
// Need Alert Group Setting ID as ID for terraform resource | ||
func (g *AlertGroupSettingGenerator) InitResources() error { | ||
client := g.Args["mackerelClient"].(*mackerel.Client) | ||
alertGroupSettings, err := client.FindAlertGroupSettings() | ||
if err != nil { | ||
return err | ||
} | ||
g.Resources = append(g.Resources, g.createResources(alertGroupSettings)...) | ||
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,58 @@ | ||
// Copyright 2021 The Terraformer Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mackerel | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
"github.com/mackerelio/mackerel-client-go" | ||
) | ||
|
||
// AWSIntegrationGenerator ... | ||
type AWSIntegrationGenerator struct { | ||
MackerelService | ||
} | ||
|
||
func (g *AWSIntegrationGenerator) createResources(awsIntegrations []*mackerel.AWSIntegration) []terraformutils.Resource { | ||
resources := []terraformutils.Resource{} | ||
for _, awsIntegration := range awsIntegrations { | ||
resources = append(resources, g.createResource(awsIntegration.ID)) | ||
} | ||
return resources | ||
} | ||
|
||
func (g *AWSIntegrationGenerator) createResource(awsIntegrationID string) terraformutils.Resource { | ||
return terraformutils.NewSimpleResource( | ||
awsIntegrationID, | ||
fmt.Sprintf("aws_integration_%s", awsIntegrationID), | ||
"mackerel_aws_integration", | ||
"mackerel", | ||
[]string{}, | ||
) | ||
} | ||
|
||
// InitResources Generate TerraformResources from Mackerel API, | ||
// from each aws integration create 1 TerraformResource. | ||
// Need AWS Integration ID as ID for terraform resource | ||
func (g *AWSIntegrationGenerator) InitResources() error { | ||
client := g.Args["mackerelClient"].(*mackerel.Client) | ||
awsIntegrations, err := client.FindAWSIntegrations() | ||
if err != nil { | ||
return err | ||
} | ||
g.Resources = append(g.Resources, g.createResources(awsIntegrations)...) | ||
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,75 @@ | ||
// Copyright 2021 The Terraformer Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mackerel | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
"github.com/mackerelio/mackerel-client-go" | ||
) | ||
|
||
// ChannelGenerator ... | ||
type ChannelGenerator struct { | ||
MackerelService | ||
} | ||
|
||
func (g *ChannelGenerator) createResources(channels []*mackerel.Channel) []terraformutils.Resource { | ||
resources := []terraformutils.Resource{} | ||
for _, channel := range channels { | ||
if channel.Type != "email" && channel.Type != "slack" && channel.Type != "webhook" { | ||
continue | ||
} | ||
|
||
if channel.Type == "email" { | ||
if channel.Events != nil { | ||
events := *channel.Events | ||
for _, event := range events { | ||
if event != "alert" && event != "alertGroup" { | ||
continue | ||
} | ||
} | ||
} else { | ||
continue | ||
} | ||
} | ||
|
||
resources = append(resources, g.createResource(channel.ID)) | ||
} | ||
return resources | ||
} | ||
|
||
func (g *ChannelGenerator) createResource(channelID string) terraformutils.Resource { | ||
return terraformutils.NewSimpleResource( | ||
channelID, | ||
fmt.Sprintf("channel_%s", channelID), | ||
"mackerel_channel", | ||
"mackerel", | ||
[]string{}, | ||
) | ||
} | ||
|
||
// InitResources Generate TerraformResources from Mackerel API, | ||
// from each channel create 1 TerraformResource. | ||
// Need Channel ID as ID for terraform resource | ||
func (g *ChannelGenerator) InitResources() error { | ||
client := g.Args["mackerelClient"].(*mackerel.Client) | ||
channels, err := client.FindChannels() | ||
if err != nil { | ||
return err | ||
} | ||
g.Resources = append(g.Resources, g.createResources(channels)...) | ||
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,58 @@ | ||
// Copyright 2021 The Terraformer Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mackerel | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
"github.com/mackerelio/mackerel-client-go" | ||
) | ||
|
||
// DowntimeGenerator ... | ||
type DowntimeGenerator struct { | ||
MackerelService | ||
} | ||
|
||
func (g *DowntimeGenerator) createResources(downtimes []*mackerel.Downtime) []terraformutils.Resource { | ||
resources := []terraformutils.Resource{} | ||
for _, downtime := range downtimes { | ||
resources = append(resources, g.createResource(downtime.ID)) | ||
} | ||
return resources | ||
} | ||
|
||
func (g *DowntimeGenerator) createResource(downtimeID string) terraformutils.Resource { | ||
return terraformutils.NewSimpleResource( | ||
downtimeID, | ||
fmt.Sprintf("downtime_%s", downtimeID), | ||
"mackerel_downtime", | ||
"mackerel", | ||
[]string{}, | ||
) | ||
} | ||
|
||
// InitResources Generate TerraformResources from Mackerel API, | ||
// from each downtime create 1 TerraformResource. | ||
// Need Downtime ID as ID for terraform resource | ||
func (g *DowntimeGenerator) InitResources() error { | ||
client := g.Args["mackerelClient"].(*mackerel.Client) | ||
downtimes, err := client.FindDowntimes() | ||
if err != nil { | ||
return err | ||
} | ||
g.Resources = append(g.Resources, g.createResources(downtimes)...) | ||
return nil | ||
} |
Oops, something went wrong.