Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rd/aws_imagebuilder_image_pipeline - add support for container_recipe_arn #23111

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/23111.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_imagebuilder_image_pipeline: Add `container_recipe_arn` argument
```

```release-note:enhancement
data-source/aws_imagebuilder_image_pipeline: Add `container_recipe_arn` attribute
```
19 changes: 18 additions & 1 deletion internal/service/imagebuilder/image_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ func ResourceImagePipeline() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"container_recipe_arn": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^arn:aws[^:]*:imagebuilder:[^:]+:(?:\d{12}|aws):container-recipe/[a-z0-9-_]+/\d+\.\d+\.\d+$`), "valid container recipe ARN must be provided"),
ExactlyOneOf: []string{"container_recipe_arn", "image_recipe_arn"},
},
"date_created": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -64,9 +71,10 @@ func ResourceImagePipeline() *schema.Resource {
},
"image_recipe_arn": {
Type: schema.TypeString,
Required: true,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^arn:aws[^:]*:imagebuilder:[^:]+:(?:\d{12}|aws):image-recipe/[a-z0-9-_]+/\d+\.\d+\.\d+$`), "valid image recipe ARN must be provided"),
ExactlyOneOf: []string{"container_recipe_arn", "image_recipe_arn"},
},
"image_tests_configuration": {
Type: schema.TypeList,
Expand Down Expand Up @@ -148,6 +156,10 @@ func resourceImagePipelineCreate(d *schema.ResourceData, meta interface{}) error
EnhancedImageMetadataEnabled: aws.Bool(d.Get("enhanced_image_metadata_enabled").(bool)),
}

if v, ok := d.GetOk("container_recipe_arn"); ok {
input.ContainerRecipeArn = aws.String(v.(string))
}

if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
}
Expand Down Expand Up @@ -227,6 +239,7 @@ func resourceImagePipelineRead(d *schema.ResourceData, meta interface{}) error {
imagePipeline := output.ImagePipeline

d.Set("arn", imagePipeline.Arn)
d.Set("container_recipe_arn", imagePipeline.ContainerRecipeArn)
d.Set("date_created", imagePipeline.DateCreated)
d.Set("date_last_run", imagePipeline.DateLastRun)
d.Set("date_next_run", imagePipeline.DateNextRun)
Expand Down Expand Up @@ -286,6 +299,10 @@ func resourceImagePipelineUpdate(d *schema.ResourceData, meta interface{}) error
ImagePipelineArn: aws.String(d.Id()),
}

if v, ok := d.GetOk("container_recipe_arn"); ok {
input.ContainerRecipeArn = aws.String(v.(string))
}

if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
}
Expand Down
5 changes: 5 additions & 0 deletions internal/service/imagebuilder/image_pipeline_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func DataSourceImagePipeline() *schema.Resource {
Required: true,
ValidateFunc: verify.ValidARN,
},
"container_recipe_arn": {
Type: schema.TypeString,
Computed: true,
},
"date_created": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -129,6 +133,7 @@ func dataSourceImagePipelineRead(d *schema.ResourceData, meta interface{}) error

d.SetId(aws.StringValue(imagePipeline.Arn))
d.Set("arn", imagePipeline.Arn)
d.Set("container_recipe_arn", imagePipeline.ContainerRecipeArn)
d.Set("date_created", imagePipeline.DateCreated)
d.Set("date_last_run", imagePipeline.DateLastRun)
d.Set("date_next_run", imagePipeline.DateNextRun)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccImageBuilderImagePipelineDataSource_arn(t *testing.T) {
Config: testAccImagePipelineARNDataSourceConfig(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "container_recipe_arn", resourceName, "container_recipe_arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "date_created", resourceName, "date_created"),
resource.TestCheckResourceAttrPair(dataSourceName, "date_last_run", resourceName, "date_last_run"),
resource.TestCheckResourceAttrPair(dataSourceName, "date_next_run", resourceName, "date_next_run"),
Expand All @@ -46,7 +47,29 @@ func TestAccImageBuilderImagePipelineDataSource_arn(t *testing.T) {
})
}

func testAccImagePipelineARNDataSourceConfig(rName string) string {
func TestAccImageBuilderImagePipelineDataSource_containerRecipeARN(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
dataSourceName := "data.aws_imagebuilder_image_pipeline.test"
resourceName := "aws_imagebuilder_image_pipeline.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, imagebuilder.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckImagePipelineDestroy,
Steps: []resource.TestStep{
{
Config: testAccImagePipelineContainerRecipeARNDataSourceConfig(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "container_recipe_arn", resourceName, "container_recipe_arn"),
),
},
},
})
}

func testAccImagePipelineBaseDataSourceConfig(rName string) string {
return fmt.Sprintf(`
data "aws_region" "current" {}

Expand Down Expand Up @@ -92,6 +115,17 @@ resource "aws_imagebuilder_component" "test" {
version = "1.0.0"
}

resource "aws_imagebuilder_infrastructure_configuration" "test" {
instance_profile_name = aws_iam_instance_profile.test.name
name = %[1]q
}
`, rName)
}

func testAccImagePipelineARNDataSourceConfig(rName string) string {
return acctest.ConfigCompose(
testAccImagePipelineBaseDataSourceConfig(rName),
fmt.Sprintf(`
resource "aws_imagebuilder_image_recipe" "test" {
component {
component_arn = aws_imagebuilder_component.test.arn
Expand All @@ -102,19 +136,56 @@ resource "aws_imagebuilder_image_recipe" "test" {
version = "1.0.0"
}

resource "aws_imagebuilder_infrastructure_configuration" "test" {
instance_profile_name = aws_iam_instance_profile.test.name
name = %[1]q
resource "aws_imagebuilder_image_pipeline" "test" {
image_recipe_arn = aws_imagebuilder_image_recipe.test.arn
infrastructure_configuration_arn = aws_imagebuilder_infrastructure_configuration.test.arn
name = %[1]q
}

data "aws_imagebuilder_image_pipeline" "test" {
arn = aws_imagebuilder_image_pipeline.test.arn
}
`, rName))
}

func testAccImagePipelineContainerRecipeARNDataSourceConfig(rName string) string {
return acctest.ConfigCompose(
testAccImagePipelineBaseDataSourceConfig(rName),
fmt.Sprintf(`
resource "aws_ecr_repository" "test" {
name = %[1]q
}

resource "aws_imagebuilder_container_recipe" "test" {
component {
component_arn = aws_imagebuilder_component.test.arn
}

dockerfile_template_data = <<EOF
FROM {{{ imagebuilder:parentImage }}}
{{{ imagebuilder:environments }}}
{{{ imagebuilder:components }}}
EOF

name = %[1]q
container_type = "DOCKER"
parent_image = "arn:${data.aws_partition.current.partition}:imagebuilder:${data.aws_region.current.name}:aws:image/amazon-linux-x86-latest/x.x.x"
version = "1.0.0"

target_repository {
repository_name = aws_ecr_repository.test.name
service = "ECR"
}
}

resource "aws_imagebuilder_image_pipeline" "test" {
image_recipe_arn = aws_imagebuilder_image_recipe.test.arn
container_recipe_arn = aws_imagebuilder_container_recipe.test.arn
infrastructure_configuration_arn = aws_imagebuilder_infrastructure_configuration.test.arn
name = %[1]q
}

data "aws_imagebuilder_image_pipeline" "test" {
arn = aws_imagebuilder_image_pipeline.test.arn
}
`, rName)
`, rName))
}
111 changes: 111 additions & 0 deletions internal/service/imagebuilder/image_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,41 @@ func TestAccImageBuilderImagePipeline_imageRecipeARN(t *testing.T) {
})
}

