diff --git a/.changelog/23924.txt b/.changelog/23924.txt new file mode 100644 index 000000000000..fa468d2b616d --- /dev/null +++ b/.changelog/23924.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_imagebuilder_distribution_configuration: Add `account_id` argument to the `launch_template_configuration` attribute of the `distribution` configuration block +``` + +```release-note:enhancement +data-source/aws_imagebuilder_distribution_configuration: Add `account_id` attribute to the `launch_template_configuration` attribute of the `distribution` configuration block +``` diff --git a/internal/service/imagebuilder/distribution_configuration.go b/internal/service/imagebuilder/distribution_configuration.go index c281c4b0b973..5879ac978b87 100644 --- a/internal/service/imagebuilder/distribution_configuration.go +++ b/internal/service/imagebuilder/distribution_configuration.go @@ -174,6 +174,11 @@ func ResourceDistributionConfiguration() *schema.Resource { MaxItems: 100, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: verify.ValidAccountID, + }, "default": { Type: schema.TypeBool, Optional: true, @@ -563,6 +568,10 @@ func expandLaunchTemplateConfiguration(tfMap map[string]interface{}) *imagebuild apiObject.SetDefaultVersion = aws.Bool(v) } + if v, ok := tfMap["account_id"].(string); ok && v != "" { + apiObject.AccountId = aws.String(v) + } + return apiObject } @@ -747,5 +756,9 @@ func flattenLaunchTemplateConfiguration(apiObject *imagebuilder.LaunchTemplateCo tfMap["default"] = aws.BoolValue(v) } + if v := apiObject.AccountId; v != nil { + tfMap["account_id"] = aws.StringValue(v) + } + return tfMap } diff --git a/internal/service/imagebuilder/distribution_configuration_data_source.go b/internal/service/imagebuilder/distribution_configuration_data_source.go index 85f45f4ede20..8107016f7638 100644 --- a/internal/service/imagebuilder/distribution_configuration_data_source.go +++ b/internal/service/imagebuilder/distribution_configuration_data_source.go @@ -142,6 +142,10 @@ func DataSourceDistributionConfiguration() *schema.Resource { Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeString, + Computed: true, + }, "default": { Type: schema.TypeBool, 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 d09e4aac246b..388d81891672 100644 --- a/internal/service/imagebuilder/distribution_configuration_data_source_test.go +++ b/internal/service/imagebuilder/distribution_configuration_data_source_test.go @@ -38,6 +38,7 @@ func TestAccImageBuilderDistributionConfigurationDataSource_arn(t *testing.T) { resource.TestCheckResourceAttrPair(dataSourceName, "distribution.0.launch_template_configuration.#", resourceName, "distribution.0.launch_template_configuration.#"), 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, "name", resourceName, "name"), resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), ), @@ -50,6 +51,8 @@ func testAccDistributionConfigurationARNDataSourceConfig(rName string) string { return fmt.Sprintf(` data "aws_region" "current" {} +data "aws_caller_identity" "current" {} + resource "aws_launch_template" "test" { instance_type = "t2.micro" name = %[1]q @@ -71,6 +74,7 @@ resource "aws_imagebuilder_distribution_configuration" "test" { } launch_template_configuration { + account_id = data.aws_caller_identity.current.account_id default = false launch_template_id = aws_launch_template.test.id } diff --git a/internal/service/imagebuilder/distribution_configuration_test.go b/internal/service/imagebuilder/distribution_configuration_test.go index e0681d3973e4..588aabefbbf9 100644 --- a/internal/service/imagebuilder/distribution_configuration_test.go +++ b/internal/service/imagebuilder/distribution_configuration_test.go @@ -624,6 +624,18 @@ func TestAccImageBuilderDistributionConfiguration_Distribution_launchTemplateCon resource.TestCheckResourceAttrPair(resourceName, "distribution.0.launch_template_configuration.0.launch_template_id", launchTemplateResourceName, "id"), ), }, + { + Config: testAccDistributionConfigurationDistributionLaunchTemplateConfigurationLaunchTemplateIDAccountIDConfig(rName, "111111111111"), + Check: resource.ComposeTestCheckFunc( + testAccCheckDistributionConfigurationExists(resourceName), + acctest.CheckResourceAttrRFC3339(resourceName, "date_updated"), + resource.TestCheckResourceAttr(resourceName, "distribution.#", "1"), + resource.TestCheckResourceAttr(resourceName, "distribution.0.launch_template_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "distribution.0.launch_template_configuration.0.default", "false"), + resource.TestCheckResourceAttrPair(resourceName, "distribution.0.launch_template_configuration.0.launch_template_id", launchTemplateResourceName, "id"), + resource.TestCheckResourceAttr(resourceName, "distribution.0.launch_template_configuration.0.account_id", "111111111111"), + ), + }, }, }) } @@ -1093,6 +1105,8 @@ func testAccDistributionConfigurationDistributionLaunchTemplateConfigurationLaun return fmt.Sprintf(` data "aws_region" "current" {} +data "aws_caller_identity" "current" {} + resource "aws_launch_template" "test" { instance_type = "t2.micro" name = %[1]q @@ -1105,6 +1119,7 @@ resource "aws_imagebuilder_distribution_configuration" "test" { launch_template_configuration { default = true launch_template_id = aws_launch_template.test.id + account_id = data.aws_caller_identity.current.account_id } region = data.aws_region.current.name @@ -1117,6 +1132,8 @@ func testAccDistributionConfigurationDistributionLaunchTemplateConfigurationLaun return fmt.Sprintf(` data "aws_region" "current" {} +data "aws_caller_identity" "current" {} + resource "aws_launch_template" "test" { instance_type = "t2.micro" name = %[1]q @@ -1129,6 +1146,7 @@ resource "aws_imagebuilder_distribution_configuration" "test" { launch_template_configuration { default = false launch_template_id = aws_launch_template.test.id + account_id = data.aws_caller_identity.current.account_id } region = data.aws_region.current.name @@ -1137,6 +1155,37 @@ resource "aws_imagebuilder_distribution_configuration" "test" { `, rName) } +func testAccDistributionConfigurationDistributionLaunchTemplateConfigurationLaunchTemplateIDAccountIDConfig(rName string, accountId string) string { + return fmt.Sprintf(` +data "aws_region" "current" {} + +resource "aws_launch_template" "test" { + instance_type = "t2.micro" + name = %[1]q +} + +resource "aws_imagebuilder_distribution_configuration" "test" { + name = %[1]q + + distribution { + launch_template_configuration { + default = false + launch_template_id = aws_launch_template.test.id + account_id = %[2]q + } + + ami_distribution_configuration { + launch_permission { + user_ids = [%[2]q] + } + } + + region = data.aws_region.current.name + } +} + `, rName, accountId) +} + func testAccDistributionConfigurationDistributionLicenseConfigurationARNs1Config(rName 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 ccbd7cfc25bc..7279e56abd7a 100644 --- a/website/docs/d/imagebuilder_distribution_configuration.html.markdown +++ b/website/docs/d/imagebuilder_distribution_configuration.html.markdown @@ -49,6 +49,7 @@ In addition to all arguments above, the following attributes are exported: * `launch_template_configuration` - Nested list of launch template configurations. * `default` - Indicates whether the specified Amazon EC2 launch template is set as the default launch template. * `launch_template_id` - ID of the Amazon EC2 launch template. + * `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. * `name` - Name of the distribution configuration. diff --git a/website/docs/r/imagebuilder_distribution_configuration.html.markdown b/website/docs/r/imagebuilder_distribution_configuration.html.markdown index ee099916d39c..47e0ac047159 100644 --- a/website/docs/r/imagebuilder_distribution_configuration.html.markdown +++ b/website/docs/r/imagebuilder_distribution_configuration.html.markdown @@ -98,6 +98,7 @@ The following arguments are optional: ### launch_template_configuration * `default` - (Optional) Indicates whether to set the specified Amazon EC2 launch template as the default launch template. Defaults to `true`. +* `account_id` - The account ID that this configuration applies to. * `launch_template_id` - (Required) The ID of the Amazon EC2 launch template to use. ## Attributes Reference