From 5a76c4fa30ef18e2dfd646d5687f584adddcd2c8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 23 Oct 2023 11:23:16 -0400 Subject: [PATCH] TestAccImageBuilderImage_basic: Enable Inspector ECR scanning. --- internal/service/imagebuilder/image_test.go | 29 ++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/service/imagebuilder/image_test.go b/internal/service/imagebuilder/image_test.go index 53583028e09..3f3cfd7265f 100644 --- a/internal/service/imagebuilder/image_test.go +++ b/internal/service/imagebuilder/image_test.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfimagebuilder "github.com/hashicorp/terraform-provider-aws/internal/service/imagebuilder" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccImageBuilderImage_basic(t *testing.T) { @@ -272,7 +273,12 @@ func TestAccImageBuilderImage_imageScanningConfiguration(t *testing.T) { resourceName := "aws_imagebuilder_image.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.Inspector2EndpointID) + acctest.PreCheckInspector2(ctx, t) + acctest.PreCheckOrganizationManagementAccount(ctx, t) + }, ErrorCheck: acctest.ErrorCheck(t, imagebuilder.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckImageDestroy(ctx), @@ -592,6 +598,10 @@ data "aws_partition" "current" {} resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" + + tags = { + Name = %[1]q + } } resource "aws_default_route_table" "test" { @@ -623,12 +633,20 @@ resource "aws_default_security_group" "test" { resource "aws_internet_gateway" "test" { vpc_id = aws_vpc.test.id + + tags = { + Name = %[1]q + } } resource "aws_subnet" "test" { cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, 0) map_public_ip_on_launch = true vpc_id = aws_vpc.test.id + + tags = { + Name = %[1]q + } } resource "aws_iam_role" "test" { @@ -722,6 +740,13 @@ func testAccImageConfig_imageScanningConfigurationEnabled(rName string) string { return acctest.ConfigCompose( testAccImageConfig_containerRecipeBase(rName), ` +data "aws_caller_identity" "current" {} + +resource "aws_inspector2_enabler" "test" { + account_ids = [data.aws_caller_identity.current.account_id] + resource_types = ["ECR"] +} + resource "aws_imagebuilder_image" "test" { container_recipe_arn = aws_imagebuilder_container_recipe.test.arn infrastructure_configuration_arn = aws_imagebuilder_infrastructure_configuration.test.arn @@ -734,6 +759,8 @@ resource "aws_imagebuilder_image" "test" { container_tags = ["foo", "bar"] } } + + depends_on = [aws_inspector2_enabler.test] } `) }