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 Account ID to Launch Template Configuration #23924

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

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