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

aws_imagebuilder_distribution_configuration: Add s3_export_configuration #35492

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
7 changes: 7 additions & 0 deletions .changelog/35492.txt
Original file line number Diff line number Diff line change
@@ -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
```
88 changes: 88 additions & 0 deletions internal/service/imagebuilder/distribution_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
},
},
},
},
},
},
},
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
Loading
Loading