diff --git a/sysdig/data_source_sysdig_fargate_ECS_test.go b/sysdig/data_source_sysdig_fargate_ECS_test.go index 466f20dd..1352abf0 100644 --- a/sysdig/data_source_sysdig_fargate_ECS_test.go +++ b/sysdig/data_source_sysdig_fargate_ECS_test.go @@ -49,6 +49,7 @@ func getKiltRecipe(t *testing.T) string { CollectorHost: "collector_host", CollectorPort: "collector_port", SysdigLogging: "sysdig_logging", + Priority: "priority", } jsonRecipeConfig, err := json.Marshal(&recipeConfig) @@ -121,6 +122,12 @@ func TestNewPatchOptions(t *testing.T) { }, }, }, + "priority": { + Type: schema.TypeString, + Description: "The priority of the agent. Can be 'security' or 'availability'", + Default: "availability", + Optional: true, + }, }, } } @@ -164,13 +171,24 @@ func TestNewPatchOptions(t *testing.T) { "stream_prefix": "fried", "region": "chicken", }, - Essential: true, + Essential: false, } actualPatchOptions := newPatchOptions(data) if !reflect.DeepEqual(expectedPatchOptions, actualPatchOptions) { t.Errorf("patcConfigurations are not equal. Expected: %v, Actual: %v", expectedPatchOptions, actualPatchOptions) } + + err = data.Set("priority", "security") + if err != nil { + assert.FailNow(t, fmt.Sprintf("Could not set priority, got error: %v", err)) + } + expectedPatchOptions.Essential = true + actualPatchOptions = newPatchOptions(data) + + if !reflect.DeepEqual(expectedPatchOptions, actualPatchOptions) { + t.Errorf("patcConfigurations are not equal. Expected: %v, Actual: %v", expectedPatchOptions, actualPatchOptions) + } } func getSidecarConfig() string { diff --git a/sysdig/data_source_sysdig_fargate_workload_agent.go b/sysdig/data_source_sysdig_fargate_workload_agent.go index d47cf75c..4c839258 100644 --- a/sysdig/data_source_sysdig_fargate_workload_agent.go +++ b/sysdig/data_source_sysdig_fargate_workload_agent.go @@ -27,6 +27,7 @@ const agentinoKiltDefinition = `build { "SYSDIG_ACCESS_KEY": ${config.sysdig_access_key} "SYSDIG_LOGGING": ${config.sysdig_logging} "SYSDIG_SIDECAR": ${config.sidecar} + "SYSDIG_PRIORITY": ${config.priority} } capabilities: ["SYS_PTRACE"] mount: [ @@ -129,14 +130,19 @@ func dataSourceSysdigFargateWorkloadAgent() *schema.Resource { "sidecar": { Type: schema.TypeString, Description: "Sidecar mode: auto/force/(empty string)", - Default: "", // we will want to change this to "auto" eventually + Default: "auto", + Optional: true, + }, + "priority": { + Type: schema.TypeString, + Description: "The priority of the agent. Can be 'security' or 'availability'", + Default: "availability", Optional: true, }, - "instrumentation_essential": { Type: schema.TypeBool, Description: "Should the instrumentation container be marked as essential", - Default: true, + Default: false, Optional: true, }, "instrumentation_cpu": { @@ -362,6 +368,7 @@ type KiltRecipeConfig struct { CollectorPort string `json:"collector_port"` SysdigLogging string `json:"sysdig_logging"` Sidecar string `json:"sidecar"` + Priority string `json:"priority"` } type patchOptions struct { @@ -404,7 +411,8 @@ func newPatchOptions(d *schema.ResourceData) *patchOptions { if essential := d.Get("instrumentation_essential"); essential != nil { opts.Essential = essential.(bool) } else { - opts.Essential = true + priority := d.Get("priority").(string) + opts.Essential = priority == "security" } if cpuShares := d.Get("instrumentation_cpu"); cpuShares != nil { @@ -429,6 +437,11 @@ func newPatchOptions(d *schema.ResourceData) *patchOptions { } func dataSourceSysdigFargateWorkloadAgentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + priority := d.Get("priority").(string) + if priority != "security" && priority != "availability" { + return diag.Errorf("Invalid priority: %s. must be either \"security\" or \"availability\"", priority) + } + recipeConfig := KiltRecipeConfig{ SysdigAccessKey: d.Get("sysdig_access_key").(string), AgentImage: d.Get("workload_agent_image").(string), @@ -438,6 +451,7 @@ func dataSourceSysdigFargateWorkloadAgentRead(ctx context.Context, d *schema.Res CollectorPort: d.Get("collector_port").(string), SysdigLogging: d.Get("sysdig_logging").(string), Sidecar: d.Get("sidecar").(string), + Priority: priority, } jsonConf, err := json.Marshal(&recipeConfig) diff --git a/sysdig/testfiles/ECSInstrumented.json b/sysdig/testfiles/ECSInstrumented.json index ae9839ea..fde4dfc9 100644 --- a/sysdig/testfiles/ECSInstrumented.json +++ b/sysdig/testfiles/ECSInstrumented.json @@ -19,6 +19,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -90,6 +94,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" diff --git a/sysdig/testfiles/fargate_bare_pdig_expected.json b/sysdig/testfiles/fargate_bare_pdig_expected.json index 482ed78d..0e436c55 100644 --- a/sysdig/testfiles/fargate_bare_pdig_expected.json +++ b/sysdig/testfiles/fargate_bare_pdig_expected.json @@ -29,6 +29,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -90,6 +94,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -172,6 +180,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" diff --git a/sysdig/testfiles/fargate_cmd_test_expected.json b/sysdig/testfiles/fargate_cmd_test_expected.json index 80e0558a..55e1c953 100644 --- a/sysdig/testfiles/fargate_cmd_test_expected.json +++ b/sysdig/testfiles/fargate_cmd_test_expected.json @@ -32,6 +32,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -85,6 +89,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" diff --git a/sysdig/testfiles/fargate_combined_test_expected.json b/sysdig/testfiles/fargate_combined_test_expected.json index 90cb628f..05610a4e 100644 --- a/sysdig/testfiles/fargate_combined_test_expected.json +++ b/sysdig/testfiles/fargate_combined_test_expected.json @@ -32,6 +32,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -97,6 +101,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" diff --git a/sysdig/testfiles/fargate_entrypoint_test_expected.json b/sysdig/testfiles/fargate_entrypoint_test_expected.json index a897e053..ed92994a 100644 --- a/sysdig/testfiles/fargate_entrypoint_test_expected.json +++ b/sysdig/testfiles/fargate_entrypoint_test_expected.json @@ -29,6 +29,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -82,6 +86,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" diff --git a/sysdig/testfiles/fargate_env_test_expected.json b/sysdig/testfiles/fargate_env_test_expected.json index 1ec13302..9947d594 100644 --- a/sysdig/testfiles/fargate_env_test_expected.json +++ b/sysdig/testfiles/fargate_env_test_expected.json @@ -29,6 +29,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -90,6 +94,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" diff --git a/sysdig/testfiles/fargate_field_case_test_expected.json b/sysdig/testfiles/fargate_field_case_test_expected.json index d3dfc0ff..cd7f68a8 100644 --- a/sysdig/testfiles/fargate_field_case_test_expected.json +++ b/sysdig/testfiles/fargate_field_case_test_expected.json @@ -29,6 +29,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -82,6 +86,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -135,6 +143,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" diff --git a/sysdig/testfiles/fargate_ignore_container_test_expected.json b/sysdig/testfiles/fargate_ignore_container_test_expected.json index 7cd73907..6db8a88f 100644 --- a/sysdig/testfiles/fargate_ignore_container_test_expected.json +++ b/sysdig/testfiles/fargate_ignore_container_test_expected.json @@ -29,6 +29,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -96,6 +100,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" diff --git a/sysdig/testfiles/fargate_linuxparameters_test_expected.json b/sysdig/testfiles/fargate_linuxparameters_test_expected.json index ff920ab9..6bc70ec3 100644 --- a/sysdig/testfiles/fargate_linuxparameters_test_expected.json +++ b/sysdig/testfiles/fargate_linuxparameters_test_expected.json @@ -29,6 +29,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -85,6 +89,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" diff --git a/sysdig/testfiles/fargate_log_group_expected.json b/sysdig/testfiles/fargate_log_group_expected.json index 2e5927fe..15a0ce1f 100644 --- a/sysdig/testfiles/fargate_log_group_expected.json +++ b/sysdig/testfiles/fargate_log_group_expected.json @@ -32,6 +32,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -94,6 +98,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" diff --git a/sysdig/testfiles/fargate_volumesfrom_test_expected.json b/sysdig/testfiles/fargate_volumesfrom_test_expected.json index 60d0b3d4..a2aacbb9 100644 --- a/sysdig/testfiles/fargate_volumesfrom_test_expected.json +++ b/sysdig/testfiles/fargate_volumesfrom_test_expected.json @@ -32,6 +32,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": "" @@ -89,6 +93,10 @@ "Name": "SYSDIG_LOGGING", "Value": "sysdig_logging" }, + { + "Name": "SYSDIG_PRIORITY", + "Value": "priority" + }, { "Name": "SYSDIG_SIDECAR", "Value": ""