Skip to content

Commit af3f215

Browse files
authored
feat(notificaion channel): enable all notification channels on ibm secure (#356)
1 parent adc1497 commit af3f215

File tree

39 files changed

+510
-82
lines changed

39 files changed

+510
-82
lines changed

.github/workflows/test.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Lint
1616
uses: golangci/golangci-lint-action@v2
1717
with:
18-
args: --timeout 30m --build-tags unit,tf_acc_sysdig_monitor,tf_acc_sysdig_secure,tf_acc_ibm_monitor
18+
args: --timeout 30m --build-tags unit,tf_acc_sysdig_monitor,tf_acc_sysdig_secure,tf_acc_ibm_monitor,tf_acc_ibm_secure
1919

2020
test:
2121
name: Unit Tests
@@ -105,3 +105,28 @@ jobs:
105105
SYSDIG_IBM_MONITOR_INSTANCE_ID: ${{ secrets.TERRAFORM_IBM_MONITOR_INSTANCE_ID }}
106106
SYSDIG_IBM_MONITOR_IAM_URL: "https://iam.cloud.ibm.com"
107107
SYSDIG_MONITOR_URL: "https://eu-gb.monitoring.cloud.ibm.com"
108+
109+
test-ibm-secure:
110+
name: IBM Secure Acceptance Tests
111+
runs-on: ubuntu-latest
112+
needs: test
113+
114+
steps:
115+
- name: Check out code
116+
uses: actions/checkout@v2
117+
118+
- name: Set up Go
119+
uses: actions/setup-go@v3
120+
with:
121+
go-version: ${{ env.GO_VERSION }}
122+
check-latest: true
123+
cache: true
124+
125+
- name: Test
126+
run: make testacc
127+
env:
128+
TEST_SUITE: tf_acc_ibm_secure
129+
SYSDIG_IBM_SECURE_API_KEY: ${{ secrets.TERRAFORM_IBM_API_KEY }}
130+
SYSDIG_IBM_SECURE_INSTANCE_ID: ${{ secrets.TERRAFORM_IBM_SECURE_INSTANCE_ID }}
131+
SYSDIG_IBM_SECURE_IAM_URL: "https://iam.cloud.ibm.com"
132+
SYSDIG_SECURE_URL: "https://eu-gb.monitoring.cloud.ibm.com"

sysdig/clienttype_string.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sysdig/common_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const (
1010
SysdigMonitorApiTokenEnv = "SYSDIG_MONITOR_API_TOKEN"
1111
SysdigSecureApiTokenEnv = "SYSDIG_SECURE_API_TOKEN"
1212
SysdigIBMMonitorAPIKeyEnv = "SYSDIG_IBM_MONITOR_API_KEY"
13+
SysdigIBMSecureAPIKeyEnv = "SYSDIG_IBM_SECURE_API_KEY"
1314
)
1415

1516
func isAnyEnvSet(envs ...string) bool {

sysdig/data_source_sysdig_secure_notification_channel_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
//go:build tf_acc_sysdig_secure || tf_acc_sysdig_common
1+
//go:build tf_acc_sysdig_secure || tf_acc_sysdig_common || tf_acc_ibm_secure || tf_acc_ibm_common
22

33
package sysdig_test
44

55
import (
66
"fmt"
7-
"os"
87
"testing"
98

109
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
@@ -18,11 +17,7 @@ func TestAccNotificationChannelDataSource(t *testing.T) {
1817
rText := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
1918

2019
resource.ParallelTest(t, resource.TestCase{
21-
PreCheck: func() {
22-
if v := os.Getenv("SYSDIG_SECURE_API_TOKEN"); v == "" {
23-
t.Fatal("SYSDIG_SECURE_API_TOKEN must be set for acceptance tests")
24-
}
25-
},
20+
PreCheck: preCheckAnyEnv(t, SysdigSecureApiTokenEnv, SysdigIBMSecureAPIKeyEnv),
2621
ProviderFactories: map[string]func() (*schema.Provider, error){
2722
"sysdig": func() (*schema.Provider, error) {
2823
return sysdig.Provider(), nil

sysdig/internal/client/v2/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
SysdigUserAgentHeaderValue = "SysdigTerraform"
2929
ContentTypeJSON = "application/json"
3030
ContentTypeFormURLEncoded = "x-www-form-urlencoded"
31+
SysdigProductHeader = "X-Sysdig-Product"
3132
)
3233

3334
var (

sysdig/internal/client/v2/config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ type config struct {
1010
ibmIamURL string
1111
sysdigTeamName string
1212
sysdigTeamID *int
13+
product string
1314
}
1415

16+
type Product string
17+
18+
const (
19+
MonitorProduct Product = "SDC"
20+
SecureProduct Product = "SDS"
21+
)
22+
1523
type ClientOption func(c *config)
1624

1725
func WithURL(url string) ClientOption {
@@ -68,6 +76,18 @@ func WithSysdigTeamName(teamName string) ClientOption {
6876
}
6977
}
7078

79+
func WithMonitorProduct() ClientOption {
80+
return func(c *config) {
81+
c.product = string(MonitorProduct)
82+
}
83+
}
84+
85+
func WithSecureProduct() ClientOption {
86+
return func(c *config) {
87+
c.product = string(SecureProduct)
88+
}
89+
}
90+
7191
func configure(opts ...ClientOption) *config {
7292
cfg := &config{}
7393
for _, opt := range opts {

sysdig/internal/client/v2/ibm.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
IBMAPIKeyGrantType = "urn:ibm:params:oauth:grant-type:apikey"
2121
SysdigTeamIDHeader = "SysdigTeamID"
2222
GetTeamByNamePath = "/api/v2/teams/light/name/"
23+
IBMProductHeader = "SysdigProduct"
2324
)
2425

2526
type IBMCommon interface {
@@ -31,6 +32,10 @@ type IBMMonitor interface {
3132
MonitorCommon
3233
}
3334

35+
type IBMSecure interface {
36+
IBMCommon
37+
}
38+
3439
type IBMAccessToken string
3540
type UnixTimestamp int64
3641

@@ -101,6 +106,8 @@ func (ir *IBMRequest) getTeamIDByName(ctx context.Context, name string, token IB
101106
r = r.WithContext(ctx)
102107
r.Header.Set(IBMInstanceIDHeader, ir.config.ibmInstanceID)
103108
r.Header.Set(AuthorizationHeader, fmt.Sprintf("Bearer %s", token))
109+
r.Header.Set(SysdigProductHeader, ir.config.product)
110+
r.Header.Set(IBMProductHeader, ir.config.product)
104111

105112
resp, err := request(ir.httpClient, ir.config, r)
106113
if err != nil {
@@ -143,6 +150,8 @@ func (ir *IBMRequest) CurrentTeamID(ctx context.Context) (int, error) {
143150
user, err := getMe(ctx, ir.config, ir.httpClient, map[string]string{
144151
IBMInstanceIDHeader: ir.config.ibmInstanceID,
145152
AuthorizationHeader: fmt.Sprintf("Bearer %s", token),
153+
SysdigProductHeader: ir.config.product,
154+
IBMProductHeader: ir.config.product,
146155
})
147156
if err != nil {
148157
return -1, err
@@ -179,6 +188,8 @@ func (ir *IBMRequest) Request(ctx context.Context, method string, url string, pa
179188
r.Header.Set(SysdigTeamIDHeader, strconv.Itoa(teamID))
180189
r.Header.Set(ContentTypeHeader, ContentTypeJSON)
181190
r.Header.Set(SysdigProviderHeader, SysdigProviderHeaderValue)
191+
r.Header.Set(SysdigProductHeader, ir.config.product)
192+
r.Header.Set(IBMProductHeader, ir.config.product)
182193

183194
return request(ir.httpClient, ir.config, r)
184195
}
@@ -200,3 +211,7 @@ func newIBMClient(opts ...ClientOption) *Client {
200211
func NewIBMMonitor(opts ...ClientOption) IBMMonitor {
201212
return newIBMClient(opts...)
202213
}
214+
215+
func NewIBMSecure(opts ...ClientOption) IBMSecure {
216+
return newIBMClient(opts...)
217+
}

sysdig/provider.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,31 @@ func Provider() *schema.Provider {
7272
Optional: true,
7373
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_IBM_MONITOR_API_KEY", nil),
7474
},
75+
"sysdig_secure_team_id": {
76+
Type: schema.TypeInt,
77+
Optional: true,
78+
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_SECURE_TEAM_ID", nil),
79+
},
80+
"sysdig_secure_team_name": {
81+
Type: schema.TypeString,
82+
Optional: true,
83+
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_SECURE_TEAM_NAME", nil),
84+
},
85+
"ibm_secure_iam_url": {
86+
Type: schema.TypeString,
87+
Optional: true,
88+
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_IBM_SECURE_IAM_URL", nil),
89+
},
90+
"ibm_secure_instance_id": {
91+
Type: schema.TypeString,
92+
Optional: true,
93+
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_IBM_SECURE_INSTANCE_ID", nil),
94+
},
95+
"ibm_secure_api_key": {
96+
Type: schema.TypeString,
97+
Optional: true,
98+
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_IBM_SECURE_API_KEY", nil),
99+
},
75100
},
76101
ResourcesMap: map[string]*schema.Resource{
77102
"sysdig_user": resourceSysdigUser(),

sysdig/resource_sysdig_monitor_notification_channel_email_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_common || tf_acc_ibm_monitor
1+
//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_common || tf_acc_ibm_monitor || tf_acc_ibm_common
22

33
package sysdig_test
44

sysdig/resource_sysdig_monitor_notification_channel_opsgenie_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_common || tf_acc_ibm_monitor
1+
//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_common || tf_acc_ibm_monitor || tf_acc_ibm_common
22

33
package sysdig_test
44

0 commit comments

Comments
 (0)