diff --git a/.changelog/22077.txt b/.changelog/22077.txt new file mode 100644 index 00000000000..a0177ace1ae --- /dev/null +++ b/.changelog/22077.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_appstream_image_builder: Correctly create resource with `image_arn` argument +``` \ No newline at end of file diff --git a/internal/service/appstream/image_builder.go b/internal/service/appstream/image_builder.go index a0d713f065d..04704d2ce16 100644 --- a/internal/service/appstream/image_builder.go +++ b/internal/service/appstream/image_builder.go @@ -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, @@ -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)) } diff --git a/internal/service/appstream/image_builder_test.go b/internal/service/appstream/image_builder_test.go index 88716a3731e..7518ad8475b 100644 --- a/internal/service/appstream/image_builder_test.go +++ b/internal/service/appstream/image_builder_test.go @@ -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] @@ -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) +}