Skip to content

Commit

Permalink
Merge pull request #6 from SquadcastHub/feat/add-new-resources
Browse files Browse the repository at this point in the history
Feat/add new resources
  • Loading branch information
mohammadmuazam authored May 21, 2024
2 parents 59d3bcc + 2433691 commit ba8014c
Show file tree
Hide file tree
Showing 28 changed files with 1,085 additions and 85 deletions.
34 changes: 29 additions & 5 deletions docs/squadcast.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ Syntax:

`export SQUADCAST_REFRESH_TOKEN=<YOUR_SQUADCAST_REFRESH_TOKEN>`

OR
OR

Add `--refresh-token` flag in cmd


```
terraformer import squadcast --resources=<SERVICE_NAMES> --region=SQUADCAST_REGION
```
Expand All @@ -35,6 +34,7 @@ terraformer import squadcast --resources=team --region=us --team-name="Default T

- `Import Deduplication Rules Resource` (without `--service-name` flag)
- Deduplication Rules for all the services under Default Team will be generated.

```
terraformer import squadcast --resources=deduplication_rules --region=us --team-name="Default Team"
```
Expand All @@ -48,20 +48,21 @@ terraformer import squadcast --resources=deduplication_rules --region=us --team-

### In order to use terraform files:

- Update version and add source in `provider.tf`
- Update version and add source in `provider.tf`
- Go to `/generated/squadcast/<RESOURCE>/<REGION>/provider.tf`
- Add `source = "SquadcastHub/squadcast"` to squadcast inside `required_providers`
- Update `version` in `required_providers` by removing `.exe` (Windows users only)
- Update `terraform_version`
- `cd /generated/squadcast/<RESOURCE>/<REGION>`
- `terraform state replace-provider -auto-approve "registry.terraform.io/-/squadcast" "SquadcastHub/squadcast"`

### Example:

