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

r/appstream_image_builder: create with image_arn if configured #22077

Merged
merged 4 commits into from
Dec 7, 2021
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
3 changes: 3 additions & 0 deletions .changelog/22077.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_appstream_image_builder: Correctly create resource with `image_arn` argument
```
5 changes: 5 additions & 0 deletions internal/service/appstream/image_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func ResourceImageBuilder() *schema.Resource {
Computed: true,
ForceNew: true,
ExactlyOneOf: []string{"image_arn", "image_name"},
ValidateFunc: verify.ValidARN,
},
"image_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -204,6 +205,10 @@ func resourceImageBuilderCreate(ctx context.Context, d *schema.ResourceData, met
input.EnableDefaultInternetAccess = aws.Bool(v.(bool))
}

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

if v, ok := d.GetOk("image_name"); ok {
input.ImageName = aws.String(v.(string))
}
Expand Down
42 changes: 42 additions & 0 deletions internal/service/appstream/image_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,36 @@ func TestAccAppStreamImageBuilder_tags(t *testing.T) {
})
}

func TestAccAppStreamImageBuilder_imageARN(t *testing.T) {
resourceName := "aws_appstream_image_builder.test"
// imageName selected from the available AWS Managed AppStream 2.0 Base Images
// Reference: https://docs.aws.amazon.com/appstream2/latest/developerguide/base-image-version-history.html
imageName := "AppStream-WinServer2012R2-07-19-2021"
instanceType := "stream.standard.small"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckImageBuilderDestroy,
ErrorCheck: acctest.ErrorCheck(t, appstream.EndpointsID),
Steps: []resource.TestStep{
{
Config: testAccImageBuilderByImageARNConfig(rName, imageName, instanceType),
Check: resource.ComposeTestCheckFunc(
testAccCheckImageBuilderExists(resourceName),
acctest.CheckResourceAttrRegionalARNNoAccount(resourceName, "image_arn", "appstream", fmt.Sprintf("image/%s", imageName)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckImageBuilderExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -280,3 +310,15 @@ resource "aws_appstream_image_builder" "test" {
}
`, instanceType, name, key1, value1, key2, value2)
}

func testAccImageBuilderByImageARNConfig(rName, imageName, instanceType string) string {
return fmt.Sprintf(`
data "aws_partition" "current" {}

resource "aws_appstream_image_builder" "test" {
image_arn = "arn:${data.aws_partition.current.partition}:appstream:%[1]s::image/%[2]s"
instance_type = %[3]q
name = %[4]q
}
`, acctest.Region(), imageName, instanceType, rName)
}