Skip to content

Commit 230b59c

Browse files
Merge pull request #337 from aquasecurity/branch_336
bug: Added repository_name in the acknowledge resource
2 parents f14b434 + 570445c commit 230b59c

11 files changed

+160
-137
lines changed

aquasec/data_acknowledge.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package aquasec
22

33
import (
4+
"context"
45
"fmt"
5-
"github.com/aquasecurity/terraform-provider-aquasec/client"
6-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
76
"log"
87
"math/rand"
8+
9+
"github.com/aquasecurity/terraform-provider-aquasec/client"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
912
)
1013

1114
func dataSourceAcknowledges() *schema.Resource {
1215
return &schema.Resource{
1316
Description: "The data source `aquasec_acknowledges` provides a method to query all acknowledges within the Aqua ",
14-
Read: dataAcknowledgesRead,
17+
ReadContext: dataAcknowledgesRead,
1518
Schema: map[string]*schema.Schema{
1619
"acknowledges": {
1720
Type: schema.TypeList,
@@ -129,14 +132,19 @@ func dataSourceAcknowledges() *schema.Resource {
129132
Description: "",
130133
Computed: true,
131134
},
135+
"repository_name": {
136+
Type: schema.TypeString,
137+
Description: "The name of the repository in whose context the issue was acknowledged (if not for all images)",
138+
Computed: true,
139+
},
132140
},
133141
},
134142
},
135143
},
136144
}
137145
}
138146

139-
func dataAcknowledgesRead(d *schema.ResourceData, m interface{}) error {
147+
func dataAcknowledgesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
140148
log.Println("[DEBUG] inside dataAcknowledges")
141149
c := m.(*client.Client)
142150
result, err := c.AcknowledgeRead()
@@ -147,10 +155,10 @@ func dataAcknowledgesRead(d *schema.ResourceData, m interface{}) error {
147155
}
148156
d.SetId(id)
149157
if err := d.Set("acknowledges", acknowledges); err != nil {
150-
return err
158+
return diag.FromErr(err)
151159
}
152160
} else {
153-
return err
161+
return diag.FromErr(err)
154162
}
155163

156164
return nil
@@ -188,6 +196,7 @@ func flattenAcknowledgesData(acknowledgesList *client.AcknowledgeList) ([]interf
188196
a["os"] = acknowledge.Os
189197
a["os_version"] = acknowledge.OsVersion
190198
a["docker_id"] = acknowledge.DockerId
199+
a["repository_name"] = acknowledge.RepositoryName
191200
acks[i] = a
192201
}
193202

