Skip to content

Commit 4235a17

Browse files
author
Tamir
committed
squash all
1 parent e8b284b commit 4235a17

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

.changelog/30294.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
data-source/aws_ami_ids: Add optional `include_deprecated` argument.
3+
```

internal/service/ec2/ec2_ami_ids_data_source.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func DataSourceAMIIDs() *schema.Resource {
5858
Default: false,
5959
Optional: true,
6060
},
61+
"include_deprecated": {
62+
Type: schema.TypeBool,
63+
Default: false,
64+
Optional: true,
65+
},
6166
},
6267
}
6368
}
@@ -67,7 +72,8 @@ func dataSourceAMIIDsRead(ctx context.Context, d *schema.ResourceData, meta inte
6772
conn := meta.(*conns.AWSClient).EC2Conn()
6873

6974
input := &ec2.DescribeImagesInput{
70-
Owners: flex.ExpandStringList(d.Get("owners").([]interface{})),
75+
Owners: flex.ExpandStringList(d.Get("owners").([]interface{})),
76+
IncludeDeprecated: aws.Bool(d.Get("include_deprecated").(bool)),
7177
}
7278

7379
if v, ok := d.GetOk("executable_users"); ok {

internal/service/ec2/ec2_ami_ids_data_source_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ func TestAccEC2AMIIDsDataSource_sorted(t *testing.T) {
5757
})
5858
}
5959

60+
func TestAccEC2AMIIDsDataSource_includeDeprecated(t *testing.T) {
61+
ctx := acctest.Context(t)
62+
datasourceName := "data.aws_ami_ids.test"
63+
64+
resource.ParallelTest(t, resource.TestCase{
65+
PreCheck: func() { acctest.PreCheck(ctx, t) },
66+
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
67+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
68+
Steps: []resource.TestStep{
69+
{
70+
Config: testAccAMIIDsDataSourceConfig_includeDeprecated(true),
71+
Check: resource.ComposeTestCheckFunc(
72+
acctest.CheckResourceAttrGreaterThanValue(datasourceName, "ids.#", "0"),
73+
),
74+
},
75+
},
76+
})
77+
}
78+
6079
const testAccAMIIDsDataSourceConfig_basic = `
6180
data "aws_ami_ids" "test" {
6281
owners = ["099720109477"]
@@ -100,3 +119,17 @@ data "aws_ami_ids" "test" {
100119
}
101120
`, sortAscending)
102121
}
122+
123+
func testAccAMIIDsDataSourceConfig_includeDeprecated(includeDeprecated bool) string {
124+
return fmt.Sprintf(`
125+
data "aws_ami_ids" "test" {
126+
owners = ["099720109477"]
127+
include_deprecated = %[1]t
128+
129+
filter {
130+
name = "name"
131+
values = ["ubuntu/images/ubuntu-*-*-amd64-server-*"]
132+
}
133+
}
134+
`, includeDeprecated)
135+
}

website/docs/d/ami_ids.html.markdown

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ This filtering is done locally on what AWS returns, and could have a performance
4040
impact if the result is large. Combine this with other
4141
options to narrow down the list AWS returns.
4242

43-
* `sort_ascending` - (Defaults to `false`) Used to sort AMIs by creation time.
43+
* `sort_ascending` - (Optional) Used to sort AMIs by creation time.
44+
If no value is specified, the default value is `false`.
45+
46+
* `include_deprecated` - (Optional) If true, all deprecated AMIs are included in the response.
47+
If false, no deprecated AMIs are included in the response. If no value is specified, the default value is `false`.
4448

4549
## Attributes Reference
4650

0 commit comments

Comments
 (0)