-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SquadcastHub/squadcast-terraformer
Added squadcast terraformer
- Loading branch information
Showing
14 changed files
with
783 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cmd | ||
|
||
import ( | ||
squadcast_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/squadcast" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newCmdSquadcastImporter(options ImportOptions) *cobra.Command { | ||
var refreshToken, teamName, region string | ||
|
||
cmd := &cobra.Command{ | ||
Use: "squadcast", | ||
Short: "Import current state to Terraform configuration from Squadcast", | ||
Long: "Import current state to Terraform configuration from Squadcast", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
provider := newSquadcastProvider() | ||
options.PathPattern += region + "/" | ||
err := Import(provider, options, []string{refreshToken, region, teamName}) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
cmd.AddCommand(listCmd(newSquadcastProvider())) | ||
baseProviderFlags(cmd.PersistentFlags(), &options, "user", "") | ||
cmd.PersistentFlags().StringVarP(&refreshToken, "refresh-token", "", "", "YOUR_SQUADCAST_REFRESH_TOKEN or env param SQUADCAST_REFRESH_TOKEN") | ||
cmd.PersistentFlags().StringVarP(®ion, "region", "", "", "eu or us") | ||
cmd.PersistentFlags().StringVarP(&teamName, "team-name", "", "", "Squadcast team name") | ||
return cmd | ||
} | ||
|
||
func newSquadcastProvider() terraformutils.ProviderGenerator { | ||
return &squadcast_terraforming.SquadcastProvider{} | ||
} |
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,76 @@ | ||
# Use with Squadcast | ||
|
||
Syntax: | ||
|
||
`export SQUADCAST_REFRESH_TOKEN=<YOUR_SQUADCAST_REFRESH_TOKEN>` | ||
|
||
OR | ||
|
||
Add `--refresh-token` flag in cmd | ||
|
||
|
||
``` | ||
terraformer import squadcast --resources=<SERVICE_NAMES> --region=SQUADCAST_REGION | ||
``` | ||
|
||
Examples: | ||
|
||
- `Import Resource by providing refresh-token as a flag` | ||
|
||
``` | ||
terraformer import squadcast --resources=team --region=us --team-name="Default Team" --refresh-token=YOUR_REFRESH_TOKEN | ||
``` | ||
|
||
- `Import User Resource` | ||
|
||
``` | ||
terraformer import squadcast --resources=user --region=us | ||
``` | ||
|
||
- `Import Squad Resource` | ||
|
||
``` | ||
terraformer import squadcast --resources=team --region=us --team-name="Default Team" | ||
``` | ||
|
||
|
||
|
||
### Flags: | ||
|
||
- `--team-name` | ||
|
||
- Required for the following resources: | ||
- squad | ||
- service | ||
- escalation_policy | ||
- team_member | ||
- team_roles | ||
- slo | ||
- runbook | ||
|
||
- `--region` | ||
|
||
- Supported Values: | ||
- `us` | ||
- `eu` | ||
|
||
### Supported resources: | ||
|
||
- `user` | ||
- [squadcast_user](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/user) | ||
- `team` | ||
- [squadcast_team](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/team) | ||
- `team_member` | ||
- [squadcast_team_member](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/team_member) | ||
- `team_roles` | ||
- [squadcast_team_roles](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/team_roles) | ||
- `squad` | ||
- [squadcast_squad](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/squad) | ||
- `service` | ||
- [squadcast_service](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/service) | ||
- `escalation_policy` | ||
- [squadcast_escalation_policy](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/escalation_policy) | ||
- `runbook` | ||
- [squadcast_runbook](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/runbook) | ||
- `slo` | ||
- [squadcast_slo](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/slo) |
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,51 @@ | ||
package squadcast | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
) | ||
|
||
type EscalationPolicyGenerator struct { | ||
SquadcastService | ||
} | ||
|
||
type EscalationPolicy struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func (g *EscalationPolicyGenerator) createResources(policies []EscalationPolicy) []terraformutils.Resource { | ||
var resourceList []terraformutils.Resource | ||
for _, policy := range policies { | ||
resourceList = append(resourceList, terraformutils.NewResource( | ||
policy.ID, | ||
fmt.Sprintf("policy_%s", policy.Name), | ||
"squadcast_escalation_policy", | ||
g.GetProviderName(), | ||
map[string]string{ | ||
"team_id": g.Args["team_id"].(string), | ||
}, | ||
[]string{}, | ||
map[string]interface{}{}, | ||
)) | ||
} | ||
|
||
return resourceList | ||
} | ||
|
||
func (g *EscalationPolicyGenerator) InitResources() error { | ||
teamID := g.Args["team_id"].(string) | ||
if teamID == "" { | ||
return errors.New("--team-name is required") | ||
} | ||
getEscalationPolicyURL := fmt.Sprintf("/v3/escalation-policies?owner_id=%s", teamID) | ||
response, err := Request[[]EscalationPolicy](getEscalationPolicyURL, g.Args["access_token"].(string), g.Args["region"].(string), true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
g.Resources = g.createResources(*response) | ||
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,51 @@ | ||
// service resource is yet to be implemented | ||
|
||
package squadcast | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
) | ||
|
||
type RunbookGenerator struct { | ||
SquadcastService | ||
} | ||
|
||
type Runbook struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func (g *RunbookGenerator) createResources(runbooks []Runbook) []terraformutils.Resource { | ||
var runbookList []terraformutils.Resource | ||
for _, runbook := range runbooks { | ||
runbookList = append(runbookList, terraformutils.NewResource( | ||
runbook.ID, | ||
fmt.Sprintf("runbook_%s", runbook.Name), | ||
"squadcast_runbook", | ||
g.GetProviderName(), | ||
map[string]string{ | ||
"team_id": g.Args["team_id"].(string), | ||
}, | ||
[]string{}, | ||
map[string]interface{}{}, | ||
)) | ||
} | ||
return runbookList | ||
} | ||
|
||
func (g *RunbookGenerator) InitResources() error { | ||
if g.Args["team_id"].(string) == "" { | ||
return errors.New("--team-name is required") | ||
} | ||
getRunbooksURL := "/v3/runbooks" | ||
response, err := Request[[]Runbook](getRunbooksURL, g.Args["access_token"].(string), g.Args["region"].(string), true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
g.Resources = g.createResources(*response) | ||
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,51 @@ | ||
// service resource is yet to be implemented | ||
|
||
package squadcast | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
) | ||
|
||
type ServiceGenerator struct { | ||
SquadcastService | ||
} | ||
|
||
type Service struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func (g *ServiceGenerator) createResources(services []Service) []terraformutils.Resource { | ||
var serviceList []terraformutils.Resource | ||
for _, service := range services { | ||
serviceList = append(serviceList, terraformutils.NewResource( | ||
service.ID, | ||
fmt.Sprintf("service_%s", service.Name), | ||
"squadcast_service", | ||
g.GetProviderName(), | ||
map[string]string{ | ||
"team_id": g.Args["team_id"].(string), | ||
}, | ||
[]string{}, | ||
map[string]interface{}{}, | ||
)) | ||
} | ||
return serviceList | ||
} | ||
|
||
func (g *ServiceGenerator) InitResources() error { | ||
if g.Args["team_id"].(string) == "" { | ||
return errors.New("--team-name is required") | ||
} | ||
getServicesURL := "/v3/services" | ||
response, err := Request[[]Service](getServicesURL, g.Args["access_token"].(string), g.Args["region"].(string), true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
g.Resources = g.createResources(*response) | ||
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,56 @@ | ||
// service resource is yet to be implemented | ||
|
||
package squadcast | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
) | ||
|
||
type SLOGenerator struct { | ||
SquadcastService | ||
} | ||
|
||
type SLO struct { | ||
ID int `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type getSLOsResponse struct { | ||
SLOs *[]SLO `json:"slos"` | ||
} | ||
|
||
func (g *SLOGenerator) createResources(slo []SLO) []terraformutils.Resource { | ||
var SLOList []terraformutils.Resource | ||
for _, s := range slo { | ||
SLOList = append(SLOList, terraformutils.NewResource( | ||
fmt.Sprintf("%d", s.ID), | ||
fmt.Sprintf("slo_%s", s.Name), | ||
"squadcast_slo", | ||
g.GetProviderName(), | ||
map[string]string{ | ||
"team_id": g.Args["team_id"].(string), | ||
}, | ||
[]string{}, | ||
map[string]interface{}{}, | ||
)) | ||
} | ||
return SLOList | ||
} | ||
|
||
func (g *SLOGenerator) InitResources() error { | ||
teamID := g.Args["team_id"].(string) | ||
if teamID == "" { | ||
return errors.New("--team-name is required") | ||
} | ||
getSLOsURL := fmt.Sprintf("/v3/slo?owner_id=%s", teamID) | ||
response, err := Request[getSLOsResponse](getSLOsURL, g.Args["access_token"].(string), g.Args["region"].(string), true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
g.Resources = g.createResources(*response.SLOs) | ||
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,51 @@ | ||
package squadcast | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/GoogleCloudPlatform/terraformer/terraformutils" | ||
) | ||
|
||
type SquadGenerator struct { | ||
SquadcastService | ||
} | ||
|
||
type Squad struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func (g *SquadGenerator) createResources(squads []Squad) []terraformutils.Resource { | ||
var resources []terraformutils.Resource | ||
for _, squad := range squads { | ||
resources = append(resources, terraformutils.NewResource( | ||
squad.ID, | ||
fmt.Sprintf("squad_%s", squad.Name), | ||
"squadcast_squad", | ||
g.GetProviderName(), | ||
map[string]string{ | ||
"team_id": g.Args["team_id"].(string), | ||
"name": squad.Name, | ||
}, | ||
[]string{}, | ||
map[string]interface{}{}, | ||
)) | ||
} | ||
return resources | ||
} | ||
|
||
func (g *SquadGenerator) InitResources() error { | ||
teamID := g.Args["team_id"].(string) | ||
if teamID == "" { | ||
return errors.New("--team-name is required") | ||
} | ||
getSquadsURL := fmt.Sprintf("/v3/squads?owner_id=%s", teamID) | ||
response, err := Request[[]Squad](getSquadsURL, g.Args["access_token"].(string), g.Args["region"].(string), true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
g.Resources = g.createResources(*response) | ||
return nil | ||
} |
Oops, something went wrong.