Skip to content

Commit 5d341e6

Browse files
committed
Merge branch 'feature/462' of https://github.com/sysdiglabs/terraform-provider-sysdig into feature/462
2 parents 9028d6a + 170189d commit 5d341e6

30 files changed

+511
-205
lines changed

sysdig/data_source_sysdig_fargate_ECS_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func getKiltRecipe(t *testing.T) string {
4949
CollectorHost: "collector_host",
5050
CollectorPort: "collector_port",
5151
SysdigLogging: "sysdig_logging",
52+
Priority: "priority",
5253
}
5354

5455
jsonRecipeConfig, err := json.Marshal(&recipeConfig)
@@ -121,6 +122,12 @@ func TestNewPatchOptions(t *testing.T) {
121122
},
122123
},
123124
},
125+
"priority": {
126+
Type: schema.TypeString,
127+
Description: "The priority of the agent. Can be 'security' or 'availability'",
128+
Default: "availability",
129+
Optional: true,
130+
},
124131
},
125132
}
126133
}
@@ -164,13 +171,24 @@ func TestNewPatchOptions(t *testing.T) {
164171
"stream_prefix": "fried",
165172
"region": "chicken",
166173
},
167-
Essential: true,
174+
Essential: false,
168175
}
169176
actualPatchOptions := newPatchOptions(data)
170177

171178
if !reflect.DeepEqual(expectedPatchOptions, actualPatchOptions) {
172179
t.Errorf("patcConfigurations are not equal. Expected: %v, Actual: %v", expectedPatchOptions, actualPatchOptions)
173180
}
181+
182+
err = data.Set("priority", "security")
183+
if err != nil {
184+
assert.FailNow(t, fmt.Sprintf("Could not set priority, got error: %v", err))
185+
}
186+
expectedPatchOptions.Essential = true
187+
actualPatchOptions = newPatchOptions(data)
188+
189+
if !reflect.DeepEqual(expectedPatchOptions, actualPatchOptions) {
190+
t.Errorf("patcConfigurations are not equal. Expected: %v, Actual: %v", expectedPatchOptions, actualPatchOptions)
191+
}
174192
}
175193

