Skip to content

Commit

Permalink
Merge pull request #5653 from terraform-providers/s-aws_ami-missing-o…
Browse files Browse the repository at this point in the history
…wners-warning-log

data-source/aws_ami: Print warning log messages for missing owners argument and missing owners filtering
  • Loading branch information
bflad authored Aug 22, 2018
2 parents 8fc0d16 + b78ed89 commit ae3096d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
22 changes: 22 additions & 0 deletions aws/data_source_aws_ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"regexp"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -203,6 +204,27 @@ func dataSourceAwsAmiRead(d *schema.ResourceData, meta interface{}) error {
}
}

// 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.")
}
}

log.Printf("[DEBUG] Reading AMI: %s", params)
resp, err := conn.DescribeImages(params)
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions aws/data_source_aws_ami_ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"regexp"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -72,6 +73,27 @@ func dataSourceAwsAmiIdsRead(d *schema.ResourceData, meta interface{}) error {
}
}

// 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.")
}
}

log.Printf("[DEBUG] Reading AMI IDs: %s", params)
resp, err := conn.DescribeImages(params)
if err != nil {
Expand Down

0 comments on commit ae3096d

Please sign in to comment.