From 493e23fe1d713f59d0c2d206f133f920aca233fd Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Thu, 16 Aug 2018 03:00:09 -0400 Subject: [PATCH] data-source/aws_ami and data-source/aws_ami_ids: Require owners argument * data-source/aws_ami: Switch owners argument from Optional to Required * data-source/aws_ami_ids: Switch owners argument from Optional to Required * tests: Update aws_ami data sources to use owners instead of filter > name = "owner-alias" Output from acceptance testing: ``` --- PASS: TestAccAWSAmiDataSource_instanceStore (8.89s) --- PASS: TestAccDataSourceAwsAmiIds_basic (9.72s) --- PASS: TestAccAWSAmiDataSource_natInstance (9.72s) --- PASS: TestAccAWSAmiDataSource_localNameFilter (12.65s) --- PASS: TestAccDataSourceAwsAmiIds_sorted (14.02s) --- PASS: TestAccAWSAmiDataSource_windowsInstance (16.91s) ``` --- aws/data_source_aws_ami.go | 57 ++---- aws/data_source_aws_ami_ids.go | 61 ++----- aws/data_source_aws_ami_ids_test.go | 25 --- aws/data_source_aws_ami_test.go | 82 +-------- ...data_source_aws_autoscaling_groups_test.go | 12 +- aws/data_source_aws_instance_test.go | 6 +- aws/resource_aws_autoscaling_group_test.go | 162 +++--------------- aws/resource_aws_eip_test.go | 48 ++---- aws/resource_aws_instance_test.go | 6 +- aws/resource_aws_launch_template_test.go | 24 +-- ...rce_aws_licensemanager_association_test.go | 8 +- ...resource_aws_spot_instance_request_test.go | 6 +- ...esource_aws_storagegateway_gateway_test.go | 18 +- website/docs/d/ami.html.markdown | 30 ++-- website/docs/d/ami_ids.html.markdown | 10 +- .../r/licensemanager_association.markdown | 8 +- 16 files changed, 108 insertions(+), 455 deletions(-) diff --git a/aws/data_source_aws_ami.go b/aws/data_source_aws_ami.go index f5b8a01d0ee..a877fe62762 100644 --- a/aws/data_source_aws_ami.go +++ b/aws/data_source_aws_ami.go @@ -41,9 +41,12 @@ func dataSourceAwsAmi() *schema.Resource { }, "owners": { Type: schema.TypeList, - Optional: true, - ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Required: true, + MinItems: 1, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, }, // Computed values. "architecture": { @@ -182,49 +185,15 @@ func dataSourceAwsAmi() *schema.Resource { func dataSourceAwsAmiRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn - executableUsers, executableUsersOk := d.GetOk("executable_users") - filters, filtersOk := d.GetOk("filter") - nameRegex, nameRegexOk := d.GetOk("name_regex") - owners, ownersOk := d.GetOk("owners") - - if !executableUsersOk && !filtersOk && !nameRegexOk && !ownersOk { - return fmt.Errorf("One of executable_users, filters, name_regex, or owners must be assigned") - } - - params := &ec2.DescribeImagesInput{} - if executableUsersOk { - params.ExecutableUsers = expandStringList(executableUsers.([]interface{})) - } - if filtersOk { - params.Filters = buildAwsDataSourceFilters(filters.(*schema.Set)) + params := &ec2.DescribeImagesInput{ + Owners: expandStringList(d.Get("owners").([]interface{})), } - if ownersOk { - o := expandStringList(owners.([]interface{})) - if len(o) > 0 { - params.Owners = o - } + if v, ok := d.GetOk("executable_users"); ok { + params.ExecutableUsers = expandStringList(v.([]interface{})) } - - // Deprecated: pre-2.0.0 warning logging - if !ownersOk { - log.Print("[WARN] The \"owners\" argument will become required in the next major version.") - log.Print("[WARN] Documentation can be found at: https://www.terraform.io/docs/providers/aws/d/ami.html#owners") - - missingOwnerFilter := true - - if filtersOk { - for _, filter := range params.Filters { - if aws.StringValue(filter.Name) == "owner-alias" || aws.StringValue(filter.Name) == "owner-id" { - missingOwnerFilter = false - break - } - } - } - - if missingOwnerFilter { - log.Print("[WARN] Potential security issue: missing \"owners\" filtering for AMI. Check AMI to ensure it came from trusted source.") - } + if v, ok := d.GetOk("filter"); ok { + params.Filters = buildAwsDataSourceFilters(v.(*schema.Set)) } log.Printf("[DEBUG] Reading AMI: %s", params) @@ -234,7 +203,7 @@ func dataSourceAwsAmiRead(d *schema.ResourceData, meta interface{}) error { } var filteredImages []*ec2.Image - if nameRegexOk { + if nameRegex, ok := d.GetOk("name_regex"); ok { r := regexp.MustCompile(nameRegex.(string)) for _, image := range resp.Images { // Check for a very rare case where the response would include no diff --git a/aws/data_source_aws_ami_ids.go b/aws/data_source_aws_ami_ids.go index 7c932fa6cd1..941dc4b8840 100644 --- a/aws/data_source_aws_ami_ids.go +++ b/aws/data_source_aws_ami_ids.go @@ -34,9 +34,12 @@ func dataSourceAwsAmiIds() *schema.Resource { }, "owners": { Type: schema.TypeList, - Optional: true, - ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Required: true, + MinItems: 1, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, }, "ids": { Type: schema.TypeList, @@ -55,51 +58,15 @@ func dataSourceAwsAmiIds() *schema.Resource { func dataSourceAwsAmiIdsRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn - executableUsers, executableUsersOk := d.GetOk("executable_users") - filters, filtersOk := d.GetOk("filter") - nameRegex, nameRegexOk := d.GetOk("name_regex") - owners, ownersOk := d.GetOk("owners") - sortAscending := d.Get("sort_ascending").(bool) - - if !executableUsersOk && !filtersOk && !nameRegexOk && !ownersOk { - return fmt.Errorf("One of executable_users, filters, name_regex, or owners must be assigned") - } - - params := &ec2.DescribeImagesInput{} - - if executableUsersOk { - params.ExecutableUsers = expandStringList(executableUsers.([]interface{})) - } - if filtersOk { - params.Filters = buildAwsDataSourceFilters(filters.(*schema.Set)) + params := &ec2.DescribeImagesInput{ + Owners: expandStringList(d.Get("owners").([]interface{})), } - if ownersOk { - o := expandStringList(owners.([]interface{})) - if len(o) > 0 { - params.Owners = o - } + if v, ok := d.GetOk("executable_users"); ok { + params.ExecutableUsers = expandStringList(v.([]interface{})) } - - // Deprecated: pre-2.0.0 warning logging - if !ownersOk { - log.Print("[WARN] The \"owners\" argument will become required in the next major version.") - log.Print("[WARN] Documentation can be found at: https://www.terraform.io/docs/providers/aws/d/ami.html#owners") - - missingOwnerFilter := true - - if filtersOk { - for _, filter := range params.Filters { - if aws.StringValue(filter.Name) == "owner-alias" || aws.StringValue(filter.Name) == "owner-id" { - missingOwnerFilter = false - break - } - } - } - - if missingOwnerFilter { - log.Print("[WARN] Potential security issue: missing \"owners\" filtering for AMI. Check AMI to ensure it came from trusted source.") - } + if v, ok := d.GetOk("filter"); ok { + params.Filters = buildAwsDataSourceFilters(v.(*schema.Set)) } log.Printf("[DEBUG] Reading AMI IDs: %s", params) @@ -111,7 +78,7 @@ func dataSourceAwsAmiIdsRead(d *schema.ResourceData, meta interface{}) error { var filteredImages []*ec2.Image imageIds := make([]string, 0) - if nameRegexOk { + if nameRegex, ok := d.GetOk("name_regex"); ok { r := regexp.MustCompile(nameRegex.(string)) for _, image := range resp.Images { // Check for a very rare case where the response would include no @@ -134,7 +101,7 @@ func dataSourceAwsAmiIdsRead(d *schema.ResourceData, meta interface{}) error { sort.Slice(filteredImages, func(i, j int) bool { itime, _ := time.Parse(time.RFC3339, aws.StringValue(filteredImages[i].CreationDate)) jtime, _ := time.Parse(time.RFC3339, aws.StringValue(filteredImages[j].CreationDate)) - if sortAscending { + if d.Get("sort_ascending").(bool) { return itime.Unix() < jtime.Unix() } return itime.Unix() > jtime.Unix() diff --git a/aws/data_source_aws_ami_ids_test.go b/aws/data_source_aws_ami_ids_test.go index 1a38b56c6af..587970f8913 100644 --- a/aws/data_source_aws_ami_ids_test.go +++ b/aws/data_source_aws_ami_ids_test.go @@ -58,22 +58,6 @@ func TestAccDataSourceAwsAmiIds_sorted(t *testing.T) { }) } -func TestAccDataSourceAwsAmiIds_empty(t *testing.T) { - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAwsAmiIdsConfig_empty, - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsAmiDataSourceID("data.aws_ami_ids.empty"), - resource.TestCheckResourceAttr("data.aws_ami_ids.empty", "ids.#", "0"), - ), - }, - }, - }) -} - const testAccDataSourceAwsAmiIdsConfig_basic = ` data "aws_ami_ids" "ubuntu" { owners = ["099720109477"] @@ -113,12 +97,3 @@ data "aws_ami_ids" "test" { } `, sort_ascending) } - -const testAccDataSourceAwsAmiIdsConfig_empty = ` -data "aws_ami_ids" "empty" { - filter { - name = "name" - values = [] - } -} -` diff --git a/aws/data_source_aws_ami_test.go b/aws/data_source_aws_ami_test.go index 1288b17a9a2..32eb66f301f 100644 --- a/aws/data_source_aws_ami_test.go +++ b/aws/data_source_aws_ami_test.go @@ -127,37 +127,6 @@ func TestAccAWSAmiDataSource_instanceStore(t *testing.T) { }) } -func TestAccAWSAmiDataSource_owners(t *testing.T) { - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckAwsAmiDataSourceOwnersConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsAmiDataSourceID("data.aws_ami.amazon_ami"), - ), - }, - }, - }) -} - -// Acceptance test for: https://github.com/hashicorp/terraform/issues/10758 -func TestAccAWSAmiDataSource_ownersEmpty(t *testing.T) { - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckAwsAmiDataSourceEmptyOwnersConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsAmiDataSourceID("data.aws_ami.amazon_ami"), - ), - }, - }, - }) -} - func TestAccAWSAmiDataSource_localNameFilter(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -175,7 +144,6 @@ func TestAccAWSAmiDataSource_localNameFilter(t *testing.T) { } func testAccCheckAwsAmiDataSourceID(n string) resource.TestCheckFunc { - // Wait for IAM role return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -196,10 +164,8 @@ func testAccCheckAwsAmiDataSourceID(n string) resource.TestCheckFunc { const testAccCheckAwsAmiDataSourceConfig = ` data "aws_ami" "nat_ami" { most_recent = true - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] + filter { name = "name" values = ["amzn-ami-vpc-nat*"] @@ -223,10 +189,8 @@ data "aws_ami" "nat_ami" { const testAccCheckAwsAmiDataSourceWindowsConfig = ` data "aws_ami" "windows_ami" { most_recent = true - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] + filter { name = "name" values = ["Windows_Server-2012-R2*"] @@ -250,10 +214,8 @@ data "aws_ami" "windows_ami" { const testAccCheckAwsAmiDataSourceInstanceStoreConfig = ` data "aws_ami" "instance_store_ami" { most_recent = true - filter { - name = "owner-id" - values = ["099720109477"] - } + owners = ["099720109477"] + filter { name = "name" values = ["ubuntu/images/hvm-instance/ubuntu-trusty-14.04-amd64-server*"] @@ -269,38 +231,6 @@ data "aws_ami" "instance_store_ami" { } ` -// Testing owner parameter -const testAccCheckAwsAmiDataSourceOwnersConfig = ` -data "aws_ami" "amazon_ami" { - most_recent = true - owners = ["amazon"] -} -` - -const testAccCheckAwsAmiDataSourceEmptyOwnersConfig = ` -data "aws_ami" "amazon_ami" { - most_recent = true - owners = [""] - - # we need to test the owners = [""] for regressions but we want to filter the results - # beyond all public AWS AMIs :) - filter { - name = "owner-alias" - values = ["amazon"] - } - - filter { - name = "name" - values = ["amzn-ami-minimal-hvm-*"] - } - - filter { - name = "root-device-type" - values = ["ebs"] - } -} -` - // Testing name_regex parameter const testAccCheckAwsAmiDataSourceNameRegexConfig = ` data "aws_ami" "name_regex_filtered_ami" { diff --git a/aws/data_source_aws_autoscaling_groups_test.go b/aws/data_source_aws_autoscaling_groups_test.go index c8b79431125..11434f1a368 100644 --- a/aws/data_source_aws_autoscaling_groups_test.go +++ b/aws/data_source_aws_autoscaling_groups_test.go @@ -84,11 +84,7 @@ func testAccCheckAwsAutoscalingGroupsConfig(rInt1, rInt2, rInt3 int) string { return fmt.Sprintf(` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -162,11 +158,7 @@ func testAccCheckAwsAutoscalingGroupsConfigWithDataSource(rInt1, rInt2, rInt3 in return fmt.Sprintf(` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" diff --git a/aws/data_source_aws_instance_test.go b/aws/data_source_aws_instance_test.go index 725fb63c027..fb600f57554 100644 --- a/aws/data_source_aws_instance_test.go +++ b/aws/data_source_aws_instance_test.go @@ -648,11 +648,7 @@ func testAccInstanceDataSourceConfig_getPasswordData(val bool, rInt int) string # Find latest Microsoft Windows Server 2016 Core image (Amazon deletes old ones) data "aws_ami" "win2016core" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" diff --git a/aws/resource_aws_autoscaling_group_test.go b/aws/resource_aws_autoscaling_group_test.go index e1a62c07228..4d915b69196 100644 --- a/aws/resource_aws_autoscaling_group_test.go +++ b/aws/resource_aws_autoscaling_group_test.go @@ -1418,11 +1418,7 @@ func TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_Ins const testAccAWSAutoScalingGroupConfig_autoGeneratedName = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1447,11 +1443,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSAutoScalingGroupConfig_namePrefix = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1477,11 +1469,7 @@ resource "aws_autoscaling_group" "test" { const testAccAWSAutoScalingGroupConfig_terminationPoliciesEmpty = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1507,11 +1495,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSAutoScalingGroupConfig_terminationPoliciesExplicitDefault = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1538,11 +1522,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSAutoScalingGroupConfig_terminationPoliciesUpdate = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1570,11 +1550,7 @@ func testAccAWSAutoScalingGroupConfig(name string) string { return fmt.Sprintf(` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1629,11 +1605,7 @@ func testAccAWSAutoScalingGroupConfigUpdate(name string) string { return fmt.Sprintf(` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1690,11 +1662,7 @@ func testAccAWSAutoScalingGroupImport(name string) string { return fmt.Sprintf(` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1857,11 +1825,7 @@ resource "aws_subnet" "main" { data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1904,11 +1868,7 @@ resource "aws_subnet" "main" { data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1936,11 +1896,7 @@ func testAccAWSAutoScalingGroupConfig_withPlacementGroup(name string) string { return fmt.Sprintf(` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1984,11 +1940,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSAutoScalingGroupConfig_withServiceLinkedRoleARN = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2018,11 +1970,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSAutoscalingMetricsCollectionConfig_allMetricsCollected = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2060,11 +2008,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSAutoscalingMetricsCollectionConfig_updatingMetricsCollected = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2135,11 +2079,7 @@ resource "aws_subnet" "alt" { data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2226,11 +2166,7 @@ resource "aws_subnet" "alt" { data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2330,11 +2266,7 @@ resource "aws_subnet" "alt" { data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2392,11 +2324,7 @@ func testAccAWSAutoScalingGroupWithHookConfig(name string) string { return fmt.Sprintf(` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2530,11 +2458,7 @@ resource "aws_route" "public_default_route" { data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2580,11 +2504,7 @@ func testAccAWSAutoScalingGroupConfigWithSuspendedProcesses(name string) string return fmt.Sprintf(` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2629,11 +2549,7 @@ func testAccAWSAutoScalingGroupConfigWithSuspendedProcessesUpdated(name string) return fmt.Sprintf(` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2686,11 +2602,7 @@ resource "aws_autoscaling_group" "test" { data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2731,11 +2643,7 @@ resource "aws_autoscaling_group" "test" { data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2752,11 +2660,7 @@ resource "aws_launch_configuration" "test" { const testAccAWSAutoScalingGroupConfig_withLaunchTemplate = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2787,11 +2691,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSAutoScalingGroupConfig_withLaunchTemplate_toLaunchConfig = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2824,11 +2724,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSAutoScalingGroupConfig_withLaunchTemplate_toLaunchTemplateName = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -2869,11 +2765,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSAutoScalingGroupConfig_withLaunchTemplate_toLaunchTemplateVersion = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" diff --git a/aws/resource_aws_eip_test.go b/aws/resource_aws_eip_test.go index 2617fcfe61e..6865ebd6c19 100644 --- a/aws/resource_aws_eip_test.go +++ b/aws/resource_aws_eip_test.go @@ -526,10 +526,8 @@ provider "aws" { data "aws_ami" "amzn-ami-minimal-pv" { most_recent = true - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] + filter { name = "name" values = ["amzn-ami-minimal-pv-*"] @@ -556,10 +554,8 @@ resource "aws_eip" "bar" { const testAccAWSEIPInstanceConfig = ` data "aws_ami" "amzn-ami-minimal-pv" { most_recent = true - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] + filter { name = "name" values = ["amzn-ami-minimal-pv-*"] @@ -583,10 +579,8 @@ resource "aws_eip" "bar" { const testAccAWSEIPInstanceConfig2 = ` data "aws_ami" "amzn-ami-minimal-pv" { most_recent = true - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] + filter { name = "name" values = ["amzn-ami-minimal-pv-*"] @@ -610,10 +604,8 @@ resource "aws_eip" "bar" { const testAccAWSEIPInstanceConfig_associated = ` data "aws_ami" "amzn-ami-minimal-hvm" { most_recent = true - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] + filter { name = "name" values = ["amzn-ami-minimal-hvm-*"] @@ -688,10 +680,8 @@ resource "aws_eip" "bar" { const testAccAWSEIPInstanceConfig_associated_switch = ` data "aws_ami" "amzn-ami-minimal-hvm" { most_recent = true - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] + filter { name = "name" values = ["amzn-ami-minimal-hvm-*"] @@ -852,10 +842,8 @@ variable "server_count" { data "aws_ami" "amzn-ami-minimal-pv" { most_recent = true - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] + filter { name = "name" values = ["amzn-ami-minimal-pv-*"] @@ -929,10 +917,8 @@ resource "aws_route_table_association" "us-east-1b-public" { const testAccAWSEIPAssociate_not_associated = ` data "aws_ami" "amzn-ami-minimal-pv" { most_recent = true - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] + filter { name = "name" values = ["amzn-ami-minimal-pv-*"] @@ -955,10 +941,8 @@ resource "aws_eip" "bar" { const testAccAWSEIPAssociate_associated = ` data "aws_ami" "amzn-ami-minimal-pv" { most_recent = true - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] + filter { name = "name" values = ["amzn-ami-minimal-pv-*"] diff --git a/aws/resource_aws_instance_test.go b/aws/resource_aws_instance_test.go index 4f23f0b9666..f902087d402 100644 --- a/aws/resource_aws_instance_test.go +++ b/aws/resource_aws_instance_test.go @@ -3720,11 +3720,7 @@ func testAccInstanceConfig_getPasswordData(val bool, rInt int) string { # Find latest Microsoft Windows Server 2016 Core image (Amazon deletes old ones) data "aws_ami" "win2016core" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" diff --git a/aws/resource_aws_launch_template_test.go b/aws/resource_aws_launch_template_test.go index b55931c5d03..497f89da310 100644 --- a/aws/resource_aws_launch_template_test.go +++ b/aws/resource_aws_launch_template_test.go @@ -1008,11 +1008,7 @@ resource "aws_launch_template" "test" { const testAccAWSLaunchTemplateConfig_asg_basic = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1043,11 +1039,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSLaunchTemplateConfig_asg_update = ` data "aws_ami" "test_ami" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1078,11 +1070,7 @@ resource "aws_autoscaling_group" "bar" { const testAccAWSLaunchTemplateConfig_instanceMarketOptions_basic = ` data "aws_ami" "test" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -1121,11 +1109,7 @@ resource "aws_autoscaling_group" "test" { const testAccAWSLaunchTemplateConfig_instanceMarketOptions_update = ` data "aws_ami" "test" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" diff --git a/aws/resource_aws_licensemanager_association_test.go b/aws/resource_aws_licensemanager_association_test.go index 040ee2a46a2..42c863faabf 100644 --- a/aws/resource_aws_licensemanager_association_test.go +++ b/aws/resource_aws_licensemanager_association_test.go @@ -95,12 +95,8 @@ func testAccCheckLicenseManagerAssociationDestroy(s *terraform.State) error { const testAccLicenseManagerAssociationConfig_basic = ` data "aws_ami" "example" { - most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + most_recent = true + owners = ["amazon"] filter { name = "name" diff --git a/aws/resource_aws_spot_instance_request_test.go b/aws/resource_aws_spot_instance_request_test.go index 9a4eb85ebda..1c61ecbae8b 100644 --- a/aws/resource_aws_spot_instance_request_test.go +++ b/aws/resource_aws_spot_instance_request_test.go @@ -756,11 +756,7 @@ func testAccAWSSpotInstanceRequestConfig_getPasswordData(rInt int) string { # Find latest Microsoft Windows Server 2016 Core image (Amazon deletes old ones) data "aws_ami" "win2016core" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" diff --git a/aws/resource_aws_storagegateway_gateway_test.go b/aws/resource_aws_storagegateway_gateway_test.go index 27542061266..a8f26501411 100644 --- a/aws/resource_aws_storagegateway_gateway_test.go +++ b/aws/resource_aws_storagegateway_gateway_test.go @@ -464,11 +464,7 @@ func testAccAWSStorageGateway_FileGatewayBase(rName string) string { return testAccAWSStorageGateway_VPCBase(rName) + fmt.Sprintf(` data "aws_ami" "aws-thinstaller" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -499,11 +495,7 @@ func testAccAWSStorageGateway_TapeAndVolumeGatewayBase(rName string) string { return testAccAWSStorageGateway_VPCBase(rName) + fmt.Sprintf(` data "aws_ami" "aws-storage-gateway-2" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" @@ -688,11 +680,7 @@ resource "aws_vpc_dhcp_options_association" "test" { data "aws_ami" "aws-thinstaller" { most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + owners = ["amazon"] filter { name = "name" diff --git a/website/docs/d/ami.html.markdown b/website/docs/d/ami.html.markdown index baae6aaf189..04d6ad1a0b8 100644 --- a/website/docs/d/ami.html.markdown +++ b/website/docs/d/ami.html.markdown @@ -11,32 +11,36 @@ description: |- Use this data source to get the ID of a registered AMI for use in other resources. -~> **NOTE:** The `owners` argument will be **required** in the next major version. - ## Example Usage ```hcl -data "aws_ami" "nat_ami" { - most_recent = true +data "aws_ami" "example" { executable_users = ["self"] + most_recent = true + name_regex = "^myami-\\d{3}" + owners = ["self"] filter { - name = "owner-alias" - values = ["amazon"] + name = "name" + values = ["myami-*"] } filter { - name = "name" - values = ["amzn-ami-vpc-nat*"] + name = "root-device-type" + values = ["ebs"] } - name_regex = "^myami-\\d{3}" - owners = ["self"] + filter { + name = "virtualization-type" + values = ["hvm"] + } } ``` ## 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`). + * `most_recent` - (Optional) If more than one result is returned, use the most recent AMI. @@ -47,18 +51,12 @@ recent AMI. several valid keys, for a full reference, check out [describe-images in the AWS CLI reference][1]. -* `owners` - (Optional) Limit search to specific AMI owners. Valid items are the numeric -account ID, `amazon`, or `self`. - * `name_regex` - (Optional) A regex string to apply to the AMI list returned by AWS. This allows more advanced filtering not supported from the AWS API. This filtering is done locally on what AWS returns, and could have a performance impact if the result is large. It is recommended to combine this with other options to narrow down the list AWS returns. -~> **NOTE:** At least one of `executable_users`, `filter`, `owners`, or -`name_regex` must be specified. - ~> **NOTE:** If more or less than a single match is returned by the search, Terraform will fail. Ensure that your search is specific enough to return a single AMI ID only, or use `most_recent` to choose the most recent one. If diff --git a/website/docs/d/ami_ids.html.markdown b/website/docs/d/ami_ids.html.markdown index 2ef3175d7fc..46db81cd3c5 100644 --- a/website/docs/d/ami_ids.html.markdown +++ b/website/docs/d/ami_ids.html.markdown @@ -10,8 +10,6 @@ description: |- Use this data source to get a list of AMI IDs matching the specified criteria. -~> **NOTE:** The `owners` argument will be **required** in the next major version. - ## Example Usage ```hcl @@ -27,6 +25,8 @@ data "aws_ami_ids" "ubuntu" { ## 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`). + * `executable_users` - (Optional) Limit search to users with *explicit* launch permission on the image. Valid items are the numeric account ID or `self`. @@ -34,18 +34,12 @@ permission on the image. Valid items are the numeric account ID or `self`. are several valid keys, for a full reference, check out [describe-images in the AWS CLI reference][1]. -* `owners` - (Optional) Limit search to specific AMI owners. Valid items are -the numeric account ID, `amazon`, or `self`. - * `name_regex` - (Optional) A regex string to apply to the AMI list returned by AWS. This allows more advanced filtering not supported from the AWS API. This filtering is done locally on what AWS returns, and could have a performance impact if the result is large. It is recommended to combine this with other options to narrow down the list AWS returns. -~> **NOTE:** At least one of `executable_users`, `filter`, `owners` or -`name_regex` must be specified. - * `sort_ascending` - (Defaults to `false`) Used to sort AMIs by creation time. ## Attributes Reference diff --git a/website/docs/r/licensemanager_association.markdown b/website/docs/r/licensemanager_association.markdown index 7c5cbc86428..4a0a2d8c55f 100644 --- a/website/docs/r/licensemanager_association.markdown +++ b/website/docs/r/licensemanager_association.markdown @@ -16,12 +16,8 @@ Provides a License Manager association. ```hcl data "aws_ami" "example" { - most_recent = true - - filter { - name = "owner-alias" - values = ["amazon"] - } + most_recent = true + owners = ["amazon"] filter { name = "name"