Skip to content

Commit 445b1fa

Browse files
authored
allow importing on_call_schedule(s) and reviewer_stage(s) (#1) (GoogleCloudPlatform#1637)
1 parent a1caa77 commit 445b1fa

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

docs/opal.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ $ terraform plan # No changes. Your infrastructure matches the configuration.
6868
* `opal_resource`
6969
* `group`
7070
* `opal_group`
71+
* `on_call_schedules`
72+
* `opal_on_call_schedules`
73+
* `message_channels`
74+
* `opal_message_channels`

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ require (
349349
github.com/DataDog/datadog-api-client-go/v2 v2.11.0
350350
github.com/Myra-Security-GmbH/myrasec-go/v2 v2.28.0
351351
github.com/manicminer/hamilton v0.44.0
352+
github.com/opalsecurity/opal-go v1.0.19
352353
gopkg.in/ns1/ns1-go.v2 v2.6.5
353354
)
354355

@@ -376,7 +377,6 @@ require (
376377

377378
require (
378379
github.com/aws/aws-sdk-go-v2/service/medialive v1.24.2
379-
github.com/opalsecurity/opal-go v1.0.9
380380
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.392
381381
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.392
382382
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.392

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,8 @@ github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je4
11881188
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
11891189
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
11901190
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
1191-
github.com/opalsecurity/opal-go v1.0.9 h1:NlP3K15cpEYwtwHMnpp9TbzaLILUtcTm+OQax0a8p88=
1192-
github.com/opalsecurity/opal-go v1.0.9/go.mod h1:bzD4vZIbH+lKhsX8NJ5ISNU2Xgm2qzjj6O9G2ycj58c=
1191+
github.com/opalsecurity/opal-go v1.0.19 h1:w9JPghoq9ks3/Br/KC/9h8jiJVlY3JJ/k/imq/pMVd8=
1192+
github.com/opalsecurity/opal-go v1.0.19/go.mod h1:G7QQIi36kI3kiTl/Dp8AvLDNoui9jqFOSUthcZ0aof4=
11931193
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
11941194
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
11951195
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=

providers/opal/on_call_schedule.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package opal
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
8+
)
9+
10+
type OnCallScheduleGenerator struct {
11+
OpalService
12+
}
13+
14+
func (g *OnCallScheduleGenerator) InitResources() error {
15+
client, err := g.newClient()
16+
if err != nil {
17+
return fmt.Errorf("unable to list opal on call schedules: %v", err)
18+
}
19+
20+
onCallSchedules, _, err := client.OnCallSchedulesApi.GetOnCallSchedules(context.TODO()).Execute()
21+
if err != nil {
22+
return fmt.Errorf("unable to list opal on call schedules: %v", err)
23+
}
24+
25+
countByName := make(map[string]int)
26+
27+
for _, onCallSchedule := range onCallSchedules.OnCallSchedules {
28+
name := normalizeResourceName(*onCallSchedule.Name)
29+
if count, ok := countByName[name]; ok {
30+
countByName[name] = count + 1
31+
name = normalizeResourceName(fmt.Sprintf("%s_%d", *onCallSchedule.Name, count+1))
32+
} else {
33+
countByName[name] = 1
34+
}
35+
36+
g.Resources = append(g.Resources, terraformutils.NewSimpleResource(
37+
*onCallSchedule.OnCallScheduleId,
38+
name,
39+
"opal_on_call_schedule",
40+
"opal",
41+
[]string{},
42+
))
43+
}
44+
45+
return nil
46+
}

providers/opal/opal_provider.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,22 @@ func (p OpalProvider) GetResourceConnections() map[string]map[string][]string {
5353
"resource": {
5454
"owner": {
5555
"admin_owner_id", "id",
56-
"reviewer.id", "id",
56+
"reviewer_stage.reviewer.id", "id",
5757
},
5858
"group": {"visibility_group.id", "id"},
5959
},
6060
"group": {
6161
"owner": {
6262
"admin_owner_id", "id",
63-
"reviewer.id", "id",
63+
"reviewer_stage.reviewer.id", "id",
6464
},
6565
"group": {"visibility_group.id", "id"},
6666
"message_channel": {
6767
"audit_message_channel.id", "id",
6868
},
69+
"on_call_schedule": {
70+
"on_call_schedule.id", "id",
71+
},
6972
},
7073
"owner": {
7174
"message_channel": {
@@ -113,9 +116,10 @@ func (p *OpalProvider) InitService(serviceName string, verbose bool) error {
113116

114117
func (p *OpalProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator {
115118
return map[string]terraformutils.ServiceGenerator{
116-
"owner": &OwnerGenerator{},
117-
"resource": &ResourceGenerator{},
118-
"group": &GroupGenerator{},
119-
"message_channel": &MessageChannelGenerator{},
119+
"owner": &OwnerGenerator{},
120+
"resource": &ResourceGenerator{},
121+
"group": &GroupGenerator{},
122+
"message_channel": &MessageChannelGenerator{},
123+
"on_call_schedule": &OnCallScheduleGenerator{},
120124
}
121125
}

0 commit comments

Comments
 (0)