Skip to content

Commit

Permalink
Merge branch 'schabert-f-add-additional-property-to-imagebuilder'
Browse files Browse the repository at this point in the history
  • Loading branch information
bflad committed Jan 4, 2021
2 parents 1a65888 + c764155 commit 523019a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
5 changes: 5 additions & 0 deletions aws/data_source_aws_imagebuilder_image_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func dataSourceAwsImageBuilderImageRecipe() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"working_directory": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -154,6 +158,7 @@ func dataSourceAwsImageBuilderImageRecipeRead(d *schema.ResourceData, meta inter
d.Set("platform", imageRecipe.Platform)
d.Set("tags", keyvaluetags.ImagebuilderKeyValueTags(imageRecipe.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map())
d.Set("version", imageRecipe.Version)
d.Set("working_directory", imageRecipe.WorkingDirectory)

return nil
}
1 change: 1 addition & 0 deletions aws/data_source_aws_imagebuilder_image_recipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestAccAwsImageBuilderImageRecipeDataSource_Arn(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceName, "platform", resourceName, "platform"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(dataSourceName, "version", resourceName, "version"),
resource.TestCheckResourceAttrPair(dataSourceName, "working_directory", resourceName, "working_directory"),
),
},
},
Expand Down
10 changes: 10 additions & 0 deletions aws/resource_aws_imagebuilder_image_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ func resourceAwsImageBuilderImageRecipe() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 128),
},
"working_directory": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 1024),
},
},
}
}
Expand Down Expand Up @@ -208,6 +214,9 @@ func resourceAwsImageBuilderImageRecipeCreate(d *schema.ResourceData, meta inter
if v, ok := d.GetOk("version"); ok {
input.SemanticVersion = aws.String(v.(string))
}
if v, ok := d.GetOk("working_directory"); ok {
input.WorkingDirectory = aws.String(v.(string))
}

output, err := conn.CreateImageRecipe(input)

Expand Down Expand Up @@ -261,6 +270,7 @@ func resourceAwsImageBuilderImageRecipeRead(d *schema.ResourceData, meta interfa
d.Set("platform", imageRecipe.Platform)
d.Set("tags", keyvaluetags.ImagebuilderKeyValueTags(imageRecipe.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map())
d.Set("version", imageRecipe.Version)
d.Set("working_directory", imageRecipe.WorkingDirectory)

return nil
}
Expand Down
42 changes: 42 additions & 0 deletions aws/resource_aws_imagebuilder_image_recipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,31 @@ func TestAccAwsImageBuilderImageRecipe_Tags(t *testing.T) {
})
}

func TestAccAwsImageBuilderImageRecipe_WorkingDirectory(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: testAccAwsImageBuilderImageRecipeConfigWorkingDirectory(rName, "/tmp"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsImageBuilderImageRecipeExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "working_directory", "/tmp"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckAwsImageBuilderImageRecipeDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).imagebuilderconn

Expand Down Expand Up @@ -920,3 +945,20 @@ resource "aws_imagebuilder_image_recipe" "test" {
}
`, rName, tagKey1, tagValue1, tagKey2, tagValue2))
}

func testAccAwsImageBuilderImageRecipeConfigWorkingDirectory(rName string, workingDirectory string) string {
return composeConfig(
testAccAwsImageBuilderImageRecipeConfigBase(rName),
fmt.Sprintf(`
resource "aws_imagebuilder_image_recipe" "test" {
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"
working_directory = %[2]q
}
`, rName, workingDirectory))
}
3 changes: 2 additions & 1 deletion website/docs/d/imagebuilder_image_recipe.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ In addition to all arguments above, the following attributes are exported:
* `owner` - Owner of the image recipe.
* `parent_image` - Platform of the image recipe.
* `platform` - Platform of the image recipe.
* `tags` - (Optional) Key-value map of resource tags for the image recipe.
* `tags` - Key-value map of resource tags for the image recipe.
* `version` - Version of the image recipe.
* `working_directory` - The working directory used during build and test workflows.
1 change: 1 addition & 0 deletions website/docs/r/imagebuilder_image_recipe.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The following attributes are optional:
* `block_device_mapping` - (Optional) Configuration block(s) with block device mappings for the the image recipe. Detailed below.
* `description` - (Optional) Description of the image recipe.
* `tags` - (Optional) Key-value map of resource tags for the image recipe.
* `working_directory` - (Optional) The working directory to be used during build and test workflows.

### block_device_mapping

Expand Down

0 comments on commit 523019a

Please sign in to comment.