Skip to content

Commit

Permalink
allow importing on_call_schedule(s) and reviewer_stage(s) (#1) (Googl…
Browse files Browse the repository at this point in the history
  • Loading branch information
giulio-opal authored May 29, 2023
1 parent a1caa77 commit 445b1fa
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/opal.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ $ terraform plan # No changes. Your infrastructure matches the configuration.
* `opal_resource`
* `group`
* `opal_group`
* `on_call_schedules`
* `opal_on_call_schedules`
* `message_channels`
* `opal_message_channels`
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ require (
github.com/DataDog/datadog-api-client-go/v2 v2.11.0
github.com/Myra-Security-GmbH/myrasec-go/v2 v2.28.0
github.com/manicminer/hamilton v0.44.0
github.com/opalsecurity/opal-go v1.0.19
gopkg.in/ns1/ns1-go.v2 v2.6.5
)

Expand Down Expand Up @@ -376,7 +377,6 @@ require (

require (
github.com/aws/aws-sdk-go-v2/service/medialive v1.24.2
github.com/opalsecurity/opal-go v1.0.9
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.392
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.392
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.392
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,8 @@ github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je4
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/opalsecurity/opal-go v1.0.9 h1:NlP3K15cpEYwtwHMnpp9TbzaLILUtcTm+OQax0a8p88=
github.com/opalsecurity/opal-go v1.0.9/go.mod h1:bzD4vZIbH+lKhsX8NJ5ISNU2Xgm2qzjj6O9G2ycj58c=
github.com/opalsecurity/opal-go v1.0.19 h1:w9JPghoq9ks3/Br/KC/9h8jiJVlY3JJ/k/imq/pMVd8=
github.com/opalsecurity/opal-go v1.0.19/go.mod h1:G7QQIi36kI3kiTl/Dp8AvLDNoui9jqFOSUthcZ0aof4=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
Expand Down
46 changes: 46 additions & 0 deletions providers/opal/on_call_schedule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package opal

import (
"context"
"fmt"

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

type OnCallScheduleGenerator struct {
OpalService
}

func (g *OnCallScheduleGenerator) InitResources() error {
client, err := g.newClient()
if err != nil {
return fmt.Errorf("unable to list opal on call schedules: %v", err)
}

onCallSchedules, _, err := client.OnCallSchedulesApi.GetOnCallSchedules(context.TODO()).Execute()
if err != nil {
return fmt.Errorf("unable to list opal on call schedules: %v", err)
}

countByName := make(map[string]int)

for _, onCallSchedule := range onCallSchedules.OnCallSchedules {
name := normalizeResourceName(*onCallSchedule.Name)
if count, ok := countByName[name]; ok {
countByName[name] = count + 1
name = normalizeResourceName(fmt.Sprintf("%s_%d", *onCallSchedule.Name, count+1))
} else {
countByName[name] = 1
}

g.Resources = append(g.Resources, terraformutils.NewSimpleResource(
*onCallSchedule.OnCallScheduleId,
name,
"opal_on_call_schedule",
"opal",
[]string{},
))
}

return nil
}
16 changes: 10 additions & 6 deletions providers/opal/opal_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ func (p OpalProvider) GetResourceConnections() map[string]map[string][]string {
"resource": {
"owner": {
"admin_owner_id", "id",
"reviewer.id", "id",
"reviewer_stage.reviewer.id", "id",
},
"group": {"visibility_group.id", "id"},
},
"group": {
"owner": {
"admin_owner_id", "id",
"reviewer.id", "id",
"reviewer_stage.reviewer.id", "id",
},
"group": {"visibility_group.id", "id"},
"message_channel": {
"audit_message_channel.id", "id",
},
"on_call_schedule": {
"on_call_schedule.id", "id",
},
},
"owner": {
"message_channel": {
Expand Down Expand Up @@ -113,9 +116,10 @@ func (p *OpalProvider) InitService(serviceName string, verbose bool) error {

func (p *OpalProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator {
return map[string]terraformutils.ServiceGenerator{
"owner": &OwnerGenerator{},
"resource": &ResourceGenerator{},
"group": &GroupGenerator{},
"message_channel": &MessageChannelGenerator{},
"owner": &OwnerGenerator{},
"resource": &ResourceGenerator{},
"group": &GroupGenerator{},
"message_channel": &MessageChannelGenerator{},
"on_call_schedule": &OnCallScheduleGenerator{},
}
}

0 comments on commit 445b1fa

Please sign in to comment.