provider/aws: rename local_name_filter attribute to name_regex
Renamed the local_name_filter attribute to name_regex and made it clear in the docs that this runs locally and could have a performance impact on a large set of AMIs returned from AWS.
This commit is contained in:
parent
6977fff406
commit
bf68590f02
|
@ -44,7 +44,7 @@ func dataSourceAwsAmi() *schema.Resource {
|
|||
},
|
||||
},
|
||||
},
|
||||
"local_name_filter": &schema.Schema{
|
||||
"name_regex": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
|
@ -212,11 +212,11 @@ func dataSourceAwsAmiRead(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
executableUsers, executableUsersOk := d.GetOk("executable_users")
|
||||
filters, filtersOk := d.GetOk("filter")
|
||||
localNameFilter, localNameFilterOk := d.GetOk("local_name_filter")
|
||||
nameRegex, nameRegexOk := d.GetOk("name_regex")
|
||||
owners, ownersOk := d.GetOk("owners")
|
||||
|
||||
if executableUsersOk == false && filtersOk == false && localNameFilterOk == false && ownersOk == false {
|
||||
return fmt.Errorf("One of executable_users, filters, local_name_filter, or owners must be assigned")
|
||||
if executableUsersOk == false && filtersOk == false && nameRegexOk == false && ownersOk == false {
|
||||
return fmt.Errorf("One of executable_users, filters, name_regex, or owners must be assigned")
|
||||
}
|
||||
|
||||
params := &ec2.DescribeImagesInput{}
|
||||
|
@ -236,8 +236,8 @@ func dataSourceAwsAmiRead(d *schema.ResourceData, meta interface{}) error {
|
|||
}
|
||||
|
||||
var filteredImages []*ec2.Image
|
||||
if localNameFilterOk == true {
|
||||
r := regexp.MustCompile(localNameFilter.(string))
|
||||
if nameRegexOk == true {
|
||||
r := regexp.MustCompile(nameRegex.(string))
|
||||
for _, image := range resp.Images {
|
||||
if r.MatchString(*image.Name) == true {
|
||||
filteredImages = append(filteredImages, image)
|
||||
|
|
|
@ -145,10 +145,10 @@ func TestAccAWSAmiDataSource_localNameFilter(t *testing.T) {
|
|||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccCheckAwsAmiDataSourceLocalNameFilterConfig,
|
||||
Config: testAccCheckAwsAmiDataSourceNameRegexConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAwsAmiDataSourceID("data.aws_ami.local_filtered_ami"),
|
||||
resource.TestMatchResourceAttr("data.aws_ami.local_filtered_ami", "image_id", regexp.MustCompile("^ami-")),
|
||||
testAccCheckAwsAmiDataSourceID("data.aws_ami.name_regex_filtered_ami"),
|
||||
resource.TestMatchResourceAttr("data.aws_ami.name_regex_filtered_ami", "image_id", regexp.MustCompile("^ami-")),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -262,15 +262,15 @@ data "aws_ami" "amazon_ami" {
|
|||
}
|
||||
`
|
||||
|
||||
// Testing local_name_filter parameter
|
||||
const testAccCheckAwsAmiDataSourceLocalNameFilterConfig = `
|
||||
data "aws_ami" "local_filtered_ami" {
|
||||
// Testing name_regex parameter
|
||||
const testAccCheckAwsAmiDataSourceNameRegexConfig = `
|
||||
data "aws_ami" "name_regex_filtered_ami" {
|
||||
most_recent = true
|
||||
owners = ["amazon"]
|
||||
filter {
|
||||
name = "name"
|
||||
values = ["amzn-ami-*"]
|
||||
}
|
||||
local_name_filter = "^amzn-ami-\\d{3}[5].*-ecs-optimized"
|
||||
name_regex = "^amzn-ami-\\d{3}[5].*-ecs-optimized"
|
||||
}
|
||||
`
|
||||
|
|
|
@ -25,7 +25,7 @@ data "aws_ami" "nat_ami" {
|
|||
name = "name"
|
||||
values = ["amzn-ami-vpc-nat*"]
|
||||
}
|
||||
local_name_filter = "^myami-\\d{3}"
|
||||
name_regex = "^myami-\\d{3}"
|
||||
owners = ["self"]
|
||||
}
|
||||
```
|
||||
|
@ -42,13 +42,17 @@ recent AMI.
|
|||
several valid keys, for a full reference, check out
|
||||
[describe-images in the AWS CLI reference][1].
|
||||
|
||||
* `local_name_filter` - (Optional) A regex string to apply to the AMI list returned
|
||||
by AWS. This allows more advanced filtering not supported from the AWS API.
|
||||
|
||||
* `owners` - (Optional) Limit search to specific AMI owners. Valid items are the numeric
|
||||
account ID, `amazon`, or `self`.
|
||||
|
||||
~> **NOTE:** At least one of `executable_users`, `filter`, or `owners` must be specified.
|
||||
* `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
|
||||
|
|
Loading…
Reference in New Issue