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

resource/aws_imagebuilder_image_recipe: Ensure proper ordering of component configuration blocks #16566

Merged
merged 1 commit into from
Dec 9, 2020
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
2 changes: 1 addition & 1 deletion aws/data_source_aws_imagebuilder_image_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func dataSourceAwsImageBuilderImageRecipe() *schema.Resource {
},
},
"component": {
Type: schema.TypeSet,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
6 changes: 3 additions & 3 deletions aws/resource_aws_imagebuilder_image_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func resourceAwsImageBuilderImageRecipe() *schema.Resource {
},
},
"component": {
Type: schema.TypeSet,
Type: schema.TypeList,
Required: true,
ForceNew: true,
MinItems: 1,
Expand Down Expand Up @@ -185,8 +185,8 @@ func resourceAwsImageBuilderImageRecipeCreate(d *schema.ResourceData, meta inter
input.BlockDeviceMappings = expandImageBuilderInstanceBlockDeviceMappings(v.(*schema.Set).List())
}

if v, ok := d.GetOk("component"); ok && v.(*schema.Set).Len() > 0 {
input.Components = expandImageBuilderComponentConfigurations(v.(*schema.Set).List())
if v, ok := d.GetOk("component"); ok && len(v.([]interface{})) > 0 {
input.Components = expandImageBuilderComponentConfigurations(v.([]interface{}))
}

if v, ok := d.GetOk("description"); ok {
Expand Down
60 changes: 60 additions & 0 deletions aws/resource_aws_imagebuilder_image_recipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,34 @@ func TestAccAwsImageBuilderImageRecipe_BlockDeviceMapping_VirtualName(t *testing
})
}

func TestAccAwsImageBuilderImageRecipe_Component(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_imagebuilder_image_recipe.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsImageBuilderImageRecipeDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsImageBuilderImageRecipeConfigComponent(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsImageBuilderImageRecipeExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "component.#", "3"),
resource.TestCheckResourceAttrPair(resourceName, "component.0.component_arn", "data.aws_imagebuilder_component.aws-cli-version-2-linux", "arn"),
resource.TestCheckResourceAttrPair(resourceName, "component.1.component_arn", "data.aws_imagebuilder_component.update-linux", "arn"),
resource.TestCheckResourceAttrPair(resourceName, "component.2.component_arn", "aws_imagebuilder_component.test", "arn"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAwsImageBuilderImageRecipe_Description(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_imagebuilder_image_recipe.test"
Expand Down Expand Up @@ -787,6 +815,38 @@ resource "aws_imagebuilder_image_recipe" "test" {
`, rName, virtualName))
}

func testAccAwsImageBuilderImageRecipeConfigComponent(rName string) string {
return composeConfig(
testAccAwsImageBuilderImageRecipeConfigBase(rName),
fmt.Sprintf(`
data "aws_imagebuilder_component" "aws-cli-version-2-linux" {
arn = "arn:${data.aws_partition.current.partition}:imagebuilder:${data.aws_region.current.name}:aws:component/aws-cli-version-2-linux/1.0.0"
}

data "aws_imagebuilder_component" "update-linux" {
arn = "arn:${data.aws_partition.current.partition}:imagebuilder:${data.aws_region.current.name}:aws:component/update-linux/1.0.0"
}

resource "aws_imagebuilder_image_recipe" "test" {
component {
component_arn = data.aws_imagebuilder_component.aws-cli-version-2-linux.arn
}

component {
component_arn = data.aws_imagebuilder_component.update-linux.arn
}

component {
component_arn = aws_imagebuilder_component.test.arn
}

name = %[1]q
parent_image = "arn:${data.aws_partition.current.partition}:imagebuilder:${data.aws_region.current.name}:aws:image/amazon-linux-2-x86/x.x.x"
version = "1.0.0"
}
`, rName))
}

func testAccAwsImageBuilderImageRecipeConfigDescription(rName string, description string) string {
return composeConfig(
testAccAwsImageBuilderImageRecipeConfigBase(rName),
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/imagebuilder_image_recipe.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ In addition to all arguments above, the following attributes are exported:
* `volume_type` - Type of the volume. For example, `gp2` or `io2`.
* `no_device` - Whether to remove a mapping from the parent image.
* `virtual_name` - Virtual device name. For example, `ephemeral0`. Instance store volumes are numbered starting from 0.
* `component` - Set of objects with components for the image recipe.
* `component` - List of objects with components for the image recipe.
* `component_arn` - Amazon Resource Name (ARN) of the Image Builder Component.
* `date_created` - Date the image recipe was created.
* `description` - Description of the image recipe.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/imagebuilder_image_recipe.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ resource "aws_imagebuilder_image_recipe" "example" {

The following arguments are required:

* `component` - (Required) Configuration block(s) with components for the image recipe. Detailed below.
* `component` - (Required) Ordered configuration block(s) with components for the image recipe. Detailed below.
* `name` - (Required) Name of the image recipe.
* `parent_image` - (Required) Platform of the image recipe.
* `version` - (Required) Version of the image recipe.
Expand Down