Skip to content

Commit 68c2fc1

Browse files
Vandana Mishrajotruon
authored andcommitted
Added - image-count option is provided for create and update container scan recipe
1 parent 12738f3 commit 68c2fc1

12 files changed

+92
-16
lines changed

examples/vulnerability_scanning_service/main.tf

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
22

3-
variable "tenancy_ocid" {
3+
variable "tenancy_ocid" {}
4+
variable "user_ocid" {}
5+
variable "fingerprint" {}
6+
variable "private_key_path" {}
7+
variable "region" {}
8+
variable "compartment_ocid" {}
9+
10+
variable "container_scan_recipe_defined_tags_value" {
11+
default = "value"
412
}
513

6-
variable "user_ocid" {
14+
variable "container_scan_recipe_display_name" {
15+
default = "displayName"
716
}
817

9-
variable "fingerprint" {
18+
variable "container_scan_recipe_freeform_tags" {
19+
default = { "bar-key" = "value" }
1020
}
1121

12-
variable "private_key_path" {
22+
variable "container_scan_recipe_defined_tags" {
1323
}
1424

15-
variable "region" {
25+
variable "container_scan_recipe_image_count" {
26+
default = 4
1627
}
1728

18-
variable "compartment_ocid" {
29+
variable "container_scan_recipe_scan_settings_scan_level" {
30+
default = "NONE"
31+
}
32+
33+
variable "container_scan_recipe_state" {
34+
default = "Active"
1935
}
2036

2137
variable "host_scan_instance_ocid" {
@@ -107,11 +123,21 @@ resource "oci_vulnerability_scanning_container_scan_recipe" "test_container_scan
107123
compartment_id = var.compartment_ocid
108124
scan_settings {
109125
#Required
110-
scan_level = "NONE"
126+
scan_level = var.container_scan_recipe_scan_settings_scan_level
111127
}
112128

113129
#Optional
114-
defined_tags = {"foo-namespace.bar-key"= "value"}
115-
display_name = "TestContainerScanRecipe"
116-
freeform_tags = {"bar-key"= "value"}
130+
defined_tags = map(var.container_scan_recipe_defined_tags, var.container_scan_recipe_defined_tags_value)
131+
display_name = var.container_scan_recipe_display_name
132+
freeform_tags = var.container_scan_recipe_freeform_tags
133+
image_count = var.container_scan_recipe_image_count
134+
}
135+
136+
data "oci_vulnerability_scanning_container_scan_recipes" "test_container_scan_recipes" {
137+
#Required
138+
compartment_id = var.compartment_ocid
139+
140+
#Optional
141+
display_name = var.container_scan_recipe_display_name
142+
state = var.container_scan_recipe_state
117143
}

internal/integrationtest/vulnerability_scanning_container_scan_recipe_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ var (
5252
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
5353
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
5454
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"bar-key": "value"}, Update: map[string]string{"Department": "Accounting"}},
55+
"image_count": acctest.Representation{RepType: acctest.Optional, Create: `2`, Update: `3`},
56+
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: ignoreDefinedTagsChangesRecipeRep},
5557
}
5658
containerScanRecipeScanSettingsRepresentation = map[string]interface{}{
5759
"scan_level": acctest.Representation{RepType: acctest.Required, Create: `NONE`, Update: `STANDARD`},
5860
}
61+
ignoreDefinedTagsChangesRecipeRep = map[string]interface{}{
62+
"ignore_changes": acctest.Representation{RepType: acctest.Required, Create: []string{`defined_tags`}},
63+
}
5964

6065
ContainerScanRecipeResourceDependencies = DefinedTagsDependencies
6166
)
@@ -112,6 +117,7 @@ func TestVulnerabilityScanningContainerScanRecipeResource_basic(t *testing.T) {
112117
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
113118
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
114119
resource.TestCheckResourceAttrSet(resourceName, "id"),
120+
resource.TestCheckResourceAttr(resourceName, "image_count", "2"),
115121
resource.TestCheckResourceAttr(resourceName, "scan_settings.#", "1"),
116122
resource.TestCheckResourceAttr(resourceName, "scan_settings.0.scan_level", "NONE"),
117123
resource.TestCheckResourceAttrSet(resourceName, "state"),
@@ -142,6 +148,7 @@ func TestVulnerabilityScanningContainerScanRecipeResource_basic(t *testing.T) {
142148
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
143149
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
144150
resource.TestCheckResourceAttrSet(resourceName, "id"),
151+
resource.TestCheckResourceAttr(resourceName, "image_count", "2"),
145152
resource.TestCheckResourceAttr(resourceName, "scan_settings.#", "1"),
146153
resource.TestCheckResourceAttr(resourceName, "scan_settings.0.scan_level", "NONE"),
147154
resource.TestCheckResourceAttrSet(resourceName, "state"),
@@ -167,6 +174,7 @@ func TestVulnerabilityScanningContainerScanRecipeResource_basic(t *testing.T) {
167174
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
168175
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
169176
resource.TestCheckResourceAttrSet(resourceName, "id"),
177+
resource.TestCheckResourceAttr(resourceName, "image_count", "3"),
170178
resource.TestCheckResourceAttr(resourceName, "scan_settings.#", "1"),
171179
resource.TestCheckResourceAttr(resourceName, "scan_settings.0.scan_level", "STANDARD"),
172180
resource.TestCheckResourceAttrSet(resourceName, "state"),
@@ -209,6 +217,7 @@ func TestVulnerabilityScanningContainerScanRecipeResource_basic(t *testing.T) {
209217
resource.TestCheckResourceAttr(singularDatasourceName, "display_name", "displayName2"),
210218
resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "1"),
211219
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
220+
resource.TestCheckResourceAttr(singularDatasourceName, "image_count", "3"),
212221
resource.TestCheckResourceAttr(singularDatasourceName, "scan_settings.#", "1"),
213222
resource.TestCheckResourceAttr(singularDatasourceName, "scan_settings.0.scan_level", "STANDARD"),
214223
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),

internal/integrationtest/vulnerability_scanning_container_scan_target_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ var (
5454
"description": acctest.Representation{RepType: acctest.Optional, Create: `description`, Update: `description2`},
5555
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
5656
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"bar-key": "value"}, Update: map[string]string{"Department": "Accounting"}},
57+
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: ignoreDefinedTagsChangesTargetRep},
5758
}
5859
containerScanTargetTargetRegistryRepresentation = map[string]interface{}{
5960
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
@@ -76,6 +77,10 @@ var (
7677
"readme": acctest.RepresentationGroup{RepType: acctest.Optional, Group: containerRepositoryReadmeRepresentation},
7778
}
7879

80+
ignoreDefinedTagsChangesTargetRep = map[string]interface{}{
81+
"ignore_changes": acctest.Representation{RepType: acctest.Required, Create: []string{`defined_tags`}},
82+
}
83+
7984
ContainerScanTargetResourceDependencies = DefinedTagsDependencies +
8085
acctest.GenerateResourceFromRepresentationMap("oci_artifacts_container_repository", "test_container_repository1", acctest.Required, acctest.Create, containerScanRepositoryRepresentation1) +
8186
acctest.GenerateResourceFromRepresentationMap("oci_artifacts_container_repository", "test_container_repository2", acctest.Required, acctest.Create, containerScanRepositoryRepresentation2) +

internal/service/vulnerability_scanning/vulnerability_scanning_container_scan_recipe_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func (s *VulnerabilityScanningContainerScanRecipeDataSourceCrud) SetData() error
8080

8181
s.D.Set("freeform_tags", s.Res.FreeformTags)
8282

83+
if s.Res.ImageCount != nil {
84+
s.D.Set("image_count", *s.Res.ImageCount)
85+
}
86+
8387
if s.Res.ScanSettings != nil {
8488
s.D.Set("scan_settings", []interface{}{ContainerScanSettingsToMap(s.Res.ScanSettings)})
8589
} else {

internal/service/vulnerability_scanning/vulnerability_scanning_container_scan_recipe_resource.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func VulnerabilityScanningContainerScanRecipeResource() *schema.Resource {
7474
Computed: true,
7575
Elem: schema.TypeString,
7676
},
77+
"image_count": {
78+
Type: schema.TypeInt,
79+
Optional: true,
80+
Computed: true,
81+
},
7782

7883
// Computed
7984
"state": {
@@ -190,6 +195,11 @@ func (s *VulnerabilityScanningContainerScanRecipeResourceCrud) Create() error {
190195
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
191196
}
192197

198+
if imageCount, ok := s.D.GetOkExists("image_count"); ok {
199+
tmp := imageCount.(int)
200+
request.ImageCount = &tmp
201+
}
202+
193203
if scanSettings, ok := s.D.GetOkExists("scan_settings"); ok {
194204
if tmpList := scanSettings.([]interface{}); len(tmpList) > 0 {
195205
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "scan_settings", 0)
@@ -374,6 +384,11 @@ func (s *VulnerabilityScanningContainerScanRecipeResourceCrud) Update() error {
374384
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
375385
}
376386

387+
if imageCount, ok := s.D.GetOkExists("image_count"); ok {
388+
tmp := imageCount.(int)
389+
request.ImageCount = &tmp
390+
}
391+
377392
if scanSettings, ok := s.D.GetOkExists("scan_settings"); ok {
378393
if tmpList := scanSettings.([]interface{}); len(tmpList) > 0 {
379394
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "scan_settings", 0)
@@ -431,6 +446,10 @@ func (s *VulnerabilityScanningContainerScanRecipeResourceCrud) SetData() error {
431446

432447
s.D.Set("freeform_tags", s.Res.FreeformTags)
433448

449+
if s.Res.ImageCount != nil {
450+
s.D.Set("image_count", *s.Res.ImageCount)
451+
}
452+
434453
if s.Res.ScanSettings != nil {
435454
s.D.Set("scan_settings", []interface{}{ContainerScanSettingsToMap(s.Res.ScanSettings)})
436455
} else {

internal/service/vulnerability_scanning/vulnerability_scanning_container_scan_target_resource.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,14 @@ func ContainerScanTargetSummaryToMap(obj oci_vulnerability_scanning.ContainerSca
549549
result["system_tags"] = tfresource.SystemTagsToMap(obj.SystemTags)
550550
}
551551

552+
if obj.TargetRegistry != nil {
553+
targetRegistryArray := []interface{}{}
554+
if targetRegistryMap := ContainerScanRegistryToMap(&obj.TargetRegistry); targetRegistryMap != nil {
555+
targetRegistryArray = append(targetRegistryArray, targetRegistryMap)
556+
}
557+
result["target_registry"] = targetRegistryArray
558+
}
559+
552560
if obj.TimeCreated != nil {
553561
result["time_created"] = obj.TimeCreated.String()
554562
}

website/docs/d/vulnerability_scanning_container_scan_recipe.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description: |-
1010
# Data Source: oci_vulnerability_scanning_container_scan_recipe
1111
This data source provides details about a specific Container Scan Recipe resource in Oracle Cloud Infrastructure Vulnerability Scanning service.
1212

13-
Gets a ContainerScanRecipe by identifier
13+
Retrieves a ContainerScanRecipe identified by the recipe ID. A recipe determines the types of security issues that you want scanned.
1414

1515

1616
## Example Usage
@@ -38,6 +38,7 @@ The following attributes are exported:
3838
* `display_name` - User friendly name of container scan recipe
3939
* `freeform_tags` - Simple key-value pair that is applied without any predefined name, type or scope. Exists for cross-compatibility only. Example: `{"bar-key": "value"}`
4040
* `id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of container scan recipe. Immutable and generated on creation.
41+
* `image_count` - This field is set equal to the number of images we want to scan in the first go when the recipe is created
4142
* `scan_settings` - A collection of container scan settings
4243
* `scan_level` - The scan level
4344
* `state` - The current state of the config.

website/docs/d/vulnerability_scanning_container_scan_recipes.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description: |-
1010
# Data Source: oci_vulnerability_scanning_container_scan_recipes
1111
This data source provides the list of Container Scan Recipes in Oracle Cloud Infrastructure Vulnerability Scanning service.
1212

13-
Returns a list of ContainerScanRecipeSummaries
13+
Retrieves a list of ContainerScanRecipeSummary objects in a compartment. A recipe determines the types of security issues that you want scanned.
1414

1515

1616
## Example Usage
@@ -50,6 +50,7 @@ The following attributes are exported:
5050
* `display_name` - User friendly name of container scan recipe
5151
* `freeform_tags` - Simple key-value pair that is applied without any predefined name, type or scope. Exists for cross-compatibility only. Example: `{"bar-key": "value"}`
5252
* `id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of container scan recipe. Immutable and generated on creation.
53+
* `image_count` - This field is set equal to the number of images we want to scan in the first go when the recipe is created
5354
* `scan_settings` - A collection of container scan settings
5455
* `scan_level` - The scan level
5556
* `state` - The current state of the config.

website/docs/d/vulnerability_scanning_container_scan_target.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description: |-
1010
# Data Source: oci_vulnerability_scanning_container_scan_target
1111
This data source provides details about a specific Container Scan Target resource in Oracle Cloud Infrastructure Vulnerability Scanning service.
1212

13-
Gets a ContainerScanTarget by identifier
13+
Gets a ContainerScanTarget identified by the target ID. A container scan target specifies a group of one or more Docker image repositories in Oracle Cloud Infrastructure Registry (OCIR) that you want routinely scanned for security vulnerabilities.
1414

1515

1616
## Example Usage

website/docs/d/vulnerability_scanning_container_scan_targets.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description: |-
1010
# Data Source: oci_vulnerability_scanning_container_scan_targets
1111
This data source provides the list of Container Scan Targets in Oracle Cloud Infrastructure Vulnerability Scanning service.
1212

13-
Returns a list of ContainerScanTargetSummaries
13+
Retrieves a list of ContainerScanTargetSummary objects in a compartment. A container scan target specifies a group of one or more Docker image repositories in Oracle Cloud Infrastructure Registry (OCIR) that you want routinely scanned for security vulnerabilities.
1414

1515

1616
## Example Usage

0 commit comments

Comments
 (0)