diff --git a/.changelog/35492.txt b/.changelog/35492.txt new file mode 100644 index 00000000000..91b5ed4f5fc --- /dev/null +++ b/.changelog/35492.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +data-source/aws_imagebuilder_distribution_configuration: Add `distribution.s3_export_configuration` attribute +``` + +```release-note:enhancement +resource/aws_imagebuilder_distribution_configuration: Add `distribution.s3_export_configuration` argument +``` \ No newline at end of file diff --git a/internal/service/imagebuilder/distribution_configuration.go b/internal/service/imagebuilder/distribution_configuration.go index 913ed40c853..9c7fae24ccb 100644 --- a/internal/service/imagebuilder/distribution_configuration.go +++ b/internal/service/imagebuilder/distribution_configuration.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -279,6 +280,35 @@ func resourceDistributionConfiguration() *schema.Resource { Required: true, ValidateFunc: validation.StringLenBetween(0, 1024), }, + "s3_export_configuration": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disk_image_format": { + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.DiskImageFormat](), + }, + "role_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringLenBetween(1, 1024), + }, + names.AttrS3Bucket: { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringLenBetween(1, 1024), + }, + "s3_prefix": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween(1, 1024), + }, + }, + }, + }, }, }, }, @@ -543,6 +573,10 @@ func expandDistribution(tfMap map[string]interface{}) *awstypes.Distribution { apiObject.Region = aws.String(v) } + if v, ok := tfMap["s3_export_configuration"].([]interface{}); ok && len(v) > 0 && v[0] != nil { + apiObject.S3ExportConfiguration = expandS3ExportConfiguration(v[0].(map[string]interface{})) + } + return apiObject } @@ -737,6 +771,32 @@ func expandLaunchTemplateConfiguration(tfMap map[string]interface{}) *awstypes.L return apiObject } +func expandS3ExportConfiguration(tfMap map[string]interface{}) *awstypes.S3ExportConfiguration { + if tfMap == nil { + return nil + } + + apiObject := &awstypes.S3ExportConfiguration{} + + if v, ok := tfMap["disk_image_format"].(string); ok && v != "" { + apiObject.DiskImageFormat = awstypes.DiskImageFormat(v) + } + + if v, ok := tfMap["role_name"].(string); ok && v != "" { + apiObject.RoleName = aws.String(v) + } + + if v, ok := tfMap[names.AttrS3Bucket].(string); ok && v != "" { + apiObject.S3Bucket = aws.String(v) + } + + if v, ok := tfMap["s3_prefix"].(string); ok && v != "" { + apiObject.S3Prefix = aws.String(v) + } + + return apiObject +} + func flattenAMIDistributionConfiguration(apiObject *awstypes.AmiDistributionConfiguration) map[string]interface{} { if apiObject == nil { return nil @@ -834,6 +894,10 @@ func flattenDistribution(apiObject awstypes.Distribution) map[string]interface{} tfMap[names.AttrRegion] = aws.ToString(v) } + if v := apiObject.S3ExportConfiguration; v != nil { + tfMap["s3_export_configuration"] = []interface{}{flattenS3ExportConfiguration(v)} + } + return tfMap } @@ -982,3 +1046,27 @@ func flattenFastLaunchSnapshotConfiguration(apiObject *awstypes.FastLaunchSnapsh return tfMap } + +func flattenS3ExportConfiguration(apiObject *awstypes.S3ExportConfiguration) map[string]interface{} { + if apiObject == nil { + return nil + } + + tfMap := map[string]interface{}{ + "disk_image_format": apiObject.DiskImageFormat, + } + + if v := apiObject.RoleName; v != nil { + tfMap["role_name"] = aws.ToString(v) + } + + if v := apiObject.S3Bucket; v != nil { + tfMap[names.AttrS3Bucket] = aws.ToString(v) + } + + if v := apiObject.S3Prefix; v != nil { + tfMap["s3_prefix"] = aws.ToString(v) + } + + return tfMap +} diff --git a/internal/service/imagebuilder/distribution_configuration_data_source.go b/internal/service/imagebuilder/distribution_configuration_data_source.go index f560352bcc5..98bc0fef62b 100644 --- a/internal/service/imagebuilder/distribution_configuration_data_source.go +++ b/internal/service/imagebuilder/distribution_configuration_data_source.go @@ -227,6 +227,30 @@ func dataSourceDistributionConfiguration() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "s3_export_configuration": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disk_image_format": { + Type: schema.TypeString, + Computed: true, + }, + "role_name": { + Type: schema.TypeString, + Computed: true, + }, + names.AttrS3Bucket: { + Type: schema.TypeString, + Computed: true, + }, + "s3_prefix": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, }, }, }, diff --git a/internal/service/imagebuilder/distribution_configuration_data_source_test.go b/internal/service/imagebuilder/distribution_configuration_data_source_test.go index ba14cdd1dcd..9d45986fdd1 100644 --- a/internal/service/imagebuilder/distribution_configuration_data_source_test.go +++ b/internal/service/imagebuilder/distribution_configuration_data_source_test.go @@ -53,6 +53,11 @@ func TestAccImageBuilderDistributionConfigurationDataSource_arn(t *testing.T) { resource.TestCheckResourceAttrPair(dataSourceName, "distribution.0.launch_template_configuration.0.default", resourceName, "distribution.0.launch_template_configuration.0.default"), resource.TestCheckResourceAttrPair(dataSourceName, "distribution.0.launch_template_configuration.0.launch_template_id", resourceName, "distribution.0.launch_template_configuration.0.launch_template_id"), resource.TestCheckResourceAttrPair(dataSourceName, "distribution.0.launch_template_configuration.0.account_id", resourceName, "distribution.0.launch_template_configuration.0.account_id"), + resource.TestCheckResourceAttrPair(dataSourceName, "distribution.0.s3_export_configuration.#", resourceName, "distribution.0.s3_export_configuration.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "distribution.0.s3_export_configuration.0.disk_image_format", resourceName, "distribution.0.s3_export_configuration.0.disk_image_format"), + resource.TestCheckResourceAttrPair(dataSourceName, "distribution.0.s3_export_configuration.0.role_name", resourceName, "distribution.0.s3_export_configuration.0.role_name"), + resource.TestCheckResourceAttrPair(dataSourceName, "distribution.0.s3_export_configuration.0.s3_bucket", resourceName, "distribution.0.s3_export_configuration.0.s3_bucket"), + resource.TestCheckResourceAttrPair(dataSourceName, "distribution.0.s3_export_configuration.0.s3_prefix", resourceName, "distribution.0.s3_export_configuration.0.s3_prefix"), resource.TestCheckResourceAttrPair(dataSourceName, names.AttrName, resourceName, names.AttrName), resource.TestCheckResourceAttrPair(dataSourceName, acctest.CtTagsPercent, resourceName, acctest.CtTagsPercent), ), @@ -67,6 +72,10 @@ data "aws_region" "current" {} data "aws_caller_identity" "current" {} +resource "aws_s3_bucket" "test" { + bucket = %[1]q +} + resource "aws_launch_template" "test" { instance_type = "t2.micro" name = %[1]q @@ -109,6 +118,13 @@ resource "aws_imagebuilder_distribution_configuration" "test" { } } + s3_export_configuration { + disk_image_format = "RAW" + role_name = "role-name" + s3_bucket = aws_s3_bucket.test.id + s3_prefix = "prefix/" + } + region = data.aws_region.current.name } } diff --git a/internal/service/imagebuilder/distribution_configuration_test.go b/internal/service/imagebuilder/distribution_configuration_test.go index 021995ad802..df00e55e8a2 100644 --- a/internal/service/imagebuilder/distribution_configuration_test.go +++ b/internal/service/imagebuilder/distribution_configuration_test.go @@ -8,6 +8,7 @@ import ( "fmt" "testing" + awstypes "github.com/aws/aws-sdk-go-v2/service/imagebuilder/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -877,6 +878,289 @@ func TestAccImageBuilderDistributionConfiguration_Distribution_licenseARNs(t *te }) } +func TestAccImageBuilderDistributionConfiguration_DistributionS3Export_diskImageFormatRaw(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_imagebuilder_distribution_configuration.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ImageBuilderServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDistributionConfigurationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccDistributionConfigurationConfig_diskImageFormat(rName, string(awstypes.DiskImageFormatRaw)), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatRaw), + "s3_export_configuration.0.role_name": "role-name", + "s3_export_configuration.0.s3_bucket": rName, + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDistributionConfigurationConfig_diskImageFormat(rName, string(awstypes.DiskImageFormatRaw)), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatRaw), + "s3_export_configuration.0.role_name": "role-name", + "s3_export_configuration.0.s3_bucket": rName, + }), + ), + }, + }, + }) +} + +func TestAccImageBuilderDistributionConfiguration_DistributionS3Export_diskImageFormatVhd(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_imagebuilder_distribution_configuration.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ImageBuilderServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDistributionConfigurationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccDistributionConfigurationConfig_diskImageFormat(rName, string(awstypes.DiskImageFormatVhd)), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatVhd), + "s3_export_configuration.0.role_name": "role-name", + "s3_export_configuration.0.s3_bucket": rName, + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDistributionConfigurationConfig_diskImageFormat(rName, string(awstypes.DiskImageFormatVhd)), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatVhd), + "s3_export_configuration.0.role_name": "role-name", + "s3_export_configuration.0.s3_bucket": rName, + }), + ), + }, + }, + }) +} + +func TestAccImageBuilderDistributionConfiguration_DistributionS3Export_diskImageFormatVmdk(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_imagebuilder_distribution_configuration.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ImageBuilderServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDistributionConfigurationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccDistributionConfigurationConfig_diskImageFormat(rName, string(awstypes.DiskImageFormatVmdk)), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatVmdk), + "s3_export_configuration.0.role_name": "role-name", + "s3_export_configuration.0.s3_bucket": rName, + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDistributionConfigurationConfig_diskImageFormat(rName, string(awstypes.DiskImageFormatVmdk)), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatVmdk), + "s3_export_configuration.0.role_name": "role-name", + "s3_export_configuration.0.s3_bucket": rName, + }), + ), + }, + }, + }) +} + +func TestAccImageBuilderDistributionConfiguration_DistributionS3Export_roleName(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_imagebuilder_distribution_configuration.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ImageBuilderServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDistributionConfigurationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccDistributionConfigurationConfig_roleName(rName, "role1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatRaw), + "s3_export_configuration.0.role_name": "role1", + "s3_export_configuration.0.s3_bucket": rName, + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDistributionConfigurationConfig_roleName(rName, "role2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + acctest.CheckResourceAttrRFC3339(resourceName, "date_updated"), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatRaw), + "s3_export_configuration.0.role_name": "role2", + "s3_export_configuration.0.s3_bucket": rName, + }), + ), + }, + }, + }) +} + +func TestAccImageBuilderDistributionConfiguration_DistributionS3Export_s3Bucket(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_imagebuilder_distribution_configuration.test" + bucketName1 := sdkacctest.RandomWithPrefix("bucket1") + bucketName2 := sdkacctest.RandomWithPrefix("bucket2") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ImageBuilderServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDistributionConfigurationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccDistributionConfigurationConfig_s3Bucket(rName, bucketName1), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatRaw), + "s3_export_configuration.0.role_name": "role-name", + "s3_export_configuration.0.s3_bucket": bucketName1, + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDistributionConfigurationConfig_s3Bucket(rName, bucketName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + acctest.CheckResourceAttrRFC3339(resourceName, "date_updated"), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatRaw), + "s3_export_configuration.0.role_name": "role-name", + "s3_export_configuration.0.s3_bucket": bucketName2, + }), + ), + }, + }, + }) +} + +func TestAccImageBuilderDistributionConfiguration_DistributionS3Export_s3Prefix(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_imagebuilder_distribution_configuration.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.ImageBuilderServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDistributionConfigurationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccDistributionConfigurationConfig_s3Prefix(rName, "prefix1/"), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatRaw), + "s3_export_configuration.0.role_name": "role-name", + "s3_export_configuration.0.s3_bucket": rName, + "s3_export_configuration.0.s3_prefix": "prefix1/", + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDistributionConfigurationConfig_s3Prefix(rName, "prefix2/"), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(ctx, resourceName), + acctest.CheckResourceAttrRFC3339(resourceName, "date_updated"), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "distribution.*", map[string]string{ + "s3_export_configuration.#": "1", + "s3_export_configuration.0.disk_image_format": string(awstypes.DiskImageFormatRaw), + "s3_export_configuration.0.role_name": "role-name", + "s3_export_configuration.0.s3_bucket": rName, + "s3_export_configuration.0.s3_prefix": "prefix2/", + }), + ), + }, + }, + }) +} + func TestAccImageBuilderDistributionConfiguration_tags(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1559,6 +1843,87 @@ resource "aws_imagebuilder_distribution_configuration" "test" { `, rName) } +func testAccDistributionConfigurationConfig_diskImageFormat(rName string, diskImageFormat string) string { + return fmt.Sprintf(` +data "aws_region" "current" {} +resource "aws_s3_bucket" "test" { + bucket = %[1]q +} +resource "aws_imagebuilder_distribution_configuration" "test" { + name = %[1]q + distribution { + s3_export_configuration { + disk_image_format = %[2]q + role_name = "role-name" + s3_bucket = aws_s3_bucket.test.id + } + region = data.aws_region.current.name + } +} +`, rName, diskImageFormat) +} + +func testAccDistributionConfigurationConfig_roleName(rName string, roleName string) string { + return fmt.Sprintf(` +data "aws_region" "current" {} +resource "aws_s3_bucket" "test" { + bucket = %[1]q +} +resource "aws_imagebuilder_distribution_configuration" "test" { + name = %[1]q + distribution { + s3_export_configuration { + disk_image_format = "RAW" + role_name = %[2]q + s3_bucket = aws_s3_bucket.test.id + } + region = data.aws_region.current.name + } +} +`, rName, roleName) +} + +func testAccDistributionConfigurationConfig_s3Bucket(rName string, s3Bucket string) string { + return fmt.Sprintf(` +data "aws_region" "current" {} +resource "aws_s3_bucket" "test" { + bucket = %[2]q +} +resource "aws_imagebuilder_distribution_configuration" "test" { + name = %[1]q + distribution { + s3_export_configuration { + disk_image_format = "RAW" + role_name = "role-name" + s3_bucket = aws_s3_bucket.test.id + } + region = data.aws_region.current.name + } +} +`, rName, s3Bucket) +} + +func testAccDistributionConfigurationConfig_s3Prefix(rName string, s3Prefix string) string { + return fmt.Sprintf(` +data "aws_region" "current" {} +resource "aws_s3_bucket" "test" { + bucket = %[1]q +} +resource "aws_imagebuilder_distribution_configuration" "test" { + name = %[1]q + distribution { + s3_export_configuration { + disk_image_format = "RAW" + role_name = "role-name" + s3_bucket = aws_s3_bucket.test.id + s3_prefix = %[2]q + } + region = data.aws_region.current.name + } +} +`, rName, s3Prefix) +} + func testAccDistributionConfigurationConfig_tags1(rName string, tagKey1 string, tagValue1 string) string { return fmt.Sprintf(` data "aws_region" "current" {} diff --git a/website/docs/d/imagebuilder_distribution_configuration.html.markdown b/website/docs/d/imagebuilder_distribution_configuration.html.markdown index 358c4fb9c41..5d857ff16e9 100644 --- a/website/docs/d/imagebuilder_distribution_configuration.html.markdown +++ b/website/docs/d/imagebuilder_distribution_configuration.html.markdown @@ -62,5 +62,10 @@ This data source exports the following attributes in addition to the arguments a * `account_id` - The account ID that this configuration applies to. * `license_configuration_arns` - Set of Amazon Resource Names (ARNs) of License Manager License Configurations. * `region` - AWS Region of distribution. + * `s3_export_configuration` - Nested list of S3 export configuration. + * `disk_image_format` - The disk image format of the exported image (`RAW`, `VHD`, or `VMDK`) + * `role_name` - The name of the IAM role to use for exporting. + * `s3_bucket` - The name of the S3 bucket to store the exported image in. + * `s3_prefix` - The prefix for the exported image. * `name` - Name of the distribution configuration. * `tags` - Key-value map of resource tags for the distribution configuration. diff --git a/website/docs/r/imagebuilder_distribution_configuration.html.markdown b/website/docs/r/imagebuilder_distribution_configuration.html.markdown index f6c46ee83f7..76ae7bdf163 100644 --- a/website/docs/r/imagebuilder_distribution_configuration.html.markdown +++ b/website/docs/r/imagebuilder_distribution_configuration.html.markdown @@ -63,6 +63,7 @@ The following arguments are optional: * `fast_launch_configuration` - (Optional) Set of Windows faster-launching configurations to use for AMI distribution. Detailed below. * `launch_template_configuration` - (Optional) Set of launch template configuration settings that apply to image distribution. Detailed below. * `license_configuration_arns` - (Optional) Set of Amazon Resource Names (ARNs) of License Manager License Configurations. +* `s3_export_configuration` - (Optional) Configuration block with S3 export settings. Detailed below. ### ami_distribution_configuration @@ -119,6 +120,13 @@ The following arguments are optional: * `account_id` - The account ID that this configuration applies to. * `launch_template_id` - (Required) The ID of the Amazon EC2 launch template to use. +### s3_export_configuration + +* `disk_image_format` - (Required) The disk image format of the exported image (`RAW`, `VHD`, or `VMDK`) +* `role_name` - (Required) The name of the IAM role to use for exporting. +* `s3_bucket` - (Required) The name of the S3 bucket to store the exported image in. The bucket needs to exist before the export configuration is created. +* `s3_prefix` - (Optional) The prefix for the exported image. + ## Attribute Reference This resource exports the following attributes in addition to the arguments above: