Skip to content

Commit 6d7298d

Browse files
authored
Merge branch 'master' into deprecate-v1-alert-resources
2 parents dff02a2 + e5fa378 commit 6d7298d

7 files changed

+31
-11
lines changed

sysdig/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const (
4848
SchemaMonitorCloudMetrics = "monitor_cloud_metrics"
4949
SchemaType = "type"
5050
SchemaInstance = "instance"
51+
SchemaVersion = "version"
5152
SchemaCloudConnectorMetadata = "cloud_connector_metadata"
5253
SchemaTrustedRoleMetadata = "trusted_role_metadata"
5354
SchemaEventBridgeMetadata = "event_bridge_metadata"

sysdig/resource_sysdig_monitor_alert_v2_form_based_prometheus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func resourceSysdigMonitorAlertV2FormBasedPrometheus() *schema.Resource {
3636
"operator": {
3737
Type: schema.TypeString,
3838
Required: true,
39-
ValidateFunc: validation.StringInSlice([]string{">", ">=", "<", "<=", "=", "!="}, false),
39+
ValidateFunc: validation.StringInSlice([]string{">", ">=", "<", "<=", "==", "!="}, false),
4040
},
4141
"threshold": {
4242
Type: schema.TypeFloat,

sysdig/resource_sysdig_monitor_alert_v2_form_based_prometheus_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func TestAccAlertV2FormBasedPrometheusTest(t *testing.T) {
2727
{
2828
Config: alertV2FormBasedPrometheusTest(rText()),
2929
},
30+
{
31+
Config: alertV2FormBasedPrometheusWithEqualOperatorTest(rText()),
32+
},
3033
{
3134
Config: alertV2FormBasedPrometheusTestWithNoData(rText()),
3235
},
@@ -77,6 +80,17 @@ resource "sysdig_monitor_alert_v2_form_based_prometheus" "sample" {
7780
`, name)
7881
}
7982

83+
func alertV2FormBasedPrometheusWithEqualOperatorTest(name string) string {
84+
return fmt.Sprintf(`
85+
resource "sysdig_monitor_alert_v2_form_based_prometheus" "sample" {
86+
name = "TERRAFORM TEST - FORM BASED PROMETHEUS %s"
87+
query = "avg_over_time(sysdig_container_cpu_used_percent{container_name=\"test\"}[59s])"
88+
operator = "=="
89+
threshold = 50
90+
}
91+
`, name)
92+
}
93+
8094
func alertV2FormBasedPrometheusTestWithNoData(name string) string {
8195
return fmt.Sprintf(`
8296
resource "sysdig_monitor_alert_v2_form_based_prometheus" "sample" {

sysdig/resource_sysdig_secure_cloud_auth_account.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ var (
3333
Type: schema.TypeString,
3434
Required: true,
3535
},
36+
SchemaVersion: {
37+
Type: schema.TypeString,
38+
Optional: true,
39+
},
3640
SchemaCloudConnectorMetadata: {
3741
Type: schema.TypeString,
3842
Optional: true,
@@ -216,9 +220,6 @@ func resourceSysdigSecureCloudauthAccountRead(ctx context.Context, data *schema.
216220

217221
cloudauthAccount, errStatus, err := client.GetCloudauthAccountSecure(ctx, data.Id())
218222
if err != nil {
219-
if strings.Contains(errStatus, "404") {
220-
return nil
221-
}
222223
return diag.Errorf("Error reading resource: %s %s", errStatus, err)
223224
}
224225

@@ -238,9 +239,6 @@ func resourceSysdigSecureCloudauthAccountUpdate(ctx context.Context, data *schem
238239

239240
existingCloudAccount, errStatus, err := client.GetCloudauthAccountSecure(ctx, data.Id())
240241
if err != nil {
241-
if strings.Contains(errStatus, "404") {
242-
return nil
243-
}
244242
return diag.Errorf("Error reading resource: %s %s", errStatus, err)
245243
}
246244

@@ -254,9 +252,6 @@ func resourceSysdigSecureCloudauthAccountUpdate(ctx context.Context, data *schem
254252

255253
_, errStatus, err = client.UpdateCloudauthAccountSecure(ctx, data.Id(), newCloudAccount)
256254
if err != nil {
257-
if strings.Contains(errStatus, "404") {
258-
return nil
259-
}
260255
return diag.Errorf("Error updating resource: %s %s", errStatus, err)
261256
}
262257

@@ -382,6 +377,8 @@ func constructAccountComponents(data *schema.ResourceData) []*cloudauth.AccountC
382377
component.Type = cloudauth.Component(cloudauth.Component_value[value.(string)])
383378
case SchemaInstance:
384379
component.Instance = value.(string)
380+
case SchemaVersion:
381+
component.Version = value.(string)
385382
case SchemaCloudConnectorMetadata:
386383
component.Metadata = &cloudauth.AccountComponent_CloudConnectorMetadata{CloudConnectorMetadata: &cloudauth.CloudConnectorMetadata{}}
387384
err = protojson.Unmarshal([]byte(value.(string)), component.GetCloudConnectorMetadata())
@@ -493,6 +490,7 @@ func componentsToResourceData(components []*cloudauth.AccountComponent) []map[st
493490
resourceData := map[string]interface{}{}
494491
resourceData[SchemaType] = component.GetType().String()
495492
resourceData[SchemaInstance] = component.GetInstance()
493+
resourceData[SchemaVersion] = component.GetVersion()
496494

497495
switch component.GetType() {
498496
case cloudauth.Component_COMPONENT_CLOUD_CONNECTOR:

sysdig/resource_sysdig_secure_cloud_auth_account_component.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func cloudauthAccountComponentFromResourceData(data *schema.ResourceData) *v2.Cl
175175
AccountComponent: cloudauth.AccountComponent{
176176
Type: cloudauth.Component(cloudauth.Component_value[data.Get(SchemaType).(string)]),
177177
Instance: data.Get(SchemaInstance).(string),
178+
Version: data.Get(SchemaVersion).(string),
178179
},
179180
}
180181
// XXX: naive but simple approach to read resource data, and check for the metadata schema type passed (only one of the types will be passed)
@@ -243,6 +244,11 @@ func cloudauthAccountComponentToResourceData(data *schema.ResourceData, cloudAcc
243244
return err
244245
}
245246

247+
err = data.Set(SchemaVersion, cloudAccountComponent.GetVersion())
248+
if err != nil {
249+
return err
250+
}
251+
246252
// XXX: naive but simple approach to read accountComponent object from cloudauth, and check for the metadata proto type (only one of the types will be returned)
247253
// then, populate the respective appropriate metadata schema in resource data.
248254
switch cloudAccountComponent.GetType() {

sysdig/resource_sysdig_secure_cloud_auth_account_component_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ resource "sysdig_secure_cloud_auth_account_component" "azure_service_principal"
7171
account_id = sysdig_secure_cloud_auth_account.azure_sample.id
7272
type = "COMPONENT_SERVICE_PRINCIPAL"
7373
instance = "secure-posture"
74+
version = "v1.0.0"
7475
service_principal_metadata = jsonencode({
7576
azure = {
7677
active_directory_service_principal = {

website/docs/r/monitor_alert_v2_form_based_prometheus.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ By defining this field, the user can add link to notifications.
7474
### Form Based Prometheus alert arguments
7575

7676
* `query` - (Required) PromQL-based metric expression to alert on. Example: `sysdig_host_memory_available_bytes / sysdig_host_memory_total_bytes * 100` or `avg_over_time(sysdig_container_cpu_used_percent{}[59s])`.
77-
* `operator` - (Required) Operator for the condition to alert on. It can be `>`, `>=`, `<`, `<=`, `=` or `!=`.
77+
* `operator` - (Required) Operator for the condition to alert on. It can be `>`, `>=`, `<`, `<=`, `==` or `!=`.
7878
* `threshold` - (Required) Threshold used together with `op` to trigger the alert if crossed.
7979
* `warning_threshold` - (Optional) Warning threshold used together with `op` to trigger the alert if crossed. Must be a number that triggers the alert before reaching the main `threshold`.
8080
* `no_data_behaviour` - (Optional) behaviour in case of missing data. Can be `DO_NOTHING`, i.e. ignore, or `TRIGGER`, i.e. notify on main threshold. Default: `DO_NOTHING`.

0 commit comments

Comments
 (0)