func TestAccImageBuilderImagePipeline_containerRecipeARN(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
containerRecipeResourceName := "aws_imagebuilder_container_recipe.test"
containerRecipeResourceName2 := "aws_imagebuilder_container_recipe.test2"
resourceName := "aws_imagebuilder_image_pipeline.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, imagebuilder.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckImagePipelineDestroy,
Steps: []resource.TestStep{
{
Config: testAccImagePipelineContainerRecipeARN1Config(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckImagePipelineExists(resourceName),
resource.TestCheckResourceAttrPair(resourceName, "container_recipe_arn", containerRecipeResourceName, "arn"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccImagePipelineContainerRecipeARN2Config(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckImagePipelineExists(resourceName),
resource.TestCheckResourceAttrPair(resourceName, "container_recipe_arn", containerRecipeResourceName2, "arn"),
),
},
},
})
}

func TestAccImageBuilderImagePipeline_ImageTests_imageTestsEnabled(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_imagebuilder_image_pipeline.test"
Expand Down Expand Up @@ -691,6 +726,82 @@ resource "aws_imagebuilder_image_pipeline" "test" {
`, rName))
}

func testAccImagePipelineContainerRecipeARN1Config(rName string) string {
return acctest.ConfigCompose(
testAccImagePipelineBaseConfig(rName),
fmt.Sprintf(`
resource "aws_ecr_repository" "test" {
name = %[1]q
}

resource "aws_imagebuilder_container_recipe" "test" {
component {
component_arn = aws_imagebuilder_component.test.arn
}

dockerfile_template_data = <<EOF
FROM {{{ imagebuilder:parentImage }}}
{{{ imagebuilder:environments }}}
{{{ imagebuilder:components }}}
EOF

name = %[1]q
container_type = "DOCKER"
parent_image = "arn:${data.aws_partition.current.partition}:imagebuilder:${data.aws_region.current.name}:aws:image/amazon-linux-x86-latest/x.x.x"
version = "1.0.0"

target_repository {
repository_name = aws_ecr_repository.test.name
service = "ECR"
}
}

resource "aws_imagebuilder_image_pipeline" "test" {
container_recipe_arn = aws_imagebuilder_container_recipe.test.arn
infrastructure_configuration_arn = aws_imagebuilder_infrastructure_configuration.test.arn
name = %[1]q
}
`, rName))
}

func testAccImagePipelineContainerRecipeARN2Config(rName string) string {
return acctest.ConfigCompose(
testAccImagePipelineBaseConfig(rName),
fmt.Sprintf(`
resource "aws_ecr_repository" "test" {
name = %[1]q
}

resource "aws_imagebuilder_container_recipe" "test2" {
component {
component_arn = aws_imagebuilder_component.test.arn
}

dockerfile_template_data = <<EOF
FROM {{{ imagebuilder:parentImage }}}
{{{ imagebuilder:environments }}}
{{{ imagebuilder:components }}}
EOF

name = "%[1]s-2"
container_type = "DOCKER"
parent_image = "arn:${data.aws_partition.current.partition}:imagebuilder:${data.aws_region.current.name}:aws:image/amazon-linux-x86-latest/x.x.x"
version = "1.0.0"

target_repository {
repository_name = aws_ecr_repository.test.name
service = "ECR"
}
}

resource "aws_imagebuilder_image_pipeline" "test" {
container_recipe_arn = aws_imagebuilder_container_recipe.test2.arn
infrastructure_configuration_arn = aws_imagebuilder_infrastructure_configuration.test.arn
name = %[1]q
}
`, rName))
}

func testAccImagePipelineImageTestsConfigurationImageTestsEnabledConfig(rName string, imageTestsEnabled bool) string {
return acctest.ConfigCompose(
testAccImagePipelineBaseConfig(rName),
Expand Down
3 changes: 2 additions & 1 deletion website/docs/d/imagebuilder_image_pipeline.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ data "aws_imagebuilder_image_pipeline" "example" {

In addition to all arguments above, the following attributes are exported:

* `container_recipe_arn` - Amazon Resource Name (ARN) of the container recipe.
* `date_created` - Date the image pipeline was created.
* `date_last_run` - Date the image pipeline was last run.
* `date_next_run` - Date the image pipeline will run next.
* `date_updated` - Date the image pipeline was updated.
* `description` - Description of the image pipeline.
* `distribution_configuration_arn` - Amazon Resource Name (ARN) of the Image Builder Distribution Configuration.
* `enhanced_image_metadata_enabled` - Whether additional information about the image being created is collected.
* `image_recipe_arn` - Amazon Resource Name (ARN) of the Image Builder Infrastructure Recipe.
* `image_recipe_arn` - Amazon Resource Name (ARN) of the image recipe.
* `image_tests_configuration` - List of an object with image tests configuration.
* `image_tests_enabled` - Whether image tests are enabled.
* `timeout_minutes` - Number of minutes before image tests time out.
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/imagebuilder_image_pipeline.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ resource "aws_imagebuilder_image_pipeline" "example" {

The following arguments are required:

* `image_recipe_arn` - (Required) Amazon Resource Name (ARN) of the Image Builder Infrastructure Recipe.
* `infrastructure_configuration_arn` - (Required) Amazon Resource Name (ARN) of the Image Builder Infrastructure Configuration.
* `name` - (Required) Name of the image pipeline.

The following arguments are optional:

* `container_recipe_arn` - (Optional) Amazon Resource Name (ARN) of the container recipe.
* `description` - (Optional) Description of the image pipeline.
* `distribution_configuration_arn` - (Optional) Amazon Resource Name (ARN) of the Image Builder Distribution Configuration.
* `enhanced_image_metadata_enabled` - (Optional) Whether additional information about the image being created is collected. Defaults to `true`.
* `image_recipe_arn` - (Optional) Amazon Resource Name (ARN) of the image recipe.
* `image_tests_configuration` - (Optional) Configuration block with image tests configuration. Detailed below.
* `schedule` - (Optional) Configuration block with schedule settings. Detailed below.
* `status` - (Optional) Status of the image pipeline. Valid values are `DISABLED` and `ENABLED`. Defaults to `ENABLED`.
Expand Down