Skip to content

Commit c19e908

Browse files
authored
Merge pull request #43950 from tabito-hara/f-aws_inspector2_filter-add_ecr_filters
[Enhancement] aws_inspector2_filter: Add missing `filter_criteria` support to `aws_inspector2_filter` resource
2 parents a7d0df8 + f8a217b commit c19e908

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

.changelog/43950.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_inspector2_filter: Support `code_repository_project_name`, `code_repository_provider_type`, `ecr_image_in_use_count`, and `ecr_image_last_in_use_at` in `filter_criteria`
3+
```

internal/service/inspector2/filter.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func (r *filterResource) Schema(ctx context.Context, request resource.SchemaRequ
7878
NestedObject: schema.NestedBlockObject{
7979
Blocks: map[string]schema.Block{
8080
names.AttrAWSAccountID: stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
81+
"code_repository_project_name": stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
82+
"code_repository_provider_type": stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
8183
"code_vulnerability_detector_name": stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
8284
"code_vulnerability_detector_tags": stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
8385
"code_vulnerability_file_path": stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
@@ -88,6 +90,8 @@ func (r *filterResource) Schema(ctx context.Context, request resource.SchemaRequ
8890
"ec2_instance_vpc_id": stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
8991
"ecr_image_architecture": stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
9092
"ecr_image_hash": stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
93+
"ecr_image_in_use_count": numberFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
94+
"ecr_image_last_in_use_at": dateFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
9195
"ecr_image_pushed_at": dateFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
9296
"ecr_image_registry": stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
9397
"ecr_image_repository_name": stringFilterSchemaFramework(ctx, defaultFilterSchemaMaxSize),
@@ -559,6 +563,8 @@ type filterResourceModel struct {
559563

560564
type filterCriteriaModel struct {
561565
AWSAccountID fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"aws_account_id"`
566+
CodeRepositoryProjectName fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"code_repository_project_name"`
567+
CodeRepositoryProviderType fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"code_repository_provider_type"`
562568
CodeVulnerabilityDetectorName fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"code_vulnerability_detector_name"`
563569
CodeVulnerabilityDetectorTags fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"code_vulnerability_detector_tags"`
564570
CodeVulnerabilityFilePath fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"code_vulnerability_file_path"`
@@ -569,6 +575,8 @@ type filterCriteriaModel struct {
569575
EC2InstanceVpcId fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"ec2_instance_vpc_id"`
570576
ECRImageArchitecture fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"ecr_image_architecture"`
571577
ECRImageHash fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"ecr_image_hash"`
578+
ECRImageInUseCount fwtypes.SetNestedObjectValueOf[numberFilterModel] `tfsdk:"ecr_image_in_use_count"`
579+
ECRImageLastInUseAt fwtypes.SetNestedObjectValueOf[dateFilterModel] `tfsdk:"ecr_image_last_in_use_at"`
572580
ECRImagePushedAt fwtypes.SetNestedObjectValueOf[dateFilterModel] `tfsdk:"ecr_image_pushed_at"`
573581
ECRImageRegistry fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"ecr_image_registry"`
574582
ECRImageRepositoryName fwtypes.SetNestedObjectValueOf[stringFilterModel] `tfsdk:"ecr_image_repository_name"`

internal/service/inspector2/filter_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ func testAccInspector2Filter_stringFilters(t *testing.T) {
181181
resource.TestCheckResourceAttr(resourceName, "reason", reason_1),
182182
resource.TestCheckResourceAttr(resourceName, names.AttrAction, action_1),
183183
resource.TestCheckResourceAttr(resourceName, "filter_criteria.#", "1"),
184+
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.code_repository_project_name.#", "1"),
185+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.code_repository_project_name.*", map[string]string{
186+
"comparison": comparison_1,
187+
names.AttrValue: value_1,
188+
}),
189+
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.code_repository_provider_type.#", "1"),
190+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.code_repository_provider_type.*", map[string]string{
191+
"comparison": comparison_1,
192+
names.AttrValue: value_1,
193+
}),
184194
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.code_vulnerability_detector_name.#", "1"),
185195
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.code_vulnerability_detector_name.*", map[string]string{
186196
"comparison": comparison_1,
@@ -205,6 +215,16 @@ func testAccInspector2Filter_stringFilters(t *testing.T) {
205215
resource.TestCheckResourceAttr(resourceName, names.AttrAction, action_2),
206216
resource.TestCheckResourceAttr(resourceName, "filter_criteria.#", "1"),
207217
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.code_vulnerability_detector_name.#", "1"),
218+
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.code_repository_project_name.#", "1"),
219+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.code_repository_project_name.*", map[string]string{
220+
"comparison": comparison_2,
221+
names.AttrValue: value_2,
222+
}),
223+
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.code_repository_provider_type.#", "1"),
224+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.code_repository_provider_type.*", map[string]string{
225+
"comparison": comparison_2,
226+
names.AttrValue: value_2,
227+
}),
208228
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.code_vulnerability_detector_name.*", map[string]string{
209229
"comparison": comparison_2,
210230
names.AttrValue: value_2,
@@ -257,6 +277,11 @@ func testAccInspector2Filter_numberFilters(t *testing.T) {
257277
resource.TestCheckResourceAttr(resourceName, "reason", reason_1),
258278
resource.TestCheckResourceAttr(resourceName, names.AttrAction, action_1),
259279
resource.TestCheckResourceAttr(resourceName, "filter_criteria.#", "1"),
280+
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.ecr_image_in_use_count.#", "1"),
281+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.ecr_image_in_use_count.*", map[string]string{
282+
"lower_inclusive": lower_inclusive_value_1,
283+
"upper_inclusive": upper_inclusive_value_1,
284+
}),
260285
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.epss_score.#", "1"),
261286
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.epss_score.*", map[string]string{
262287
"lower_inclusive": lower_inclusive_value_1,
@@ -280,6 +305,11 @@ func testAccInspector2Filter_numberFilters(t *testing.T) {
280305
resource.TestCheckResourceAttr(resourceName, "reason", reason_2),
281306
resource.TestCheckResourceAttr(resourceName, names.AttrAction, action_2),
282307
resource.TestCheckResourceAttr(resourceName, "filter_criteria.#", "1"),
308+
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.ecr_image_in_use_count.#", "1"),
309+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.ecr_image_in_use_count.*", map[string]string{
310+
"lower_inclusive": lower_inclusive_value_2,
311+
"upper_inclusive": upper_inclusive_value_2,
312+
}),
283313
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.epss_score.#", "1"),
284314
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.epss_score.*", map[string]string{
285315
"lower_inclusive": lower_inclusive_value_2,
@@ -333,6 +363,11 @@ func testAccInspector2Filter_dateFilters(t *testing.T) {
333363
resource.TestCheckResourceAttr(resourceName, "reason", reason_1),
334364
resource.TestCheckResourceAttr(resourceName, names.AttrAction, action_1),
335365
resource.TestCheckResourceAttr(resourceName, "filter_criteria.#", "1"),
366+
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.ecr_image_last_in_use_at.#", "1"),
367+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.ecr_image_last_in_use_at.*", map[string]string{
368+
"start_inclusive": start_inclusive_value_1,
369+
"end_inclusive": end_inclusive_value_1,
370+
}),
336371
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.ecr_image_pushed_at.#", "1"),
337372
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.ecr_image_pushed_at.*", map[string]string{
338373
"start_inclusive": start_inclusive_value_1,
@@ -356,6 +391,11 @@ func testAccInspector2Filter_dateFilters(t *testing.T) {
356391
resource.TestCheckResourceAttr(resourceName, "reason", reason_2),
357392
resource.TestCheckResourceAttr(resourceName, names.AttrAction, action_2),
358393
resource.TestCheckResourceAttr(resourceName, "filter_criteria.#", "1"),
394+
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.ecr_image_last_in_use_at.#", "1"),
395+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.ecr_image_last_in_use_at.*", map[string]string{
396+
"start_inclusive": start_inclusive_value_2,
397+
"end_inclusive": end_inclusive_value_2,
398+
}),
359399
resource.TestCheckResourceAttr(resourceName, "filter_criteria.0.ecr_image_pushed_at.#", "1"),
360400
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "filter_criteria.0.ecr_image_pushed_at.*", map[string]string{
361401
"start_inclusive": start_inclusive_value_2,
@@ -819,6 +859,14 @@ resource "aws_inspector2_filter" "test" {
819859
description = %[3]q
820860
reason = %[4]q
821861
filter_criteria {
862+
code_repository_project_name {
863+
comparison = %[5]q
864+
value = %[6]q
865+
}
866+
code_repository_provider_type {
867+
comparison = %[5]q
868+
value = %[6]q
869+
}
822870
code_vulnerability_detector_name {
823871
comparison = %[5]q
824872
value = %[6]q
@@ -836,6 +884,10 @@ resource "aws_inspector2_filter" "test" {
836884
description = %[3]q
837885
reason = %[4]q
838886
filter_criteria {
887+
ecr_image_in_use_count {
888+
lower_inclusive = %[5]q
889+
upper_inclusive = %[6]q
890+
}
839891
epss_score {
840892
lower_inclusive = %[5]q
841893
upper_inclusive = %[6]q
@@ -853,6 +905,10 @@ resource "aws_inspector2_filter" "test" {
853905
description = %[3]q
854906
reason = %[4]q
855907
filter_criteria {
908+
ecr_image_last_in_use_at {
909+
start_inclusive = %[5]q
910+
end_inclusive = %[6]q
911+
}
856912
ecr_image_pushed_at {
857913
start_inclusive = %[5]q
858914
end_inclusive = %[6]q

website/docs/r/inspector2_filter.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ This resource exports the following attributes in addition to the arguments abov
5454
The `filter_criteria` configuration block supports the following attributes:
5555

5656
* `aws_account_id` - (Optional) The AWS account ID in which the finding was generated. [Documented below](#string-filter).
57+
* `code_repository_project_name` - (Optional) The project name in a code repository. [Documented below](#string-filter).
58+
* `code_repository_provider_type` - (Optional) The repository provider type (such as GitHub, GitLab, etc.) [Documented below](#string-filter).
5759
* `code_vulnerability_detector_name` - (Optional) The ID of the component. [Documented below](#string-filter).
5860
* `code_vulnerability_detector_tags` - (Optional) The ID of the component. [Documented below](#string-filter).
5961
* `code_vulnerability_file_path` - (Optional) The ID of the component. [Documented below](#string-filter).
@@ -63,6 +65,8 @@ The `filter_criteria` configuration block supports the following attributes:
6365
* `ec2_instance_subnet_id` - (Optional) The ID of the subnet. [Documented below](#string-filter).
6466
* `ec2_instance_vpc_id` - (Optional) The ID of the VPC. [Documented below](#string-filter).
6567
* `ecr_image_architecture` - (Optional) The architecture of the ECR image. [Documented below](#string-filter).
68+
* `ecr_image_in_use_count` - (Optional) The number of the ECR images in use. [Documented below](#number-filter).
69+
* `ecr_image_last_in_use_at` - (Optional) The date range when an ECR image was last used in an ECS cluster task or EKS cluster pod. [Documented below](#date-filter).
6670
* `ecr_image_hash` - (Optional) The SHA256 hash of the ECR image. [Documented below](#string-filter).
6771
* `ecr_image_pushed_at` - (Optional) The date range when the image was pushed. [Documented below](#date-filter).
6872
* `ecr_image_registry` - (Optional) The registry of the ECR image. [Documented below](#string-filter).

0 commit comments

Comments
 (0)