aquasec/data_function_runtime_policy.go

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func dataFunctionRuntimePolicy() *schema.Resource {
2929
Description: "Version of the function runtime policy",
3030
Computed: true,
3131
},
32-
32+
3333
// Policy control fields
3434
"enabled": {
3535
Type: schema.TypeBool,
@@ -46,7 +46,7 @@ func dataFunctionRuntimePolicy() *schema.Resource {
4646
Description: "Indicates the number of days after which the runtime policy will be changed to enforce mode.",
4747
Computed: true,
4848
},
49-
49+
5050
// Application scope fields
5151
"application_scopes": {
5252
Type: schema.TypeList,
@@ -94,7 +94,7 @@ func dataFunctionRuntimePolicy() *schema.Resource {
9494
},
9595
Computed: true,
9696
},
97-
97+
9898
// Function security controls
9999
"drift_prevention": {
100100
Type: schema.TypeList,
@@ -200,7 +200,7 @@ func dataFunctionRuntimePolicy() *schema.Resource {
200200
Description: "Block deployment from disallowed images.",
201201
Computed: true,
202202
},
203-
203+
204204
// File monitoring and integrity
205205
"file_integrity_monitoring": {
206206
Type: schema.TypeList,
@@ -289,7 +289,7 @@ func dataFunctionRuntimePolicy() *schema.Resource {
289289
},
290290
},
291291
},
292-
292+
293293
// Malware protection
294294
"malware_scan_options": {
295295
Type: schema.TypeList,
@@ -331,10 +331,15 @@ func dataFunctionRuntimePolicy() *schema.Resource {
331331
},
332332
Computed: true,
333333
},
334+
"file_forensic_collection": {
335+
Type: schema.TypeBool,
336+
Description: "Whether to enable file forensic collection.",
337+
Computed: true,
338+
},
334339
},
335340
},
336341
},
337-
342+
338343
// Honeypot/tripwire - renamed for consistency with resource
339344
"tripwire": {
340345
Type: schema.TypeList,
@@ -374,14 +379,14 @@ func dataFunctionRuntimePolicy() *schema.Resource {
374379
},
375380
},
376381
},
377-
382+
378383
// Network security
379384
"enable_crypto_mining_dns": {
380385
Type: schema.TypeBool,
381386
Description: "Enable detection of crypto mining via DNS monitoring",
382387
Computed: true,
383388
},
384-
389+
385390
// Required internal fields
386391
"runtime_type": {
387392
Type: schema.TypeString,
@@ -393,7 +398,7 @@ func dataFunctionRuntimePolicy() *schema.Resource {
393398
Description: "Policy type identifier",
394399
Computed: true,
395400
},
396-
401+
397402
// Administrative fields
398403
"author": {
399404
Type: schema.TypeString,
@@ -415,7 +420,7 @@ func dataFunctionRuntimePolicy() *schema.Resource {
415420
Description: "Indicates if audit check is enabled",
416421
Computed: true,
417422
},
418-
423+
419424
// Internal tracking fields
420425
"created": {
421426
Type: schema.TypeString,
@@ -449,71 +454,71 @@ func dataFunctionRuntimePolicyRead(ctx context.Context, d *schema.ResourceData,
449454
d.Set("name", crp.Name)
450455
d.Set("description", crp.Description)
451456
d.Set("version", crp.Version)
452-
457+
453458
// Policy control fields
454459
d.Set("enabled", crp.Enabled)
455460
d.Set("enforce", crp.Enforce)
456461
d.Set("enforce_after_days", crp.EnforceAfterDays)
457-
462+
458463
// Application scope fields
459464
d.Set("application_scopes", crp.ApplicationScopes)
460465
d.Set("exclude_application_scopes", crp.ExcludeApplicationScopes)
461466
d.Set("scope_expression", crp.Scope.Expression)
462467
d.Set("scope_variables", flattenScopeVariables(crp.Scope.Variables))
463-
468+
464469
// Function security controls
465470
d.Set("drift_prevention", flattenDriftPrevention(crp.DriftPrevention))
466471
d.Set("executable_blacklist", flattenExecutableBlacklist(crp.ExecutableBlacklist))
467472
d.Set("allowed_executables", flattenAllowedExecutables(crp.AllowedExecutables))
468473
d.Set("block_fileless_exec", crp.BlockFilelessExec)
469474
d.Set("block_non_compliant_workloads", crp.BlockNonCompliantWorkloads)
470475
d.Set("block_disallowed_images", crp.BlockDisallowedImages)
471-
476+
472477
// File integrity monitoring
473478
// Since we can't compare with an empty struct due to slice fields,
474479
// check a key field to determine if we should set it
475480
if len(crp.FileIntegrityMonitoring.MonitoredFiles) > 0 || crp.FileIntegrityMonitoring.Enabled {
476481
d.Set("file_integrity_monitoring", flattenFileIntegrityMonitoring(crp.FileIntegrityMonitoring))
477482
}
478-
483+
479484
// Malware scan options
480485
// Since we can't compare with an empty struct due to slice fields,
481486
// check a key field to determine if we should set it
482-
if len(crp.MalwareScanOptions.ExcludeDirectories) > 0 ||
483-
len(crp.MalwareScanOptions.IncludeDirectories) > 0 ||
484-
crp.MalwareScanOptions.Enabled {
487+
if len(crp.MalwareScanOptions.ExcludeDirectories) > 0 ||
488+
len(crp.MalwareScanOptions.IncludeDirectories) > 0 ||
489+
crp.MalwareScanOptions.Enabled {
485490
d.Set("malware_scan_options", flattenMalwareScanOptions(crp.MalwareScanOptions))
486491
}
487-
492+
488493
// Honeypot/tripwire
489494
d.Set("tripwire", flattenTripwire(crp.Tripwire))
490-
495+
491496
// Network security
492497
d.Set("enable_crypto_mining_dns", crp.EnableCryptoMiningDns)
493-
498+
494499
// Required internal fields
495500
d.Set("runtime_type", crp.RuntimeType)
496501
d.Set("type", crp.Type)
497-
502+
498503
// Administrative fields
499504
d.Set("author", crp.Author)
500505
d.Set("is_auto_generated", crp.IsAutoGenerated)
501506
d.Set("is_ootb_policy", crp.IsOOTBPolicy)
502507
d.Set("is_audit_checked", crp.IsAuditChecked)
503-
508+
504509
// Internal tracking fields - with special handling for time.Time
505510
d.Set("created", crp.Created)
506-
511+
507512
// Fix for time.Time field
508513
if !crp.Updated.IsZero() {
509514
d.Set("updated", crp.Updated.Format(time.RFC3339))
510515
} else {
511516
d.Set("updated", "")
512517
}
513-
518+
514519
d.Set("lastupdate", crp.Lastupdate)
515520

516521
d.SetId(name)
517-
522+
518523
return nil
519-
}
524+
}

aquasec/data_host_runtime_policy.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ func dataHostRuntimePolicy() *schema.Resource {
471471
},
472472
"malware_scan_options": {
473473
Type: schema.TypeList,
474-
MaxItems: 1,
475474
Description: "Configuration for Real-Time Malware Protection.",
476475
Elem: &schema.Resource{
477476
Schema: map[string]*schema.Schema{
@@ -481,39 +480,39 @@ func dataHostRuntimePolicy() *schema.Resource {
481480
Elem: &schema.Schema{
482481
Type: schema.TypeString,
483482
},
484-
Optional: true,
483+
Computed: true,
485484
},
486485
"action": {
487486
Type: schema.TypeString,
488487
Description: "Set Action, Defaults to 'Alert' when empty",
489488
Elem: &schema.Schema{
490489
Type: schema.TypeString,
491490
},
492-
Optional: true,
491+
Computed: true,
493492
},
494493
"include_directories": {
495494
Type: schema.TypeList,
496495
Description: "List of registry paths to be excluded from being protected.",
497496
Elem: &schema.Schema{
498497
Type: schema.TypeString,
499498
},
500-
Optional: true,
499+
Computed: true,
501500
},
502501
"exclude_directories": {
503502
Type: schema.TypeList,
504503
Description: "List of registry paths to be excluded from being protected.",
505504
Elem: &schema.Schema{
506505
Type: schema.TypeString,
507506
},
508-
Optional: true,
507+
Computed: true,
509508
},
510509
"exclude_processes": {
511510
Type: schema.TypeList,
512511
Description: "List of registry processes to be excluded from being protected.",
513512
Elem: &schema.Schema{
514513
Type: schema.TypeString,
515514
},
516-
Optional: true,
515+
Computed: true,
517516
},
518517
"file_forensic_collection": {
519518
Type: schema.TypeBool,
@@ -522,7 +521,7 @@ func dataHostRuntimePolicy() *schema.Resource {
522521
},
523522
},
524523
},
525-
Optional: true,
524+
Computed: true,
526525
},
527526
"auditing": {
528527
Type: schema.TypeList,

0 commit comments

Comments
 (0)