diff --git a/.changelog/25566.txt b/.changelog/25566.txt new file mode 100644 index 000000000000..a787b859ce93 --- /dev/null +++ b/.changelog/25566.txt @@ -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 +``` diff --git a/internal/service/ec2/ec2_ami_data_source.go b/internal/service/ec2/ec2_ami_data_source.go index 321f3ec5621a..6e1ff00b97d6 100644 --- a/internal/service/ec2/ec2_ami_data_source.go +++ b/internal/service/ec2/ec2_ami_data_source.go @@ -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, @@ -128,7 +133,7 @@ func DataSourceAMI() *schema.Resource { }, "owners": { Type: schema.TypeList, - Required: true, + Optional: true, MinItems: 1, Elem: &schema.Schema{ Type: schema.TypeString, @@ -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)) } diff --git a/internal/service/ec2/ec2_ami_data_source_test.go b/internal/service/ec2/ec2_ami_data_source_test.go index 042e783f7cfb..881ced21424f 100644 --- a/internal/service/ec2/ec2_ami_data_source_test.go +++ b/internal/service/ec2/ec2_ami_data_source_test.go @@ -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" diff --git a/website/docs/d/ami.html.markdown b/website/docs/d/ami.html.markdown index 92576cc822c3..72f1823248d2 100644 --- a/website/docs/d/ami.html.markdown +++ b/website/docs/d/ami.html.markdown @@ -39,7 +39,7 @@ 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. @@ -47,6 +47,8 @@ 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].