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

d/ami - make owners optional + include_deprecated arg #25566

Merged
merged 3 commits into from
Jun 27, 2022
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/25566.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
data-source/aws_ami: Make `owners` optional
```

```release-note:enhancement
data-source/aws_ami: Add `include_deprecated` argument
```
14 changes: 12 additions & 2 deletions internal/service/ec2/ec2_ami_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func DataSourceAMI() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"include_deprecated": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"kernel_id": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -128,7 +133,7 @@ func DataSourceAMI() *schema.Resource {
},
"owners": {
Type: schema.TypeList,
Required: true,
Optional: true,
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -215,12 +220,17 @@ func dataSourceAMIRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).EC2Conn

params := &ec2.DescribeImagesInput{
Owners: flex.ExpandStringList(d.Get("owners").([]interface{})),
IncludeDeprecated: aws.Bool(d.Get("include_deprecated").(bool)),
}

if v, ok := d.GetOk("owners"); ok && len(v.([]interface{})) > 0 {
params.Owners = flex.ExpandStringList(v.([]interface{}))
}

if v, ok := d.GetOk("executable_users"); ok {
params.ExecutableUsers = flex.ExpandStringList(v.([]interface{}))
}

if v, ok := d.GetOk("filter"); ok {
params.Filters = BuildFiltersDataSource(v.(*schema.Set))
}
Expand Down
1 change: 0 additions & 1 deletion internal/service/ec2/ec2_ami_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ func testAccAMIDataSourceConfig_latestAmazonLinuxHVMInstanceStore() string {
return `
data "aws_ami" "amzn-ami-minimal-hvm-instance-store" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
Expand Down
4 changes: 3 additions & 1 deletion website/docs/d/ami.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ data "aws_ami" "example" {

## Argument Reference

* `owners` - (Required) List of AMI owners to limit search. At least 1 value must be specified. Valid values: an AWS account ID, `self` (the current account), or an AWS owner alias (e.g., `amazon`, `aws-marketplace`, `microsoft`).
* `owners` - (Optional) List of AMI owners to limit search. Valid values: an AWS account ID, `self` (the current account), or an AWS owner alias (e.g., `amazon`, `aws-marketplace`, `microsoft`).

* `most_recent` - (Optional) If more than one result is returned, use the most
recent AMI.

* `executable_users` - (Optional) Limit search to users with *explicit* launch permission on
the image. Valid items are the numeric account ID or `self`.

* `include_deprecated` - (Optional) If true, all deprecated AMIs are included in the response. If false, no deprecated AMIs are included in the response. If no value is specified, the default value is false.

* `filter` - (Optional) One or more name/value pairs to filter off of. There are
several valid keys, for a full reference, check out
[describe-images in the AWS CLI reference][1].
Expand Down