```
terraform {
required_providers {
squadcast = {
version = "~> 1.0.5"
version = "~> 2.0.1"
source = "SquadcastHub/squadcast"
}
}
Expand All @@ -71,6 +72,7 @@ terraform {
### Flags:

- `--team-name`

- Required for the following resources:
- deduplication_rules
- escalation_policy
Expand All @@ -84,18 +86,30 @@ terraform {
- team_member
- team_roles
- user
- webform
- schedules_v2
- global_event_rules
- status_pages
- status_page_components
- status_page_groups

- `--region`

- Supported Values:
- `us`
- `eu`

- `--service-name` (optional)

- Supported for the following resources:
- deduplication_rules
- routing_rules
- suppression_rules
- tagging_rules
- deduplication_rules_v2
- routing_rules_v2
- suppression_rules_v2
- tagging_rules_v2
- If service name is not provided, resources for specified automation rule for all the service within the specified team will be generated. However it will only generate for a specific service when this flag is used. [see examples](squadcast.md:36)

- `--refresh-token` (optional)
Expand All @@ -105,15 +119,25 @@ terraform {
### Supported resources:

- [`deduplication_rules`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/deduplication_rules)
- [`deduplication_rule_v2`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/deduplication_rule_v2)
- [`escalation_policy`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/escalation_policy)
- [`routing_rules`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/routing_rules)
- [`routing_rule_v2`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/routing_rule_v2)
- [`runbook`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/runbook)
- [`service`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/service)
- [`slo`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/slo)
- [`squad`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/squad)
- [`suppression_rules`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/suppression_rules)
- [`suppression_rule_v2`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/suppression_rule_v2)
- [`tagging_rules`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/tagging_rules)
- [`tagging_rule_v2`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/tagging_rule_v2)
- [`team`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/team)
- [`team_member`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/team_member)
- [`team_roles`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/team_role)
- [`user`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/user)
- [`webforms`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/webform)
- [`status_pages`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/status_page)
- [`status_page_components`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/status_page_component)
- [`status_page_groups`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/status_page_group)
- [`global_event_rules`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/ger)
- [`schedules_v2`](https://registry.terraform.io/providers/SquadcastHub/squadcast/latest/docs/resources/schedule_v2)
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/jsonapi v1.0.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down Expand Up @@ -389,11 +389,13 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
nhooyr.io/websocket v1.8.10 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
)

require (
github.com/gofrs/uuid/v3 v3.1.2
github.com/hasura/go-graphql-client v0.12.1
github.com/ionos-cloud/sdk-go-cert-manager v1.0.0
github.com/ionos-cloud/sdk-go-container-registry v1.0.0
github.com/ionos-cloud/sdk-go-dataplatform v1.0.1
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,8 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
github.com/googleapis/enterprise-certificate-proxy v0.1.0/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
github.com/googleapis/enterprise-certificate-proxy v0.2.0/go.mod h1:8C0jb7/mgJe/9KK8Lm7X9ctZC2t60YyIpYEI16jx0Qg=
Expand Down Expand Up @@ -1036,6 +1038,8 @@ github.com/hashicorp/vault v0.10.4/go.mod h1:KfSyffbKxoVyspOdlaGVjIuwLobi07qD1bA
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 h1:xixZ2bWeofWV68J+x6AzmKuVM/JWCQwkWm6GW/MUR6I=
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hasura/go-graphql-client v0.12.1 h1:tL+BCoyubkYYyaQ+tJz+oPe/pSxYwOJHwe5SSqqi6WI=
github.com/hasura/go-graphql-client v0.12.1/go.mod h1:F4N4kR6vY8amio3gEu3tjSZr8GPOXJr3zj72DKixfLE=
github.com/heimweh/go-pagerduty v0.0.0-20210930203304-530eff2acdc6 h1:/D0VtHEOCdotE1vSB9XznceAjIGkUieZ4BF6VKUIqNU=
github.com/heimweh/go-pagerduty v0.0.0-20210930203304-530eff2acdc6/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w=
github.com/heroku/heroku-go/v5 v5.4.1 h1:J1nNnR3/571b2iUDHl+y1B3VkhKm6YOXIq9GGzQUv5s=
Expand Down Expand Up @@ -2416,6 +2420,8 @@ k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42/go.mod h1:Z/45zLw8lUo4wdi
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
Expand Down
27 changes: 21 additions & 6 deletions providers/squadcast/deduplication_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,39 @@ func (g *DeduplicationRulesGenerator) createResources(deduplicationRules Dedupli

func (g *DeduplicationRulesGenerator) InitResources() error {
if len(g.Args["service_name"].(string)) == 0 {
getServicesURL := "/v3/services"
responseService, err := Request[[]Service](getServicesURL, g.Args["access_token"].(string), g.Args["region"].(string), true)
req := TRequest{
URL: "/v3/services",
AccessToken: g.Args["access_token"].(string),
Region: g.Args["region"].(string),
IsAuthenticated: true,
}
responseService, _, err := Request[[]Service](req)
if err != nil {
return err
}

for _, service := range *responseService {
getDeduplicationRulesURL := fmt.Sprintf("/v3/services/%s/deduplication-rules", service.ID)
response, err := Request[DeduplicationRules](getDeduplicationRulesURL, g.Args["access_token"].(string), g.Args["region"].(string), true)
req := TRequest{
URL: fmt.Sprintf("/v3/services/%s/deduplication-rules", service.ID),
AccessToken: g.Args["access_token"].(string),
Region: g.Args["region"].(string),
IsAuthenticated: true,
}
response, _, err := Request[DeduplicationRules](req)
if err != nil {
return err
}

g.Resources = append(g.Resources, g.createResources(*response)...)
}
} else {
getDeduplicationRulesURL := fmt.Sprintf("/v3/services/%s/deduplication-rules", g.Args["service_id"])
response, err := Request[DeduplicationRules](getDeduplicationRulesURL, g.Args["access_token"].(string), g.Args["region"].(string), true)
req := TRequest{
URL: fmt.Sprintf("/v3/services/%s/deduplication-rules", g.Args["service_id"]),
AccessToken: g.Args["access_token"].(string),
Region: g.Args["region"].(string),
IsAuthenticated: true,
}
response, _, err := Request[DeduplicationRules](req)
if err != nil {
return err
}
Expand Down
79 changes: 79 additions & 0 deletions providers/squadcast/deduplocation_rules_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package squadcast

import (
"fmt"
"strings"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
)

type DeduplicationRuleGenerator struct {
SCService
}

func (g *DeduplicationRuleGenerator) createResources(deduplicationRulesV2 DeduplicationRules) []terraformutils.Resource {
var resourceList []terraformutils.Resource
for _, rule := range deduplicationRulesV2.Rules {
resourceList = append(resourceList, terraformutils.NewResource(
rule.ID,
fmt.Sprintf("deduplication_rule_v2_%s", rule.ID),
"squadcast_deduplication_rule_v2",
g.GetProviderName(),
map[string]string{
"team_id": g.Args["team_id"].(string),
"service_id": deduplicationRulesV2.ServiceID,
},
[]string{},
map[string]interface{}{},
))
}
return resourceList
}

func (g *DeduplicationRuleGenerator) InitResources() error {
if len(g.Args["service_name"].(string)) == 0 {
getServicesURL := "/v3/services"
if strings.TrimSpace(g.Args["team_id"].(string)) != "" {
getServicesURL = fmt.Sprintf("/v3/services?owner_id=%s", g.Args["team_id"].(string))
}
req := TRequest{
URL: getServicesURL,
AccessToken: g.Args["access_token"].(string),
Region: g.Args["region"].(string),
IsAuthenticated: true,
}
responseService, _, err := Request[[]Service](req)
if err != nil {
return err
}

for _, service := range *responseService {
req := TRequest{
URL: fmt.Sprintf("/v3/services/%s/deduplication-rules", service.ID),
AccessToken: g.Args["access_token"].(string),
Region: g.Args["region"].(string),
IsAuthenticated: true,
}
response, _, err := Request[DeduplicationRules](req)
if err != nil {
return err
}

g.Resources = append(g.Resources, g.createResources(*response)...)
}
} else {
req := TRequest{
URL: fmt.Sprintf("/v3/services/%s/deduplication-rules", g.Args["service_id"]),
AccessToken: g.Args["access_token"].(string),
Region: g.Args["region"].(string),
IsAuthenticated: true,
}
response, _, err := Request[DeduplicationRules](req)
if err != nil {
return err
}

g.Resources = g.createResources(*response)
}
return nil
}
10 changes: 8 additions & 2 deletions providers/squadcast/escalation_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ func (g *EscalationPolicyGenerator) createResources(policies []EscalationPolicy)
}

func (g *EscalationPolicyGenerator) InitResources() error {
getEscalationPolicyURL := fmt.Sprintf("/v3/escalation-policies?owner_id=%s", g.Args["team_id"].(string))
response, err := Request[[]EscalationPolicy](getEscalationPolicyURL, g.Args["access_token"].(string), g.Args["region"].(string), true)
req := TRequest{
URL: fmt.Sprintf("/v3/escalation-policies?owner_id=%s", g.Args["team_id"].(string)),
AccessToken: g.Args["access_token"].(string),
Region: g.Args["region"].(string),
IsAuthenticated: true,
}

response, _, err := Request[[]EscalationPolicy](req)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit ba8014c

Please sign in to comment.