176194
func getSidecarConfig() string {

sysdig/data_source_sysdig_fargate_workload_agent.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const agentinoKiltDefinition = `build {
2727
"SYSDIG_ACCESS_KEY": ${config.sysdig_access_key}
2828
"SYSDIG_LOGGING": ${config.sysdig_logging}
2929
"SYSDIG_SIDECAR": ${config.sidecar}
30+
"SYSDIG_PRIORITY": ${config.priority}
3031
}
3132
capabilities: ["SYS_PTRACE"]
3233
mount: [
@@ -129,14 +130,19 @@ func dataSourceSysdigFargateWorkloadAgent() *schema.Resource {
129130
"sidecar": {
130131
Type: schema.TypeString,
131132
Description: "Sidecar mode: auto/force/(empty string)",
132-
Default: "", // we will want to change this to "auto" eventually
133+
Default: "auto",
134+
Optional: true,
135+
},
136+
"priority": {
137+
Type: schema.TypeString,
138+
Description: "The priority of the agent. Can be 'security' or 'availability'",
139+
Default: "availability",
133140
Optional: true,
134141
},
135-
136142
"instrumentation_essential": {
137143
Type: schema.TypeBool,
138144
Description: "Should the instrumentation container be marked as essential",
139-
Default: true,
145+
Default: false,
140146
Optional: true,
141147
},
142148
"instrumentation_cpu": {
@@ -362,6 +368,7 @@ type KiltRecipeConfig struct {
362368
CollectorPort string `json:"collector_port"`
363369
SysdigLogging string `json:"sysdig_logging"`
364370
Sidecar string `json:"sidecar"`
371+
Priority string `json:"priority"`
365372
}
366373

367374
type patchOptions struct {
@@ -404,7 +411,8 @@ func newPatchOptions(d *schema.ResourceData) *patchOptions {
404411
if essential := d.Get("instrumentation_essential"); essential != nil {
405412
opts.Essential = essential.(bool)
406413
} else {
407-
opts.Essential = true
414+
priority := d.Get("priority").(string)
415+
opts.Essential = priority == "security"
408416
}
409417

410418
if cpuShares := d.Get("instrumentation_cpu"); cpuShares != nil {
@@ -429,6 +437,11 @@ func newPatchOptions(d *schema.ResourceData) *patchOptions {
429437
}
430438

431439
func dataSourceSysdigFargateWorkloadAgentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
440+
priority := d.Get("priority").(string)
441+
if priority != "security" && priority != "availability" {
442+
return diag.Errorf("Invalid priority: %s. must be either \"security\" or \"availability\"", priority)
443+
}
444+
432445
recipeConfig := KiltRecipeConfig{
433446
SysdigAccessKey: d.Get("sysdig_access_key").(string),
434447
AgentImage: d.Get("workload_agent_image").(string),
@@ -438,6 +451,7 @@ func dataSourceSysdigFargateWorkloadAgentRead(ctx context.Context, d *schema.Res
438451
CollectorPort: d.Get("collector_port").(string),
439452
SysdigLogging: d.Get("sysdig_logging").(string),
440453
Sidecar: d.Get("sidecar").(string),
454+
Priority: priority,
441455
}
442456

443457
jsonConf, err := json.Marshal(&recipeConfig)

sysdig/data_source_sysdig_secure_aws_ml_policy_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_secure || tf_acc_policies || tf_acc_onprem_secure
1+
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws || tf_acc_onprem_secure
22

33
package sysdig_test
44

sysdig/data_source_sysdig_secure_drift_policy_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_secure || tf_acc_policies || tf_acc_onprem_secure
1+
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws || tf_acc_onprem_secure
22

33
package sysdig_test
44

sysdig/data_source_sysdig_secure_malware_policy_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_secure || tf_acc_policies || tf_acc_onprem_secure
1+
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws || tf_acc_onprem_secure
22

33
package sysdig_test
44

sysdig/data_source_sysdig_secure_ml_policy_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_secure || tf_acc_policies || tf_acc_onprem_secure
1+
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws || tf_acc_onprem_secure
22

33
package sysdig_test
44

sysdig/resource_sysdig_secure_aws_ml_policy_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_secure || tf_acc_policies || tf_acc_onprem_secure
1+
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws || tf_acc_onprem_secure
22

33
package sysdig_test
44

sysdig/resource_sysdig_secure_cloud_auth_account.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,37 @@ func resourceSysdigSecureCloudauthAccount() *schema.Resource {
8787
SchemaCloudConnectorMetadata: {
8888
Type: schema.TypeString,
8989
Optional: true,
90+
Default: "",
9091
},
9192
SchemaTrustedRoleMetadata: {
9293
Type: schema.TypeString,
9394
Optional: true,
95+
Default: "",
9496
},
9597
SchemaEventBridgeMetadata: {
9698
Type: schema.TypeString,
9799
Optional: true,
100+
Default: "",
98101
},
99102
SchemaServicePrincipalMetadata: {
100103
Type: schema.TypeString,
101104
Optional: true,
105+
Default: "",
102106
},
103107
SchemaWebhookDatasourceMetadata: {
104108
Type: schema.TypeString,
105109
Optional: true,
110+
Default: "",
106111
},
107112
SchemaCryptoKeyMetadata: {
108113
Type: schema.TypeString,
109114
Optional: true,
115+
Default: "",
110116
},
111117
SchemaCloudLogsMetadata: {
112118
Type: schema.TypeString,
113119
Optional: true,
120+
Default: "",
114121
},
115122
},
116123
}
@@ -387,25 +394,26 @@ func constructAccountComponents(data *schema.ResourceData) []*cloudauth.AccountC
387394
if data.Get(SchemaCloudProviderType).(string) == cloudauth.Provider_PROVIDER_GCP.String() {
388395
spGcp := &internalServicePrincipalMetadata{}
389396
err = json.Unmarshal([]byte(value.(string)), spGcp)
397+
// special handling if GCP service principal key is present, decode and unmarshal it before populating all the metadata
398+
var spGcpKey *cloudauth.ServicePrincipalMetadata_GCP_Key
390399
if len(spGcp.Gcp.Key) > 0 {
391400
var spGcpKeyBytes []byte
392401
spGcpKeyBytes, err = base64.StdEncoding.DecodeString(spGcp.Gcp.Key)
393402
if err != nil {
394403
diag.FromErr(err)
395404
}
396-
spGcpKey := &cloudauth.ServicePrincipalMetadata_GCP_Key{}
397-
err = json.Unmarshal(spGcpKeyBytes, spGcpKey)
398-
component.Metadata = &cloudauth.AccountComponent_ServicePrincipalMetadata{
399-
ServicePrincipalMetadata: &cloudauth.ServicePrincipalMetadata{
400-
Provider: &cloudauth.ServicePrincipalMetadata_Gcp{
401-
Gcp: &cloudauth.ServicePrincipalMetadata_GCP{
402-
Key: spGcpKey,
403-
WorkloadIdentityFederation: spGcp.Gcp.WorkloadIdentityFederation,
404-
Email: spGcp.Gcp.Email,
405-
},
405+
err = json.Unmarshal(spGcpKeyBytes, &spGcpKey)
406+
}
407+
component.Metadata = &cloudauth.AccountComponent_ServicePrincipalMetadata{
408+
ServicePrincipalMetadata: &cloudauth.ServicePrincipalMetadata{
409+
Provider: &cloudauth.ServicePrincipalMetadata_Gcp{
410+
Gcp: &cloudauth.ServicePrincipalMetadata_GCP{
411+
Key: spGcpKey,
412+
WorkloadIdentityFederation: spGcp.Gcp.WorkloadIdentityFederation,
413+
Email: spGcp.Gcp.Email,
406414
},
407415
},
408-
}
416+
},
409417
}
410418
}
411419
case SchemaWebhookDatasourceMetadata:

0 commit comments

Comments
 (0)