Skip to content

Commit e0cc194

Browse files
authored
Merge pull request #200 from KoppulaRajender/kap_fix
bug: fix resource assurance policy "assurance_type" && Data KAP
2 parents 3ec3003 + 5472826 commit e0cc194

31 files changed

Lines changed: 199 additions & 163 deletions

aquasec/data_application_scope.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ func dataApplicationScope() *schema.Resource {
1010
Read: readApplicationScopeRead,
1111
Schema: map[string]*schema.Schema{
1212
"name": {
13-
Type: schema.TypeString,
13+
Type: schema.TypeString,
1414
Description: "Name of an application scope.",
15-
Required: true,
15+
Required: true,
1616
},
1717
"description": {
18-
Type: schema.TypeString,
18+
Type: schema.TypeString,
1919
Description: "Description of the application scope.",
20-
Optional: true,
20+
Computed: true,
2121
},
2222
"author": {
23-
Type: schema.TypeString,
23+
Type: schema.TypeString,
2424
Description: "Username of the account that created the service.",
25-
Computed: true,
25+
Computed: true,
2626
},
2727
"owner_email": {
28-
Type: schema.TypeString,
28+
Type: schema.TypeString,
2929
Description: "Name of an application scope.",
30-
Optional: true,
30+
Computed: true,
3131
},
3232
"categories": {
33-
Type: schema.TypeSet,
34-
Optional: true,
33+
Type: schema.TypeSet,
34+
Optional: true,
3535
Description: "Artifacts (of applications) / Workloads (containers) / Infrastructure (elements).",
3636
Elem: &schema.Resource{
3737
Schema: map[string]*schema.Schema{

aquasec/data_container_runtime_policy.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ func dataContainerRuntimePolicy() *schema.Resource {
191191
},
192192
"malware_scan_options": {
193193
Type: schema.TypeList,
194-
MaxItems: 1,
195194
Description: "Configuration for Real-Time Malware Protection.",
196195
Elem: &schema.Resource{
197196
Schema: map[string]*schema.Schema{
@@ -201,35 +200,36 @@ func dataContainerRuntimePolicy() *schema.Resource {
201200
Elem: &schema.Schema{
202201
Type: schema.TypeString,
203202
},
204-
Optional: true,
203+
Computed: true,
205204
},
206205
"action": {
207206
Type: schema.TypeString,
208207
Description: "Set Action, Defaults to 'Alert' when empty",
209208
Elem: &schema.Schema{
210209
Type: schema.TypeString,
211210
},
212-
Optional: true,
211+
Computed: true,
213212
},
214213
"exclude_directories": {
215214
Type: schema.TypeList,
216215
Description: "List of registry paths to be excluded from being protected.",
217216
Elem: &schema.Schema{
218217
Type: schema.TypeString,
219218
},
220-
Optional: true,
219+
Computed: true,
221220
},
222221
"exclude_processes": {
223222
Type: schema.TypeList,
224223
Description: "List of registry processes to be excluded from being protected.",
225224
Elem: &schema.Schema{
226225
Type: schema.TypeString,
227226
},
228-
Optional: true,
227+
Computed: true,
229228
},
230229
},
231230
},
232231
Optional: true,
232+
Computed: true,
233233
},
234234
"file_integrity_monitoring": {
235235
Type: schema.TypeList,

aquasec/data_function_assurance_policy.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ func dataFunctionAssurancePolicy() *schema.Resource {
99
return &schema.Resource{
1010
Read: dataFunctionAssurancePolicyRead,
1111
Schema: map[string]*schema.Schema{
12-
"assurance_type": {
13-
Type: schema.TypeString,
14-
Description: "What type of assurance policy is described.",
15-
Computed: true,
16-
},
12+
/*
13+
"assurance_type": {
14+
Type: schema.TypeString,
15+
Description: "What type of assurance policy is described.",
16+
Computed: true,
17+
},
18+
*/
1719
"id": {
1820
Type: schema.TypeString,
1921
Computed: true,
@@ -602,7 +604,7 @@ func dataFunctionAssurancePolicy() *schema.Resource {
602604
"maximum_score_exclude_no_fix": {
603605
Type: schema.TypeBool,
604606
Description: "Indicates that policy should ignore cases that do not have a known fix.",
605-
Optional: true,
607+
Computed: true,
606608
},
607609
},
608610
}
@@ -616,7 +618,7 @@ func dataFunctionAssurancePolicyRead(d *schema.ResourceData, m interface{}) erro
616618
iap, err := ac.GetAssurancePolicy(name, assurance_type)
617619
if err == nil {
618620
d.Set("description", iap.Description)
619-
d.Set("assurance_type", iap.AssuranceType)
621+
//d.Set("assurance_type", iap.AssuranceType)
620622
d.Set("author", iap.Author)
621623
d.Set("application_scopes", iap.ApplicationScopes)
622624
d.Set("registry", iap.Registry)

aquasec/data_host_assurance_policy.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ func dataHostAssurancePolicy() *schema.Resource {
99
return &schema.Resource{
1010
Read: dataHostAssurancePolicyRead,
1111
Schema: map[string]*schema.Schema{
12-
"assurance_type": {
13-
Type: schema.TypeString,
14-
Description: "What type of assurance policy is described.",
15-
Computed: true,
16-
},
12+
/*
13+
"assurance_type": {
14+
Type: schema.TypeString,
15+
Description: "What type of assurance policy is described.",
16+
Computed: true,
17+
},
18+
*/
1719
"id": {
1820
Type: schema.TypeString,
1921
Computed: true,
@@ -602,7 +604,7 @@ func dataHostAssurancePolicy() *schema.Resource {
602604
"maximum_score_exclude_no_fix": {
603605
Type: schema.TypeBool,
604606
Description: "Indicates that policy should ignore cases that do not have a known fix.",
605-
Optional: true,
607+
Computed: true,
606608
},
607609
},
608610
}
@@ -616,7 +618,7 @@ func dataHostAssurancePolicyRead(d *schema.ResourceData, m interface{}) error {
616618
iap, err := ac.GetAssurancePolicy(name, assurance_type)
617619
if err == nil {
618620
d.Set("description", iap.Description)
619-
d.Set("assurance_type", iap.AssuranceType)
621+
//d.Set("assurance_type", iap.AssuranceType)
620622
d.Set("author", iap.Author)
621623
d.Set("application_scopes", iap.ApplicationScopes)
622624
d.Set("registry", iap.Registry)

aquasec/data_host_runtime_policy.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ func dataHostRuntimePolicy() *schema.Resource {
411411
},
412412
"malware_scan_options": {
413413
Type: schema.TypeList,
414-
MaxItems: 1,
415414
Description: "Configuration for Real-Time Malware Protection.",
416415
Elem: &schema.Resource{
417416
Schema: map[string]*schema.Schema{
@@ -421,35 +420,35 @@ func dataHostRuntimePolicy() *schema.Resource {
421420
Elem: &schema.Schema{
422421
Type: schema.TypeString,
423422
},
424-
Optional: true,
423+
Computed: true,
425424
},
426425
"action": {
427426
Type: schema.TypeString,
428427
Description: "Set Action, Defaults to 'Alert' when empty",
429428
Elem: &schema.Schema{
430429
Type: schema.TypeString,
431430
},
432-
Optional: true,
431+
Computed: true,
433432
},
434433
"exclude_processes": {
435434
Type: schema.TypeList,
436435
Description: "List of registry processes to be excluded from being protected.",
437436
Elem: &schema.Schema{
438437
Type: schema.TypeString,
439438
},
440-
Optional: true,
439+
Computed: true,
441440
},
442441
"include_directories": {
443442
Type: schema.TypeList,
444443
Description: "List of directories to be protected.",
445444
Elem: &schema.Schema{
446445
Type: schema.TypeString,
447446
},
448-
Optional: true,
447+
Computed: true,
449448
},
450449
},
451450
},
452-
Optional: true,
451+
Computed: true,
453452
},
454453
},
455454
}

aquasec/data_image_assurance_policy.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ func dataImageAssurancePolicy() *schema.Resource {
99
return &schema.Resource{
1010
Read: dataImageAssurancePolicyRead,
1111
Schema: map[string]*schema.Schema{
12-
"assurance_type": {
13-
Type: schema.TypeString,
14-
Description: "What type of assurance policy is described.",
15-
Computed: true,
16-
},
12+
/*
13+
"assurance_type": {
14+
Type: schema.TypeString,
15+
Description: "What type of assurance policy is described.",
16+
Computed: true,
17+
},
18+
*/
1719
"id": {
1820
Type: schema.TypeString,
1921
Computed: true,
@@ -602,7 +604,7 @@ func dataImageAssurancePolicy() *schema.Resource {
602604
"maximum_score_exclude_no_fix": {
603605
Type: schema.TypeBool,
604606
Description: "Indicates that policy should ignore cases that do not have a known fix.",
605-
Optional: true,
607+
Computed: true,
606608
},
607609
},
608610
}
@@ -616,7 +618,7 @@ func dataImageAssurancePolicyRead(d *schema.ResourceData, m interface{}) error {
616618
iap, err := ac.GetAssurancePolicy(name, assurance_type)
617619
if err == nil {
618620
d.Set("description", iap.Description)
619-
d.Set("assurance_type", iap.AssuranceType)
621+
//d.Set("assurance_type", iap.AssuranceType)
620622
d.Set("author", iap.Author)
621623
d.Set("application_scopes", iap.ApplicationScopes)
622624
d.Set("registry", iap.Registry)

aquasec/data_kubernetes_assurance_policy.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ func dataKubernetesAssurancePolicy() *schema.Resource {
99
return &schema.Resource{
1010
Read: dataKubernetesAssurancePolicyRead,
1111
Schema: map[string]*schema.Schema{
12-
"assurance_type": {
13-
Type: schema.TypeString,
14-
Description: "What type of assurance policy is described.",
15-
Computed: true,
16-
},
12+
/*
13+
"assurance_type": {
14+
Type: schema.TypeString,
15+
Description: "What type of assurance policy is described.",
16+
Computed: true,
17+
},
18+
*/
1719
"id": {
1820
Type: schema.TypeString,
1921
Computed: true,
@@ -82,7 +84,7 @@ func dataKubernetesAssurancePolicy() *schema.Resource {
8284
"kubernetes_controls_names": {
8385
Type: schema.TypeList,
8486
Description: "List of kubernetes control names",
85-
Optional: true,
87+
Computed: true,
8688
Elem: &schema.Schema{
8789
Type: schema.TypeString,
8890
},
@@ -610,7 +612,7 @@ func dataKubernetesAssurancePolicy() *schema.Resource {
610612
"maximum_score_exclude_no_fix": {
611613
Type: schema.TypeBool,
612614
Description: "Indicates that policy should ignore cases that do not have a known fix.",
613-
Optional: true,
615+
Computed: true,
614616
},
615617
},
616618
}
@@ -624,7 +626,7 @@ func dataKubernetesAssurancePolicyRead(d *schema.ResourceData, m interface{}) er
624626
iap, err := ac.GetAssurancePolicy(name, assurance_type)
625627
if err == nil {
626628
d.Set("description", iap.Description)
627-
d.Set("assurance_type", iap.AssuranceType)
629+
//d.Set("assurance_type", iap.AssuranceType)
628630
d.Set("author", iap.Author)
629631
d.Set("application_scopes", iap.ApplicationScopes)
630632
d.Set("registry", iap.Registry)

aquasec/data_registry.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func dataSourceRegistry() *schema.Resource {
4444
"auto_pull_rescan": {
4545
Type: schema.TypeBool,
4646
Description: "Whether to automatically pull and rescan images from the registry on creation and daily",
47-
Optional: true,
47+
Computed: true,
4848
},
4949
"auto_pull_max": {
5050
Type: schema.TypeInt,
@@ -83,11 +83,13 @@ func dataSourceRegistry() *schema.Resource {
8383
Type: schema.TypeString,
8484
Description: "Scanner type",
8585
Optional: true,
86+
Computed: true,
8687
},
8788
"scanner_name": {
8889
Type: schema.TypeList,
8990
Description: "List of scanner names",
9091
Optional: true,
92+
Computed: true,
9193
Elem: &schema.Schema{
9294
Type: schema.TypeString,
9395
},

aquasec/resource_function_assurance_policy.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ func resourceFunctionAssurancePolicy() *schema.Resource {
1515
StateContext: schema.ImportStatePassthroughContext,
1616
},
1717
Schema: map[string]*schema.Schema{
18-
"assurance_type": {
19-
Type: schema.TypeString,
20-
Description: "What type of assurance policy is described.",
21-
Optional: true,
22-
},
18+
/*
19+
"assurance_type": {
20+
Type: schema.TypeString,
21+
Description: "What type of assurance policy is described.",
22+
Optional: true,
23+
Computed: true,
24+
},
25+
*/
2326
"id": {
2427
Type: schema.TypeString,
2528
Computed: true,
@@ -630,7 +633,7 @@ func resourceFunctionAssurancePolicyCreate(d *schema.ResourceData, m interface{}
630633
name := d.Get("name").(string)
631634
assurance_type := "function"
632635

633-
iap := expandAssurancePolicy(d)
636+
iap := expandAssurancePolicy(d, assurance_type)
634637
err := ac.CreateAssurancePolicy(iap, assurance_type)
635638

636639
if err != nil {
@@ -652,7 +655,7 @@ func resourceFunctionAssurancePolicyUpdate(d *schema.ResourceData, m interface{}
652655
"function_integrity_enabled", "dta_enabled", "cves_white_list", "cves_white_list_enabled", "blacklist_permissions_enabled", "blacklist_permissions", "enabled", "enforce", "enforce_after_days", "ignore_recently_published_vln", "ignore_recently_published_vln_period",
653656
"ignore_risk_resources_enabled", "ignored_risk_resources", "application_scopes", "auto_scan_enabled", "auto_scan_configured", "auto_scan_time", "required_labels_enabled", "required_labels", "forbidden_labels_enabled", "forbidden_labels", "domain_name",
654657
"domain", "description", "dta_severity", "scan_nfs_mounts", "malware_action", "partial_results_image_fail", "maximum_score_exclude_no_fix") {
655-
iap := expandAssurancePolicy(d)
658+
iap := expandAssurancePolicy(d, assurance_type)
656659
err := ac.UpdateAssurancePolicy(iap, assurance_type)
657660
if err == nil {
658661
err1 := resourceFunctionAssurancePolicyRead(d, m)
@@ -674,7 +677,7 @@ func resourceFunctionAssurancePolicyRead(d *schema.ResourceData, m interface{})
674677

675678
iap, err := ac.GetAssurancePolicy(d.Id(), assurance_type)
676679
if err == nil {
677-
d.Set("assurance_type", iap.AssuranceType)
680+
//d.Set("assurance_type", iap.AssuranceType)
678681
d.Set("name", iap.Name)
679682
d.Set("description", iap.Description)
680683
d.Set("author", iap.Author)

aquasec/resource_function_assurance_policy_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
func TestAquasecFunctionAssurancePolicy(t *testing.T) {
1313
t.Parallel()
14-
assurance_type := "function"
1514
description := "Created using Terraform"
1615
name := acctest.RandomWithPrefix("terraform-test")
1716
application_scopes := "Global"
@@ -21,7 +20,7 @@ func TestAquasecFunctionAssurancePolicy(t *testing.T) {
2120
CheckDestroy: CheckDestroy("aquasec_function_assurance_policy.terraformiap"),
2221
Steps: []resource.TestStep{
2322
{
24-
Config: testAccCheckFunctionAssurancePolicy(assurance_type, description, name, application_scopes),
23+
Config: testAccCheckFunctionAssurancePolicy(description, name, application_scopes),
2524
Check: resource.ComposeTestCheckFunc(
2625
testAccCheckFunctionAssurancePolicyExists("aquasec_function_assurance_policy.terraformiap"),
2726
),
@@ -35,16 +34,15 @@ func TestAquasecFunctionAssurancePolicy(t *testing.T) {
3534
})
3635
}
3736

38-
func testAccCheckFunctionAssurancePolicy(assurance_type string, description string, name string, application_scopes string) string {
37+
func testAccCheckFunctionAssurancePolicy(description string, name string, application_scopes string) string {
3938
return fmt.Sprintf(`
4039
resource "aquasec_function_assurance_policy" "terraformiap" {
41-
assurance_type = "%s"
4240
description = "%s"
4341
name = "%s"
4442
application_scopes = [
4543
"%s"
4644
]
47-
}`, assurance_type, description, name, application_scopes)
45+
}`, description, name, application_scopes)
4846

4947
}
5048

0 commit comments

Comments
 (0)